[libcxx-commits] [libcxx] e0b3356 - [libc++] Enable rvalue overloads for pair in C++03
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Sep 5 05:40:26 PDT 2022
Author: Nikolas Klauser
Date: 2022-09-05T14:40:17+02:00
New Revision: e0b3356e67a9288accab0f079963397a4421923c
URL: https://github.com/llvm/llvm-project/commit/e0b3356e67a9288accab0f079963397a4421923c
DIFF: https://github.com/llvm/llvm-project/commit/e0b3356e67a9288accab0f079963397a4421923c.diff
LOG: [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
Added:
Modified:
libcxx/include/__utility/pair.h
libcxx/test/std/utilities/utility/pairs/pair.astuple/get_const_rv.pass.cpp
libcxx/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp
libcxx/test/std/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp
libcxx/test/std/utilities/utility/pairs/pairs.spec/non_member_swap.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__utility/pair.h b/libcxx/include/__utility/pair.h
index 51aa3e6ea517..6669b9a62748 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 <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
pair<typename __unwrap_ref_decay<_T1>::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 <class _T1, class _T2>
-inline _LIBCPP_INLINE_VISIBILITY
-pair<_T1,_T2>
-make_pair(_T1 __x, _T2 __y)
-{
- return pair<_T1, _T2>(__x, __y);
-}
-
-#endif // _LIBCPP_CXX03_LANG
-
template <class _T1, class _T2>
struct _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> >
: public integral_constant<size_t, 2> {};
@@ -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 <class _T1, class _T2>
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<const _T1>(__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 <class _T1, class _T2>
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<const _T2>(__p.second);}
-#endif // _LIBCPP_CXX03_LANG
};
template <size_t _Ip, class _T1, class _T2>
@@ -544,7 +522,6 @@ get(const pair<_T1, _T2>& __p) _NOEXCEPT
return __get_pair<_Ip>::get(__p);
}
-#ifndef _LIBCPP_CXX03_LANG
template <size_t _Ip, class _T1, class _T2>
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 <class _T1, class _T2>
@@ -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 3fda510f448b..88b646c09d26 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<I, std::pair<T1, T2> >::type&&
// get(const pair<T1, T2>&&);
-// UNSUPPORTED: c++03
+// UNSUPPORTED: c++03 && !stdlib=libc++
#include <utility>
#include <memory>
@@ -26,12 +26,14 @@
int main(int, char**)
{
{
+#if TEST_STD_VER >= 11
typedef std::pair<std::unique_ptr<int>, short> P;
const P p(std::unique_ptr<int>(new int(3)), static_cast<short>(4));
static_assert(std::is_same<const std::unique_ptr<int>&&, decltype(std::get<0>(std::move(p)))>::value, "");
static_assert(noexcept(std::get<0>(std::move(p))), "");
const std::unique_ptr<int>&& 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<int&, int const&> const p(x, y);
static_assert(std::is_same<int&, decltype(std::get<0>(std::move(p)))>::value, "");
- static_assert(noexcept(std::get<0>(std::move(p))), "");
static_assert(std::is_same<int const&, decltype(std::get<1>(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<int&&, int const&&> 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<int const&&, decltype(std::get<1>(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 12d6ab019170..76c1509fe71c 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 dff26e57f0b3..3670c023240e 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 9aac80468d01..3a1008c8d182 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
//
//===----------------------------------------------------------------------===//
More information about the libcxx-commits
mailing list