
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
56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <utility>
|
|
|
|
// template <class T1, class T2> struct pair
|
|
|
|
// tuple_element<I, pair<T1, T2> >::type
|
|
|
|
#include <utility>
|
|
|
|
template <class T1, class T2>
|
|
void test()
|
|
{
|
|
{
|
|
typedef T1 Exp1;
|
|
typedef T2 Exp2;
|
|
typedef std::pair<T1, T2> P;
|
|
static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), "");
|
|
static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), "");
|
|
}
|
|
{
|
|
typedef T1 const Exp1;
|
|
typedef T2 const Exp2;
|
|
typedef std::pair<T1, T2> const P;
|
|
static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), "");
|
|
static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), "");
|
|
}
|
|
{
|
|
typedef T1 volatile Exp1;
|
|
typedef T2 volatile Exp2;
|
|
typedef std::pair<T1, T2> volatile P;
|
|
static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), "");
|
|
static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), "");
|
|
}
|
|
{
|
|
typedef T1 const volatile Exp1;
|
|
typedef T2 const volatile Exp2;
|
|
typedef std::pair<T1, T2> const volatile P;
|
|
static_assert((std::is_same<typename std::tuple_element<0, P>::type, Exp1>::value), "");
|
|
static_assert((std::is_same<typename std::tuple_element<1, P>::type, Exp2>::value), "");
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
test<int, short>();
|
|
test<int*, char>();
|
|
}
|