Home | History | Annotate | Download | only in tuple.helper
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <tuple>
     11 
     12 // template <class... Types> class tuple;
     13 
     14 // template <size_t I, class... Types>
     15 // class tuple_element<I, tuple<Types...> >
     16 // {
     17 // public:
     18 //     typedef Ti type;
     19 // };
     20 //
     21 //  LWG #2212 says that tuple_size and tuple_element must be
     22 //     available after including <utility>
     23 
     24 #include <array>
     25 #include <type_traits>
     26 
     27 template <class T, std::size_t N, class U, size_t idx>
     28 void test()
     29 {
     30     static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
     31                                    std::tuple_size<T> >::value), "");
     32     static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
     33                                    std::tuple_size<const T> >::value), "");
     34     static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
     35                                    std::tuple_size<volatile T> >::value), "");
     36     static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
     37                                    std::tuple_size<const volatile T> >::value), "");
     38     static_assert((std::is_same<typename std::tuple_element<idx, T>::type, U>::value), "");
     39     static_assert((std::is_same<typename std::tuple_element<idx, const T>::type, const U>::value), "");
     40     static_assert((std::is_same<typename std::tuple_element<idx, volatile T>::type, volatile U>::value), "");
     41     static_assert((std::is_same<typename std::tuple_element<idx, const volatile T>::type, const volatile U>::value), "");
     42 }
     43 
     44 int main()
     45 {
     46     test<std::array<int, 5>, 5, int, 0>();
     47     test<std::array<int, 5>, 5, int, 1>();
     48     test<std::array<const char *, 4>, 4, const char *, 3>();
     49     test<std::array<volatile int, 4>, 4, volatile int, 3>();
     50     test<std::array<char *, 3>, 3, char *, 1>();
     51     test<std::array<char *, 3>, 3, char *, 2>();
     52 }
     53