tuple_size_v.pass.cpp (1312B)
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 // UNSUPPORTED: c++98, c++03, c++11, c++14 11 12 // <tuple> 13 14 // template <class T> constexpr size_t tuple_size_v = tuple_size<T>::value; 15 16 #include <tuple> 17 #include <utility> 18 #include <array> 19 20 template <class Tuple, int Expect> 21 void test() 22 { 23 static_assert(std::tuple_size_v<Tuple> == Expect, ""); 24 static_assert(std::tuple_size_v<Tuple> == std::tuple_size<Tuple>::value, ""); 25 static_assert(std::tuple_size_v<Tuple const> == std::tuple_size<Tuple>::value, ""); 26 static_assert(std::tuple_size_v<Tuple volatile> == std::tuple_size<Tuple>::value, ""); 27 static_assert(std::tuple_size_v<Tuple const volatile> == std::tuple_size<Tuple>::value, ""); 28 } 29 30 int main() 31 { 32 test<std::tuple<>, 0>(); 33 34 test<std::tuple<int>, 1>(); 35 test<std::array<int, 1>, 1>(); 36 37 test<std::tuple<int, int>, 2>(); 38 test<std::pair<int, int>, 2>(); 39 test<std::array<int, 2>, 2>(); 40 41 test<std::tuple<int, int, int>, 3>(); 42 test<std::array<int, 3>, 3>(); 43 }