[libcxx-commits] [libcxx] [libc++] Add `__exchange` as a C++11 utility (PR #187953)

Jordan Rupprecht via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 4 20:49:38 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
----------------
rupprecht wrote:

Is adding `[[nodiscard]]` intended / desired? I don't see it mentioned in the PR description.

https://github.com/llvm/llvm-project/pull/187953


More information about the libcxx-commits mailing list