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 <class... Types> 15 // class tuple_size<tuple<Types...>> 16 // : public integral_constant<size_t, sizeof...(Types)> { }; 17 // 18 // LWG #2212 says that tuple_size and tuple_element must be 19 // available after including <utility> 20 21 #include <cstddef> 22 #include <utility> 23 #include <type_traits> 24 25 template <class T, std::size_t N, class U, size_t idx> 26 void test() 27 { 28 static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, 29 std::tuple_size<T> >::value), ""); 30 static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, 31 std::tuple_size<const T> >::value), ""); 32 static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, 33 std::tuple_size<volatile T> >::value), ""); 34 static_assert((std::is_base_of<std::integral_constant<std::size_t, N>, 35 std::tuple_size<const volatile T> >::value), ""); 36 static_assert((std::is_same<typename std::tuple_element<idx, T>::type, U>::value), ""); 37 static_assert((std::is_same<typename std::tuple_element<idx, const T>::type, const U>::value), ""); 38 static_assert((std::is_same<typename std::tuple_element<idx, volatile T>::type, volatile U>::value), ""); 39 static_assert((std::is_same<typename std::tuple_element<idx, const volatile T>::type, const volatile U>::value), ""); 40 } 41 42 int main() 43 { 44 test<std::pair<int, int>, 2, int, 0>(); 45 test<std::pair<int, int>, 2, int, 1>(); 46 test<std::pair<const int, int>, 2, int, 1>(); 47 test<std::pair<int, volatile int>, 2, volatile int, 1>(); 48 test<std::pair<char *, int>, 2, char *, 0>(); 49 test<std::pair<char *, int>, 2, int, 1>(); 50 } 51