From 75eff74803140f4e0d8713b7d55f8da70472b10b Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 22 Jul 2013 16:02:19 +0000 Subject: [PATCH] Make tuple's constructor and std::get<>(tuple) constexpr. Final stage of fixing bug #16599. Thanks to Howard for the review and updates. llvm-svn: 186834 --- libcxx/include/tuple | 114 +++++++++++---------- .../tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp | 20 ++++ .../tuple.tuple/tuple.cnstr/const_Types.pass.cpp | 17 +++ .../tuple.tuple/tuple.cnstr/const_pair.pass.cpp | 12 +++ .../tuple.tuple/tuple.cnstr/convert_copy.pass.cpp | 36 +++++++ .../tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp | 15 +++ .../tuple.tuple/tuple.creation/make_tuple.pass.cpp | 9 ++ .../tuple.tuple/tuple.creation/tuple_cat.pass.cpp | 28 ++++- .../tuple.tuple/tuple.elem/get_const.pass.cpp | 15 +++ .../tuple.tuple/tuple.elem/get_non_const.pass.cpp | 25 +++++ .../tuple.tuple/tuple.elem/tuple.by.type.pass.cpp | 6 ++ .../tuple/tuple.tuple/tuple.rel/eq.pass.cpp | 10 ++ .../tuple/tuple.tuple/tuple.rel/lt.pass.cpp | 12 +++ 13 files changed, 263 insertions(+), 56 deletions(-) diff --git a/libcxx/include/tuple b/libcxx/include/tuple index 5d5debf..94876c9 100644 --- a/libcxx/include/tuple +++ b/libcxx/include/tuple @@ -21,19 +21,19 @@ template class tuple { public: constexpr tuple(); - explicit tuple(const T&...); + explicit tuple(const T&...); // constexpr in C++14 template - explicit tuple(U&&...); + explicit tuple(U&&...); // constexpr in C++14 tuple(const tuple&) = default; tuple(tuple&&) = default; template - tuple(const tuple&); + tuple(const tuple&); // constexpr in C++14 template - tuple(tuple&&); + tuple(tuple&&); // constexpr in C++14 template - tuple(const pair&); // iff sizeof...(T) == 2 + tuple(const pair&); // iff sizeof...(T) == 2 // constexpr in C++14 template - tuple(pair&&); // iff sizeof...(T) == 2 + tuple(pair&&); // iff sizeof...(T) == 2 // constexpr in C++14 // allocator-extended constructors template @@ -72,10 +72,10 @@ public: const unspecified ignore; -template tuple make_tuple(T&&...); +template tuple make_tuple(T&&...); // constexpr in C++14 template tuple forward_as_tuple(T&&...) noexcept; template tuple tie(T&...) noexcept; -template tuple tuple_cat(Tuples&&... tpls); +template tuple tuple_cat(Tuples&&... tpls); // constexpr in C++14 // 20.4.1.4, tuple helper classes: template class tuple_size; // undefined @@ -102,12 +102,12 @@ template constexpr T1&& get(tuple&&) noexcept; // C++14 // 20.4.1.6, relational operators: -template bool operator==(const tuple&, const tuple&); -template bool operator<(const tuple&, const tuple&); -template bool operator!=(const tuple&, const tuple&); -template bool operator>(const tuple&, const tuple&); -template bool operator<=(const tuple&, const tuple&); -template bool operator>=(const tuple&, const tuple&); +template bool operator==(const tuple&, const tuple&); // constexpr in C++14 +template bool operator<(const tuple&, const tuple&); // constexpr in C++14 +template bool operator!=(const tuple&, const tuple&); // constexpr in C++14 +template bool operator>(const tuple&, const tuple&); // constexpr in C++14 +template bool operator<=(const tuple&, const tuple&); // constexpr in C++14 +template bool operator>=(const tuple&, const tuple&); // constexpr in C++14 template struct uses_allocator, Alloc>; @@ -266,7 +266,7 @@ public: template ::value>::type> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) : value(_VSTD::forward<_Tp>(__t)) {static_assert(!is_reference<_Hp>::value || @@ -323,15 +323,17 @@ public: >::value)), "Attempted to construct a reference element in a tuple with an rvalue");} + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_AFTER_CXX11 __tuple_leaf(const __tuple_leaf& __t) _NOEXCEPT_(is_nothrow_copy_constructible<_Hp>::value) : value(__t.get()) {static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");} - template - _LIBCPP_INLINE_VISIBILITY - explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t) - _NOEXCEPT_((is_nothrow_constructible<_Hp, const _Tp&>::value)) - : value(__t.get()) {} + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_AFTER_CXX11 + __tuple_leaf(__tuple_leaf&& __t) _NOEXCEPT_(is_nothrow_move_constructible<_Hp>::value) + : value(_VSTD::move(__t.get())) + {} template _LIBCPP_INLINE_VISIBILITY @@ -349,8 +351,8 @@ public: return 0; } - _LIBCPP_INLINE_VISIBILITY _Hp& get() _NOEXCEPT {return value;} - _LIBCPP_INLINE_VISIBILITY const _Hp& get() const _NOEXCEPT {return value;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;} }; template @@ -379,7 +381,7 @@ public: template ::value>::type> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) : _Hp(_VSTD::forward<_Tp>(__t)) {} @@ -400,12 +402,6 @@ public: template _LIBCPP_INLINE_VISIBILITY - explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t) - _NOEXCEPT_((is_nothrow_constructible<_Hp, const _Tp&>::value)) - : _Hp(__t.get()) {} - - template - _LIBCPP_INLINE_VISIBILITY __tuple_leaf& operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value)) { @@ -421,8 +417,8 @@ public: return 0; } - _LIBCPP_INLINE_VISIBILITY _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);} - _LIBCPP_INLINE_VISIBILITY const _Hp& get() const _NOEXCEPT {return static_cast(*this);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast(*this);} }; template @@ -457,7 +453,7 @@ struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...> template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>, __tuple_indices<_Ul...>, __tuple_types<_Tl...>, @@ -487,7 +483,7 @@ struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...> __tuple_constructible<_Tuple, tuple<_Tp...> >::value >::type > - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all::type>::type>::value...>::value)) : __tuple_leaf<_Indx, _Tp>(_VSTD::forward::value...>::value) {} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all::value...>::value)) : base_(typename __make_tuple_indices::type(), typename __make_tuple_types::type(), @@ -593,7 +589,7 @@ public: bool >::type = false > - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 tuple(_Up&&... __u) _NOEXCEPT_(( is_nothrow_constructible< @@ -633,7 +629,7 @@ public: bool >::type =false > - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit tuple(_Up&&... __u) _NOEXCEPT_(( @@ -681,7 +677,7 @@ public: bool >::type = false > - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible::value)) : base_(_VSTD::forward<_Tuple>(__t)) {} @@ -693,7 +689,7 @@ public: bool >::type = false > - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible::value)) : base_(_VSTD::forward<_Tuple>(__t)) {} @@ -889,7 +885,7 @@ struct __make_tuple_return }; template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 tuple::type...> make_tuple(_Tp&&... __t) { @@ -897,6 +893,14 @@ make_tuple(_Tp&&... __t) } template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +tuple<_Tp&&...> +__forward_as_tuple(_Tp&&... __t) _NOEXCEPT +{ + return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...); +} + +template inline _LIBCPP_INLINE_VISIBILITY tuple<_Tp&&...> forward_as_tuple(_Tp&&... __t) _NOEXCEPT @@ -908,7 +912,7 @@ template struct __tuple_equal { template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _Tp& __x, const _Up& __y) { return __tuple_equal<_Ip - 1>()(__x, __y) && get<_Ip-1>(__x) == get<_Ip-1>(__y); @@ -919,7 +923,7 @@ template <> struct __tuple_equal<0> { template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _Tp&, const _Up&) { return true; @@ -927,7 +931,7 @@ struct __tuple_equal<0> }; template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -935,7 +939,7 @@ operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -946,7 +950,7 @@ template struct __tuple_less { template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _Tp& __x, const _Up& __y) { return __tuple_less<_Ip-1>()(__x, __y) || @@ -958,7 +962,7 @@ template <> struct __tuple_less<0> { template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _Tp&, const _Up&) { return false; @@ -966,7 +970,7 @@ struct __tuple_less<0> }; template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -974,7 +978,7 @@ operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -982,7 +986,7 @@ operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -990,7 +994,7 @@ operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { @@ -1048,7 +1052,7 @@ struct __tuple_cat_return<> typedef tuple<> type; }; -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 tuple<> tuple_cat() { @@ -1095,16 +1099,16 @@ template struct __tuple_cat, __tuple_indices<_I0...>, __tuple_indices<_J0...> > { template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename __tuple_cat_return_ref&&, _Tuple0&&>::type operator()(tuple<_Types...> __t, _Tuple0&& __t0) { - return _VSTD::forward_as_tuple(_VSTD::forward<_Types>(get<_I0>(__t))..., + return __forward_as_tuple(_VSTD::forward<_Types>(get<_I0>(__t))..., get<_J0>(_VSTD::forward<_Tuple0>(__t0))...); } template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename __tuple_cat_return_ref&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls) { @@ -1114,7 +1118,7 @@ struct __tuple_cat, __tuple_indices<_I0...>, __tuple_indices<_J tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>, typename __make_tuple_indices::value>::type, typename __make_tuple_indices::value>::type>() - (_VSTD::forward_as_tuple( + (__forward_as_tuple( _VSTD::forward<_Types>(get<_I0>(__t))..., get<_J0>(_VSTD::forward<_Tuple0>(__t0))... ), @@ -1124,7 +1128,7 @@ struct __tuple_cat, __tuple_indices<_I0...>, __tuple_indices<_J }; template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename __tuple_cat_return<_Tuple0, _Tuples...>::type tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) { diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp index 37d58b8..d6fbdae 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp @@ -19,6 +19,17 @@ #include "../MoveOnly.h" +#if _LIBCPP_STD_VER > 11 + +struct Empty {}; +struct A +{ + int id_; + explicit constexpr A(int i) : id_(i) {} +}; + +#endif + int main() { { @@ -52,4 +63,13 @@ int main() assert(std::get<1>(t) == MoveOnly()); assert(std::get<2>(t) == MoveOnly()); } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple t0{Empty()}; + } + { + constexpr std::tuple t(3, 2); + static_assert(std::get<0>(t).id_ == 3, ""); + } +#endif } diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp index 188d632..04cb3d5 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp @@ -23,11 +23,28 @@ int main() std::tuple t(2); assert(std::get<0>(t) == 2); } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple t(2); + static_assert(std::get<0>(t) == 2, ""); + } + { + constexpr std::tuple t; + static_assert(std::get<0>(t) == 0, ""); + } +#endif { std::tuple t(2, 0); assert(std::get<0>(t) == 2); assert(std::get<1>(t) == nullptr); } +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple t(2, nullptr); + static_assert(std::get<0>(t) == 2, ""); + static_assert(std::get<1>(t) == nullptr, ""); + } +#endif { std::tuple t(2, nullptr); assert(std::get<0>(t) == 2); diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp index 54807f1..d40196b 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp @@ -27,4 +27,16 @@ int main() assert(std::get<0>(t1) == 2); assert(std::get<1>(t1) == short('a')); } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P0; + typedef std::tuple T1; + constexpr P0 p0(2.5, 'a'); + constexpr T1 t1 = p0; + static_assert(std::get<0>(t1) != std::get<0>(p0), ""); + static_assert(std::get<1>(t1) == std::get<1>(p0), ""); + static_assert(std::get<0>(t1) == 2, ""); + static_assert(std::get<1>(t1) == short('a'), ""); + } +#endif } diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp index 33aed89..bcdb9d9 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp @@ -30,6 +30,26 @@ struct D explicit D(int i) : B(i) {} }; +#if _LIBCPP_STD_VER > 11 + +struct A +{ + int id_; + + constexpr A(int i) : id_(i) {} + friend constexpr bool operator==(const A& x, const A& y) {return x.id_ == y.id_;} +}; + +struct C +{ + int id_; + + constexpr explicit C(int i) : id_(i) {} + friend constexpr bool operator==(const C& x, const C& y) {return x.id_ == y.id_;} +}; + +#endif + int main() { { @@ -39,6 +59,22 @@ int main() T1 t1 = t0; assert(std::get<0>(t1) == 2); } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple T0; + typedef std::tuple T1; + constexpr T0 t0(2.5); + constexpr T1 t1 = t0; + static_assert(std::get<0>(t1) == 2, ""); + } + { + typedef std::tuple T0; + typedef std::tuple T1; + constexpr T0 t0(2); + constexpr T1 t1{t0}; + static_assert(std::get<0>(t1) == C(2), ""); + } +#endif { typedef std::tuple T0; typedef std::tuple T1; diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp index 7de3ef6..fd953f8 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp @@ -17,6 +17,8 @@ #include #include +struct Empty {}; + int main() { { @@ -45,4 +47,17 @@ int main() assert(std::get<1>(t) == 'a'); assert(std::get<2>(t) == "some text"); } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple T; + constexpr T t0(2); + constexpr T t = t0; + static_assert(std::get<0>(t) == 2, ""); + } + { + typedef std::tuple T; + constexpr T t0; + constexpr T t = t0; + } +#endif } diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp index f3dba38..4b6649a 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp @@ -38,4 +38,13 @@ int main() assert(i == 0); assert(j == 0); } +#if _LIBCPP_STD_VER > 11 + { + constexpr auto t1 = std::make_tuple(0, 1, 3.14); + constexpr int i1 = std::get<1>(t1); + constexpr double d1 = std::get<2>(t1); + static_assert (i1 == 1, "" ); + static_assert (d1 == 3.14, "" ); + } +#endif } diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp index 7cfc736..b47842d 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp @@ -36,12 +36,38 @@ int main() { std::tuple<> t = std::tuple_cat(std::array()); } - { std::tuple t1(1); std::tuple t = std::tuple_cat(t1); assert(std::get<0>(t) == 1); } + +#if _LIBCPP_STD_VER > 11 + { + constexpr std::tuple<> t = std::tuple_cat(); + } + { + constexpr std::tuple<> t1; + constexpr std::tuple<> t2 = std::tuple_cat(t1); + } + { + constexpr std::tuple<> t = std::tuple_cat(std::tuple<>()); + } + { + constexpr std::tuple<> t = std::tuple_cat(std::array()); + } + { + constexpr std::tuple t1(1); + constexpr std::tuple t = std::tuple_cat(t1); + static_assert(std::get<0>(t) == 1, ""); + } + { + constexpr std::tuple t1(1); + constexpr std::tuple t = std::tuple_cat(t1, t1); + static_assert(std::get<0>(t) == 1, ""); + static_assert(std::get<1>(t) == 1, ""); + } +#endif { std::tuple t = std::tuple_cat(std::tuple(1, 2)); diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp index 03a00ae..0ba898d 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp @@ -19,6 +19,8 @@ #include #include +struct Empty {}; + int main() { { @@ -32,6 +34,19 @@ int main() assert(std::get<0>(t) == "high"); assert(std::get<1>(t) == 5); } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple T; + constexpr T t(2.718, 5); + static_assert(std::get<0>(t) == 2.718, ""); + static_assert(std::get<1>(t) == 5, ""); + } + { + typedef std::tuple T; + constexpr T t{Empty()}; + constexpr Empty e = std::get<0>(t); + } +#endif { typedef std::tuple T; double d = 1.5; diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp index bcbf10e..3b98b5e 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp @@ -19,6 +19,20 @@ #include #include +#if __cplusplus > 201103L + +struct Empty {}; + +struct S { + std::tuple a; + int k; + Empty e; + constexpr S() : a{1,Empty{}}, k(std::get<0>(a)), e(std::get<1>(a)) {} + }; + +constexpr std::tuple getP () { return { 3, 4 }; } +#endif + int main() { { @@ -53,4 +67,15 @@ int main() assert(std::get<2>(t) == 4); assert(d == 2.5); } +#if _LIBCPP_STD_VER > 11 + { // get on an rvalue tuple + static_assert ( std::get<0> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 0, "" ); + static_assert ( std::get<1> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 1, "" ); + static_assert ( std::get<2> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 2, "" ); + static_assert ( std::get<3> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 3, "" ); + static_assert(S().k == 1, ""); + static_assert(std::get<1>(getP()) == 4, ""); + } +#endif + } diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp index 1835a9f..5cc33e1 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp @@ -33,6 +33,12 @@ int main() } { + constexpr std::tuple p5 { 1, 2, 3.4, 5.6 }; + static_assert ( std::get(p5) == 1, "" ); + static_assert ( std::get(p5) == 2, "" ); + } + + { const std::tuple p5 { 1, 2, 3.4, 5.6 }; const int &i1 = std::get(p5); const int &i2 = std::get(p5); diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp index fff93f5..e05cd61 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp @@ -141,4 +141,14 @@ int main() assert(!(t1 == t2)); assert(t1 != t2); } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple T1; + typedef std::tuple T2; + constexpr T1 t1(1, 2, 3); + constexpr T2 t2(1.1, 3, 2); + static_assert(!(t1 == t2), ""); + static_assert(t1 != t2, ""); + } +#endif } diff --git a/libcxx/test/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp b/libcxx/test/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp index dcefa17..f09a105 100644 --- a/libcxx/test/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp +++ b/libcxx/test/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp @@ -193,4 +193,16 @@ int main() assert(!(t1 > t2)); assert(!(t1 >= t2)); } +#if _LIBCPP_STD_VER > 11 + { + typedef std::tuple T1; + typedef std::tuple T2; + constexpr T1 t1(1, 2, 3); + constexpr T2 t2(1, 2, 4); + static_assert( (t1 < t2), ""); + static_assert( (t1 <= t2), ""); + static_assert(!(t1 > t2), ""); + static_assert(!(t1 >= t2), ""); + } +#endif } -- 2.7.4