diff --git a/include/utility b/include/utility index 46a8803a0..2d2670d69 100644 --- a/include/utility +++ b/include/utility @@ -66,10 +66,10 @@ struct pair pair(const pair&) = default; pair(pair&&) = default; constexpr pair(); - pair(const T1& x, const T2& y); - template pair(U&& x, V&& y); - template pair(const pair& p); - template pair(pair&& p); + pair(const T1& x, const T2& y); // constexpr in C++14 + template pair(U&& x, V&& y); // constexpr in C++14 + template pair(const pair& p); // constexpr in C++14 + template pair(pair&& p); // constexpr in C++14 template pair(piecewise_construct_t, tuple first_args, tuple second_args); @@ -83,14 +83,14 @@ struct pair noexcept(swap(second, p.second))); }; -template bool operator==(const pair&, const pair&); -template bool operator!=(const pair&, const pair&); -template bool operator< (const pair&, const pair&); -template bool operator> (const pair&, const pair&); -template bool operator>=(const pair&, const pair&); -template bool operator<=(const pair&, const pair&); +template bool operator==(const pair&, const pair&); // constexpr in C++14 +template bool operator!=(const pair&, const pair&); // constexpr in C++14 +template bool operator< (const pair&, const pair&); // constexpr in C++14 +template bool operator> (const pair&, const pair&); // constexpr in C++14 +template bool operator>=(const pair&, const pair&); // constexpr in C++14 +template bool operator<=(const pair&, const pair&); // constexpr in C++14 -template pair make_pair(T1&&, T2&&); +template pair make_pair(T1&&, T2&&); // constexpr in C++14 template void swap(pair& x, pair& y) noexcept(noexcept(x.swap(y))); @@ -258,11 +258,12 @@ struct _LIBCPP_TYPE_VIS pair _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {} - _LIBCPP_INLINE_VISIBILITY pair(const _T1& __x, const _T2& __y) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + pair(const _T1& __x, const _T2& __y) : first(__x), second(__y) {} template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair(const pair<_U1, _U2>& __p #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE ,typename enable_if::value && @@ -271,6 +272,10 @@ struct _LIBCPP_TYPE_VIS pair ) : first(__p.first), second(__p.second) {} +#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + _LIBCPP_INLINE_VISIBILITY + pair(const pair& __p) = default; +#else _LIBCPP_INLINE_VISIBILITY pair(const pair& __p) _NOEXCEPT_(is_nothrow_copy_constructible::value && @@ -279,6 +284,7 @@ struct _LIBCPP_TYPE_VIS pair second(__p.second) { } +#endif _LIBCPP_INLINE_VISIBILITY pair& operator=(const pair& __p) @@ -295,20 +301,24 @@ struct _LIBCPP_TYPE_VIS pair template ::value && is_convertible<_U2, second_type>::value>::type> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair(_U1&& __u1, _U2&& __u2) : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair(pair<_U1, _U2>&& __p, typename enable_if::value && is_convertible<_U2, _T2>::value>::type* = 0) : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} +#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + _LIBCPP_INLINE_VISIBILITY + pair(pair&& __p) = default; +#else _LIBCPP_INLINE_VISIBILITY pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible::value && is_nothrow_move_constructible::value) @@ -316,6 +326,7 @@ struct _LIBCPP_TYPE_VIS pair second(_VSTD::forward(__p.second)) { } +#endif _LIBCPP_INLINE_VISIBILITY pair& @@ -331,7 +342,7 @@ struct _LIBCPP_TYPE_VIS pair template::value>::type> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair(_Tuple&& __p) : first(_VSTD::forward::type>::type>(get<0>(__p))), @@ -387,7 +398,7 @@ private: }; template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -395,7 +406,7 @@ operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -403,7 +414,7 @@ operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -411,7 +422,7 @@ operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -419,7 +430,7 @@ operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -427,7 +438,7 @@ operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) { @@ -472,7 +483,7 @@ struct __make_pair_return }; template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair::type, typename __make_pair_return<_T2>::type> make_pair(_T1&& __t1, _T2&& __t2) { @@ -615,42 +626,42 @@ template _LIBCPP_INLINE_VISIBILITY inline constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT { - return __get_pair<0>::get(__p); + return __get_pair<0>::get(__p); } template _LIBCPP_INLINE_VISIBILITY inline constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT { - return __get_pair<0>::get(__p); + return __get_pair<0>::get(__p); } template _LIBCPP_INLINE_VISIBILITY inline constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT { - return __get_pair<0>::get(_VSTD::move(__p)); + return __get_pair<0>::get(_VSTD::move(__p)); } template _LIBCPP_INLINE_VISIBILITY inline constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT { - return __get_pair<1>::get(__p); + return __get_pair<1>::get(__p); } template _LIBCPP_INLINE_VISIBILITY inline constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT { - return __get_pair<1>::get(__p); + return __get_pair<1>::get(__p); } template _LIBCPP_INLINE_VISIBILITY inline constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT { - return __get_pair<1>::get(_VSTD::move(__p)); + return __get_pair<1>::get(_VSTD::move(__p)); } #endif diff --git a/test/utilities/utility/pairs/pair.astuple/get_const.pass.cpp b/test/utilities/utility/pairs/pair.astuple/get_const.pass.cpp index a9c44818c..43e70ea52 100644 --- a/test/utilities/utility/pairs/pair.astuple/get_const.pass.cpp +++ b/test/utilities/utility/pairs/pair.astuple/get_const.pass.cpp @@ -26,4 +26,15 @@ int main() assert(std::get<0>(p) == 3); assert(std::get<1>(p) == 4); } + +#if __cplusplus > 201103L + { + typedef std::pair P; + constexpr P p1(3, 4); + static_assert(p1.first == 3, "" ); // for now! + static_assert(p1.second == 4, "" ); // for now! +// static_assert(std::get<0>(p1) == 3, ""); +// static_assert(std::get<1>(p1) == 4, ""); + } +#endif } diff --git a/test/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp b/test/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp index de3a86417..2041b39c2 100644 --- a/test/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp +++ b/test/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp @@ -22,9 +22,20 @@ class A public: A(int data) : data_(data) {} - bool operator==(const A& a) {return data_ == a.data_;} + bool operator==(const A& a) const {return data_ == a.data_;} }; +#if _LIBCPP_STD_VER > 11 +class AC +{ + int data_; +public: + constexpr AC(int data) : data_(data) {} + + constexpr bool operator==(const AC& a) const {return data_ == a.data_;} +}; +#endif + int main() { { @@ -39,4 +50,19 @@ int main() assert(p.first == A(1)); assert(p.second == 2); } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P; + constexpr P p(3.5f, 0); + static_assert(p.first == 3.5f, ""); + static_assert(p.second == nullptr, ""); + } + { + typedef std::pair P; + constexpr P p(1, 2); + static_assert(p.first == AC(1), ""); + static_assert(p.second == 2, ""); + } +#endif } diff --git a/test/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp b/test/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp index bcb3e5335..286cce47f 100644 --- a/test/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp +++ b/test/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp @@ -26,4 +26,15 @@ int main() assert(p2.first == 3); assert(p2.second == 4); } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P1; + typedef std::pair P2; + constexpr P1 p1(3, 4); + constexpr P2 p2 = p1; + static_assert(p2.first == 3, ""); + static_assert(p2.second == 4, ""); + } +#endif } diff --git a/test/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp b/test/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp index 433b0ae08..b163f246c 100644 --- a/test/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp +++ b/test/utilities/utility/pairs/pairs.pair/copy_ctor.pass.cpp @@ -25,4 +25,14 @@ int main() assert(p2.first == 3); assert(p2.second == 4); } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P1; + constexpr P1 p1(3, 4); + constexpr P1 p2 = p1; + static_assert(p2.first == 3, ""); + static_assert(p2.second == 4, ""); + } +#endif } diff --git a/test/utilities/utility/pairs/pairs.pair/default.pass.cpp b/test/utilities/utility/pairs/pairs.pair/default.pass.cpp index 644779e0e..18fdb47bb 100644 --- a/test/utilities/utility/pairs/pairs.pair/default.pass.cpp +++ b/test/utilities/utility/pairs/pairs.pair/default.pass.cpp @@ -18,8 +18,19 @@ int main() { + { typedef std::pair P; P p; assert(p.first == 0.0f); assert(p.second == nullptr); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P; + constexpr P p; + static_assert(p.first == 0.0f, ""); + static_assert(p.second == nullptr, ""); + } +#endif } diff --git a/test/utilities/utility/pairs/pairs.spec/comparison.pass.cpp b/test/utilities/utility/pairs/pairs.spec/comparison.pass.cpp index 821f4cd7b..9ba8532ab 100644 --- a/test/utilities/utility/pairs/pairs.spec/comparison.pass.cpp +++ b/test/utilities/utility/pairs/pairs.spec/comparison.pass.cpp @@ -78,4 +78,18 @@ int main() assert( (p1 > p2)); assert( (p1 >= p2)); } + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P; + constexpr P p1(3, 4); + constexpr P p2(3, 2); + static_assert(!(p1 == p2), ""); + static_assert( (p1 != p2), ""); + static_assert(!(p1 < p2), ""); + static_assert(!(p1 <= p2), ""); + static_assert( (p1 > p2), ""); + static_assert( (p1 >= p2), ""); + } +#endif } diff --git a/test/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp b/test/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp index a3d132ff5..48e09735a 100644 --- a/test/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp +++ b/test/utilities/utility/pairs/pairs.spec/make_pair.pass.cpp @@ -23,6 +23,7 @@ int main() assert(p1.first == 3); assert(p1.second == 4); } + #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { typedef std::pair, short> P1; @@ -37,4 +38,14 @@ int main() assert(p1.second == 4); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P1; + constexpr P1 p1 = std::make_pair(3, 4); + static_assert(p1.first == 3, ""); + static_assert(p1.second == 4, ""); + } +#endif + }