[libcxx] Move tuple_size and tuple_element overloads for pair and array out of !defined(_LIBCPP_HAS_NO_VARIADICS) block.
Summary: There is no reason to guard `tuple_size`, `tuple_element` and `get<I>(...)` for pair and array inside of `<__tuple>` so that they are only available when we have variadic templates. This requires there be redundant declarations and definitions. It also makes it easy to get things wrong. For example the following code should compile (and does in c++11). ``` #define _LIBCPP_HAS_NO_VARIADICS #include <array> int main() { static_assert((std::tuple_size<std::array<int, 10> volatile>::value == 10), ""); } ``` This patch lifts the non-variadic parts of `tuple_size`, `tuple_types`, and `get<I>(...)` to the top of `<__tuple>` where they don't require variadic templates. This patch also removes `<__tuple_03>` because there is no longer a need for it. Reviewers: danalbert, K-ballo, mclow.lists Reviewed By: mclow.lists Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D7774 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@232492 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -14,20 +14,41 @@
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
template <class T>
|
||||
void test()
|
||||
{
|
||||
{
|
||||
typedef double T;
|
||||
typedef std::array<T, 3> C;
|
||||
static_assert((std::is_same<std::tuple_element<0, C>::type, T>::value), "");
|
||||
static_assert((std::is_same<std::tuple_element<1, C>::type, T>::value), "");
|
||||
static_assert((std::is_same<std::tuple_element<2, C>::type, T>::value), "");
|
||||
typedef T Exp;
|
||||
typedef std::array<T, 3> C;
|
||||
static_assert((std::is_same<typename std::tuple_element<0, C>::type, Exp>::value), "");
|
||||
static_assert((std::is_same<typename std::tuple_element<1, C>::type, Exp>::value), "");
|
||||
static_assert((std::is_same<typename std::tuple_element<2, C>::type, Exp>::value), "");
|
||||
}
|
||||
{
|
||||
typedef int T;
|
||||
typedef std::array<T, 3> C;
|
||||
static_assert((std::is_same<std::tuple_element<0, C>::type, T>::value), "");
|
||||
static_assert((std::is_same<std::tuple_element<1, C>::type, T>::value), "");
|
||||
static_assert((std::is_same<std::tuple_element<2, C>::type, T>::value), "");
|
||||
typedef T const Exp;
|
||||
typedef std::array<T, 3> const C;
|
||||
static_assert((std::is_same<typename std::tuple_element<0, C>::type, Exp>::value), "");
|
||||
static_assert((std::is_same<typename std::tuple_element<1, C>::type, Exp>::value), "");
|
||||
static_assert((std::is_same<typename std::tuple_element<2, C>::type, Exp>::value), "");
|
||||
}
|
||||
{
|
||||
typedef T volatile Exp;
|
||||
typedef std::array<T, 3> volatile C;
|
||||
static_assert((std::is_same<typename std::tuple_element<0, C>::type, Exp>::value), "");
|
||||
static_assert((std::is_same<typename std::tuple_element<1, C>::type, Exp>::value), "");
|
||||
static_assert((std::is_same<typename std::tuple_element<2, C>::type, Exp>::value), "");
|
||||
}
|
||||
{
|
||||
typedef T const volatile Exp;
|
||||
typedef std::array<T, 3> const volatile C;
|
||||
static_assert((std::is_same<typename std::tuple_element<0, C>::type, Exp>::value), "");
|
||||
static_assert((std::is_same<typename std::tuple_element<1, C>::type, Exp>::value), "");
|
||||
static_assert((std::is_same<typename std::tuple_element<2, C>::type, Exp>::value), "");
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<double>();
|
||||
test<int>();
|
||||
}
|
||||
|
@@ -13,16 +13,30 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
int main()
|
||||
template <class T, std::size_t N>
|
||||
void test()
|
||||
{
|
||||
{
|
||||
typedef double T;
|
||||
typedef std::array<T, 3> C;
|
||||
static_assert((std::tuple_size<C>::value == 3), "");
|
||||
typedef std::array<T, N> C;
|
||||
static_assert((std::tuple_size<C>::value == N), "");
|
||||
}
|
||||
{
|
||||
typedef double T;
|
||||
typedef std::array<T, 0> C;
|
||||
static_assert((std::tuple_size<C>::value == 0), "");
|
||||
typedef std::array<T const, N> C;
|
||||
static_assert((std::tuple_size<C>::value == N), "");
|
||||
}
|
||||
{
|
||||
typedef std::array<T volatile, N> C;
|
||||
static_assert((std::tuple_size<C>::value == N), "");
|
||||
}
|
||||
{
|
||||
typedef std::array<T const volatile, N> C;
|
||||
static_assert((std::tuple_size<C>::value == N), "");
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<double, 0>();
|
||||
test<double, 3>();
|
||||
test<double, 5>();
|
||||
}
|
||||
|
Reference in New Issue
Block a user