[libcxx-commits] [libcxx] [libc++] Add `__exchange` as a C++11 utility (PR #187953)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Tue May 5 01:26:07 PDT 2026
================
@@ -24,14 +27,21 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
-#if _LIBCPP_STD_VER >= 14
template <class _T1, class _T2 = _T1>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _T1 exchange(_T1& __obj, _T2&& __new_value) noexcept(
- is_nothrow_move_constructible<_T1>::value && is_nothrow_assignable<_T1&, _T2>::value) {
+[[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _T1
----------------
frederick-vs-ja wrote:
A user should use plain assignment if the return value of `exchange` is not desired. In any case, I believe we should enhance the documentation and keep using `[[nodiscard]]`.
BTW, it seems that we should use __uglified `[[__nodiscard__]]` for pre-C++17 code.
https://github.com/llvm/llvm-project/pull/187953
More information about the libcxx-commits
mailing list