Path: blob/main/contrib/llvm-project/libcxx/include/__utility/exchange.h
35236 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___UTILITY_EXCHANGE_H9#define _LIBCPP___UTILITY_EXCHANGE_H1011#include <__config>12#include <__type_traits/is_nothrow_assignable.h>13#include <__type_traits/is_nothrow_constructible.h>14#include <__utility/forward.h>15#include <__utility/move.h>1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18# pragma GCC system_header19#endif2021_LIBCPP_PUSH_MACROS22#include <__undef_macros>2324_LIBCPP_BEGIN_NAMESPACE_STD2526#if _LIBCPP_STD_VER >= 1427template <class _T1, class _T2 = _T1>28inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _T1 exchange(_T1& __obj, _T2&& __new_value) noexcept(29is_nothrow_move_constructible<_T1>::value && is_nothrow_assignable<_T1&, _T2>::value) {30_T1 __old_value = std::move(__obj);31__obj = std::forward<_T2>(__new_value);32return __old_value;33}34#endif // _LIBCPP_STD_VER >= 143536_LIBCPP_END_NAMESPACE_STD3738_LIBCPP_POP_MACROS3940#endif // _LIBCPP___UTILITY_EXCHANGE_H414243