File indexing completed on 2026-05-03 08:14:06
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___UTILITY_TRANSACTION_H
0010 #define _LIBCPP___UTILITY_TRANSACTION_H
0011
0012 #include <__assert>
0013 #include <__config>
0014 #include <__type_traits/is_nothrow_constructible.h>
0015 #include <__utility/exchange.h>
0016 #include <__utility/move.h>
0017
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 # pragma GCC system_header
0020 #endif
0021
0022 _LIBCPP_PUSH_MACROS
0023 #include <__undef_macros>
0024
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 template <class _Rollback>
0065 struct __exception_guard_exceptions {
0066 __exception_guard_exceptions() = delete;
0067
0068 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __exception_guard_exceptions(_Rollback __rollback)
0069 : __rollback_(std::move(__rollback)), __completed_(false) {}
0070
0071 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0072 __exception_guard_exceptions(__exception_guard_exceptions&& __other)
0073 _NOEXCEPT_(is_nothrow_move_constructible<_Rollback>::value)
0074 : __rollback_(std::move(__other.__rollback_)), __completed_(__other.__completed_) {
0075 __other.__completed_ = true;
0076 }
0077
0078 __exception_guard_exceptions(__exception_guard_exceptions const&) = delete;
0079 __exception_guard_exceptions& operator=(__exception_guard_exceptions const&) = delete;
0080 __exception_guard_exceptions& operator=(__exception_guard_exceptions&&) = delete;
0081
0082 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __complete() _NOEXCEPT { __completed_ = true; }
0083
0084 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__exception_guard_exceptions() {
0085 if (!__completed_)
0086 __rollback_();
0087 }
0088
0089 private:
0090 _Rollback __rollback_;
0091 bool __completed_;
0092 };
0093
0094 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__exception_guard_exceptions);
0095
0096 template <class _Rollback>
0097 struct __exception_guard_noexceptions {
0098 __exception_guard_noexceptions() = delete;
0099 _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI
0100 _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit __exception_guard_noexceptions(_Rollback) {}
0101
0102 _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0103 __exception_guard_noexceptions(__exception_guard_noexceptions&& __other)
0104 _NOEXCEPT_(is_nothrow_move_constructible<_Rollback>::value)
0105 : __completed_(__other.__completed_) {
0106 __other.__completed_ = true;
0107 }
0108
0109 __exception_guard_noexceptions(__exception_guard_noexceptions const&) = delete;
0110 __exception_guard_noexceptions& operator=(__exception_guard_noexceptions const&) = delete;
0111 __exception_guard_noexceptions& operator=(__exception_guard_noexceptions&&) = delete;
0112
0113 _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __complete() _NOEXCEPT {
0114 __completed_ = true;
0115 }
0116
0117 _LIBCPP_NODEBUG _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__exception_guard_noexceptions() {
0118 _LIBCPP_ASSERT_INTERNAL(__completed_, "__exception_guard not completed with exceptions disabled");
0119 }
0120
0121 private:
0122 bool __completed_ = false;
0123 };
0124
0125 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__exception_guard_noexceptions);
0126
0127 #if !_LIBCPP_HAS_EXCEPTIONS
0128 template <class _Rollback>
0129 using __exception_guard _LIBCPP_NODEBUG = __exception_guard_noexceptions<_Rollback>;
0130 #else
0131 template <class _Rollback>
0132 using __exception_guard _LIBCPP_NODEBUG = __exception_guard_exceptions<_Rollback>;
0133 #endif
0134
0135 template <class _Rollback>
0136 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __exception_guard<_Rollback> __make_exception_guard(_Rollback __rollback) {
0137 return __exception_guard<_Rollback>(std::move(__rollback));
0138 }
0139
0140 _LIBCPP_END_NAMESPACE_STD
0141
0142 _LIBCPP_POP_MACROS
0143
0144 #endif