[libcxx] r186834 - Make tuple's constructor and std::get<>(tuple) constexpr. Final stage of fixing bug #16599. Thanks to Howard for the review and updates.
Marshall Clow
mclow.lists at gmail.com
Mon Jul 22 09:02:20 PDT 2013
Author: marshall
Date: Mon Jul 22 11:02:19 2013
New Revision: 186834
URL: http://llvm.org/viewvc/llvm-project?rev=186834&view=rev
Log:
Make tuple's constructor and std::get<>(tuple) constexpr. Final stage of fixing bug #16599. Thanks to Howard for the review and updates.
Modified:
libcxx/trunk/include/tuple
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp
libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp
Modified: libcxx/trunk/include/tuple
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/tuple?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/include/tuple (original)
+++ libcxx/trunk/include/tuple Mon Jul 22 11:02:19 2013
@@ -21,19 +21,19 @@ template <class... T>
class tuple {
public:
constexpr tuple();
- explicit tuple(const T&...);
+ explicit tuple(const T&...); // constexpr in C++14
template <class... U>
- explicit tuple(U&&...);
+ explicit tuple(U&&...); // constexpr in C++14
tuple(const tuple&) = default;
tuple(tuple&&) = default;
template <class... U>
- tuple(const tuple<U...>&);
+ tuple(const tuple<U...>&); // constexpr in C++14
template <class... U>
- tuple(tuple<U...>&&);
+ tuple(tuple<U...>&&); // constexpr in C++14
template <class U1, class U2>
- tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2
+ tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
template <class U1, class U2>
- tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2
+ tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
// allocator-extended constructors
template <class Alloc>
@@ -72,10 +72,10 @@ public:
const unspecified ignore;
-template <class... T> tuple<V...> make_tuple(T&&...);
+template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept;
template <class... T> tuple<T&...> tie(T&...) noexcept;
-template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls);
+template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
// 20.4.1.4, tuple helper classes:
template <class T> class tuple_size; // undefined
@@ -102,12 +102,12 @@ template <class T1, class... T>
constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
// 20.4.1.6, relational operators:
-template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&);
-template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);
-template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&);
-template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);
-template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&);
-template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&);
+template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
+template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
+template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
+template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
+template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
+template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
template <class... Types, class Alloc>
struct uses_allocator<tuple<Types...>, Alloc>;
@@ -266,7 +266,7 @@ public:
template <class _Tp,
class = typename enable_if<is_constructible<_Hp, _Tp>::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 <class _Tp>
- _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 <class _Tp>
_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 <size_t _Ip, class _Hp>
@@ -379,7 +381,7 @@ public:
template <class _Tp,
class = typename enable_if<is_constructible<_Hp, _Tp>::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 <class _Tp>
_LIBCPP_INLINE_VISIBILITY
- explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
- _NOEXCEPT_((is_nothrow_constructible<_Hp, const _Tp&>::value))
- : _Hp(__t.get()) {}
-
- template <class _Tp>
- _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<const _Hp&>(*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<const _Hp&>(*this);}
};
template <class ..._Tp>
@@ -457,7 +453,7 @@ struct __tuple_impl<__tuple_indices<_Ind
template <size_t ..._Uf, class ..._Tf,
size_t ..._Ul, class ..._Tl, class ..._Up>
- _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<_Ind
__tuple_constructible<_Tuple, tuple<_Tp...> >::value
>::type
>
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
__tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
: __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
@@ -558,7 +554,7 @@ public:
_LIBCPP_CONSTEXPR tuple()
_NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
: base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Tp)>::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<base, _Tuple>::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<base, _Tuple>::value))
: base_(_VSTD::forward<_Tuple>(__t)) {}
@@ -889,7 +885,7 @@ struct __make_tuple_return
};
template <class... _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
tuple<typename __make_tuple_return<_Tp>::type...>
make_tuple(_Tp&&... __t)
{
@@ -897,6 +893,14 @@ make_tuple(_Tp&&... __t)
}
template <class... _Tp>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+tuple<_Tp&&...>
+__forward_as_tuple(_Tp&&... __t) _NOEXCEPT
+{
+ return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
+}
+
+template <class... _Tp>
inline _LIBCPP_INLINE_VISIBILITY
tuple<_Tp&&...>
forward_as_tuple(_Tp&&... __t) _NOEXCEPT
@@ -908,7 +912,7 @@ template <size_t _Ip>
struct __tuple_equal
{
template <class _Tp, class _Up>
- _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 <class _Tp, class _Up>
- _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 <class ..._Tp, class ..._Up>
-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, con
}
template <class ..._Tp, class ..._Up>
-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 <size_t _Ip>
struct __tuple_less
{
template <class _Tp, class _Up>
- _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 <class _Tp, class _Up>
- _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 <class ..._Tp, class ..._Up>
-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, cons
}
template <class ..._Tp, class ..._Up>
-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, cons
}
template <class ..._Tp, class ..._Up>
-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, con
}
template <class ..._Tp, class ..._Up>
-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 <class ..._Types, size_t ..._I0
struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
{
template <class _Tuple0>
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename __tuple_cat_return_ref<tuple<_Types...>&&, _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 <class _Tuple0, class _Tuple1, class ..._Tuples>
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
{
@@ -1114,7 +1118,7 @@ struct __tuple_cat<tuple<_Types...>, __t
tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
typename __make_tuple_indices<tuple_size<_T1>::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<_Types...>, __t
};
template <class _Tuple0, class... _Tuples>
-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)
{
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/UTypes.pass.cpp Mon Jul 22 11:02:19 2013
@@ -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<Empty> t0{Empty()};
+ }
+ {
+ constexpr std::tuple<A, A> t(3, 2);
+ static_assert(std::get<0>(t).id_ == 3, "");
+ }
+#endif
}
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_Types.pass.cpp Mon Jul 22 11:02:19 2013
@@ -23,11 +23,28 @@ int main()
std::tuple<int> t(2);
assert(std::get<0>(t) == 2);
}
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr std::tuple<int> t(2);
+ static_assert(std::get<0>(t) == 2, "");
+ }
+ {
+ constexpr std::tuple<int> t;
+ static_assert(std::get<0>(t) == 0, "");
+ }
+#endif
{
std::tuple<int, char*> t(2, 0);
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == nullptr);
}
+#if _LIBCPP_STD_VER > 11
+ {
+ constexpr std::tuple<int, char*> t(2, nullptr);
+ static_assert(std::get<0>(t) == 2, "");
+ static_assert(std::get<1>(t) == nullptr, "");
+ }
+#endif
{
std::tuple<int, char*> t(2, nullptr);
assert(std::get<0>(t) == 2);
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/const_pair.pass.cpp Mon Jul 22 11:02:19 2013
@@ -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<double, char> P0;
+ typedef std::tuple<int, short> 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
}
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/convert_copy.pass.cpp Mon Jul 22 11:02:19 2013
@@ -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<double> T0;
+ typedef std::tuple<A> T1;
+ constexpr T0 t0(2.5);
+ constexpr T1 t1 = t0;
+ static_assert(std::get<0>(t1) == 2, "");
+ }
+ {
+ typedef std::tuple<int> T0;
+ typedef std::tuple<C> T1;
+ constexpr T0 t0(2);
+ constexpr T1 t1{t0};
+ static_assert(std::get<0>(t1) == C(2), "");
+ }
+#endif
{
typedef std::tuple<double, char> T0;
typedef std::tuple<int, int> T1;
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.cnstr/copy.pass.cpp Mon Jul 22 11:02:19 2013
@@ -17,6 +17,8 @@
#include <string>
#include <cassert>
+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<int> T;
+ constexpr T t0(2);
+ constexpr T t = t0;
+ static_assert(std::get<0>(t) == 2, "");
+ }
+ {
+ typedef std::tuple<Empty> T;
+ constexpr T t0;
+ constexpr T t = t0;
+ }
+#endif
}
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp Mon Jul 22 11:02:19 2013
@@ -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
}
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.creation/tuple_cat.pass.cpp Mon Jul 22 11:02:19 2013
@@ -36,12 +36,38 @@ int main()
{
std::tuple<> t = std::tuple_cat(std::array<int, 0>());
}
-
{
std::tuple<int> t1(1);
std::tuple<int> 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<int, 0>());
+ }
+ {
+ constexpr std::tuple<int> t1(1);
+ constexpr std::tuple<int> t = std::tuple_cat(t1);
+ static_assert(std::get<0>(t) == 1, "");
+ }
+ {
+ constexpr std::tuple<int> t1(1);
+ constexpr std::tuple<int, int> t = std::tuple_cat(t1, t1);
+ static_assert(std::get<0>(t) == 1, "");
+ static_assert(std::get<1>(t) == 1, "");
+ }
+#endif
{
std::tuple<int, MoveOnly> t =
std::tuple_cat(std::tuple<int, MoveOnly>(1, 2));
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp Mon Jul 22 11:02:19 2013
@@ -19,6 +19,8 @@
#include <string>
#include <cassert>
+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<double, int> 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<Empty> T;
+ constexpr T t{Empty()};
+ constexpr Empty e = std::get<0>(t);
+ }
+#endif
{
typedef std::tuple<double&, std::string, int> T;
double d = 1.5;
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/get_non_const.pass.cpp Mon Jul 22 11:02:19 2013
@@ -19,6 +19,20 @@
#include <string>
#include <cassert>
+#if __cplusplus > 201103L
+
+struct Empty {};
+
+struct S {
+ std::tuple<int, Empty> a;
+ int k;
+ Empty e;
+ constexpr S() : a{1,Empty{}}, k(std::get<0>(a)), e(std::get<1>(a)) {}
+ };
+
+constexpr std::tuple<int, int> 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
+
}
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.elem/tuple.by.type.pass.cpp Mon Jul 22 11:02:19 2013
@@ -33,6 +33,12 @@ int main()
}
{
+ constexpr std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 };
+ static_assert ( std::get<int>(p5) == 1, "" );
+ static_assert ( std::get<const int>(p5) == 2, "" );
+ }
+
+ {
const std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 };
const int &i1 = std::get<int>(p5);
const int &i2 = std::get<const int>(p5);
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.rel/eq.pass.cpp Mon Jul 22 11:02:19 2013
@@ -141,4 +141,14 @@ int main()
assert(!(t1 == t2));
assert(t1 != t2);
}
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef std::tuple<char, int, double> T1;
+ typedef std::tuple<double, char, int> T2;
+ constexpr T1 t1(1, 2, 3);
+ constexpr T2 t2(1.1, 3, 2);
+ static_assert(!(t1 == t2), "");
+ static_assert(t1 != t2, "");
+ }
+#endif
}
Modified: libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp?rev=186834&r1=186833&r2=186834&view=diff
==============================================================================
--- libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp (original)
+++ libcxx/trunk/test/utilities/tuple/tuple.tuple/tuple.rel/lt.pass.cpp Mon Jul 22 11:02:19 2013
@@ -193,4 +193,16 @@ int main()
assert(!(t1 > t2));
assert(!(t1 >= t2));
}
+#if _LIBCPP_STD_VER > 11
+ {
+ typedef std::tuple<char, int, double> T1;
+ typedef std::tuple<double, char, int> 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
}
More information about the cfe-commits
mailing list