From e0b3356e67a9288accab0f079963397a4421923c Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Mon, 5 Sep 2022 12:44:28 +0200 Subject: [PATCH] [libc++] Enable rvalue overloads for pair in C++03 We require rvalue support anyways, so let's use it. Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D133013 --- libcxx/include/__utility/pair.h | 26 +--------------------- .../pairs/pair.astuple/get_const_rv.pass.cpp | 10 +++++++-- .../utility/pairs/pairs.spec/comparison.pass.cpp | 7 +++--- .../utility/pairs/pairs.spec/make_pair.pass.cpp | 7 +++--- .../pairs/pairs.spec/non_member_swap.pass.cpp | 7 +++--- 5 files changed, 18 insertions(+), 39 deletions(-) diff --git a/libcxx/include/__utility/pair.h b/libcxx/include/__utility/pair.h index 51aa3e6..6669b9a 100644 --- a/libcxx/include/__utility/pair.h +++ b/libcxx/include/__utility/pair.h @@ -49,12 +49,8 @@ struct _LIBCPP_TEMPLATE_VIS pair _T1 first; _T2 second; -#if !defined(_LIBCPP_CXX03_LANG) pair(pair const&) = default; pair(pair&&) = default; -#else - // Use the implicitly declared copy constructor in C++03 -#endif #ifdef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY @@ -421,8 +417,6 @@ swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) __x.swap(__y); } -#ifndef _LIBCPP_CXX03_LANG - template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 pair::type, typename __unwrap_ref_decay<_T2>::type> @@ -432,18 +426,6 @@ make_pair(_T1&& __t1, _T2&& __t2) (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); } -#else // _LIBCPP_CXX03_LANG - -template -inline _LIBCPP_INLINE_VISIBILITY -pair<_T1,_T2> -make_pair(_T1 __x, _T2 __y) -{ - return pair<_T1, _T2>(__x, __y); -} - -#endif // _LIBCPP_CXX03_LANG - template struct _LIBCPP_TEMPLATE_VIS tuple_size > : public integral_constant {}; @@ -483,7 +465,6 @@ struct __get_pair<0> const _T1& get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} -#ifndef _LIBCPP_CXX03_LANG template static _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 @@ -495,7 +476,6 @@ struct __get_pair<0> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T1&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward(__p.first);} -#endif // _LIBCPP_CXX03_LANG }; template <> @@ -513,7 +493,6 @@ struct __get_pair<1> const _T2& get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} -#ifndef _LIBCPP_CXX03_LANG template static _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 @@ -525,7 +504,6 @@ struct __get_pair<1> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 const _T2&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward(__p.second);} -#endif // _LIBCPP_CXX03_LANG }; template @@ -544,7 +522,6 @@ get(const pair<_T1, _T2>& __p) _NOEXCEPT return __get_pair<_Ip>::get(__p); } -#ifndef _LIBCPP_CXX03_LANG template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, pair<_T1, _T2> >::type&& @@ -560,7 +537,6 @@ get(const pair<_T1, _T2>&& __p) _NOEXCEPT { return __get_pair<_Ip>::get(_VSTD::move(__p)); } -#endif // _LIBCPP_CXX03_LANG #if _LIBCPP_STD_VER > 11 template @@ -619,7 +595,7 @@ constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT return __get_pair<1>::get(_VSTD::move(__p)); } -#endif +#endif // _LIBCPP_STD_VER > 11 _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp index 3fda510..88b646c 100644 --- a/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp +++ b/libcxx/test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp @@ -14,7 +14,7 @@ // const typename tuple_element >::type&& // get(const pair&&); -// UNSUPPORTED: c++03 +// UNSUPPORTED: c++03 && !stdlib=libc++ #include #include @@ -26,12 +26,14 @@ int main(int, char**) { { +#if TEST_STD_VER >= 11 typedef std::pair, short> P; const P p(std::unique_ptr(new int(3)), static_cast(4)); static_assert(std::is_same&&, decltype(std::get<0>(std::move(p)))>::value, ""); static_assert(noexcept(std::get<0>(std::move(p))), ""); const std::unique_ptr&& ptr = std::get<0>(std::move(p)); assert(*ptr == 3); +#endif } { @@ -39,12 +41,15 @@ int main(int, char**) int const y = 43; std::pair const p(x, y); static_assert(std::is_same(std::move(p)))>::value, ""); - static_assert(noexcept(std::get<0>(std::move(p))), ""); static_assert(std::is_same(std::move(p)))>::value, ""); +#if TEST_STD_VER >= 11 + static_assert(noexcept(std::get<0>(std::move(p))), ""); static_assert(noexcept(std::get<1>(std::move(p))), ""); +#endif } { +#if TEST_STD_VER >= 11 int x = 42; int const y = 43; std::pair const p(std::move(x), std::move(y)); @@ -52,6 +57,7 @@ int main(int, char**) static_assert(noexcept(std::get<0>(std::move(p))), ""); static_assert(std::is_same(std::move(p)))>::value, ""); static_assert(noexcept(std::get<1>(std::move(p))), ""); +#endif } #if TEST_STD_VER > 11 diff --git a/libcxx/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp index 12d6ab0..76c1509 100644 --- a/libcxx/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp +++ b/libcxx/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/libcxx/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp index dff26e5..3670c02 100644 --- a/libcxx/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp +++ b/libcxx/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/libcxx/test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp index 9aac804..3a1008c 100644 --- a/libcxx/test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp +++ b/libcxx/test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// -- 2.7.4