File indexing completed on 2026-05-03 08:14:06
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___UTILITY_EXCHANGE_H
0010 #define _LIBCPP___UTILITY_EXCHANGE_H
0011
0012 #include <__config>
0013 #include <__type_traits/is_nothrow_assignable.h>
0014 #include <__type_traits/is_nothrow_constructible.h>
0015 #include <__utility/forward.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 #if _LIBCPP_STD_VER >= 14
0028 template <class _T1, class _T2 = _T1>
0029 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _T1 exchange(_T1& __obj, _T2&& __new_value) noexcept(
0030 is_nothrow_move_constructible<_T1>::value && is_nothrow_assignable<_T1&, _T2>::value) {
0031 _T1 __old_value = std::move(__obj);
0032 __obj = std::forward<_T2>(__new_value);
0033 return __old_value;
0034 }
0035 #endif
0036
0037 _LIBCPP_END_NAMESPACE_STD
0038
0039 _LIBCPP_POP_MACROS
0040
0041 #endif