xref: /llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.pass.cpp (revision 5dfdac74cadd9483a66eb17e51dc632b554cccb1)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <tuple>
10 
11 // template <class... Types> class tuple;
12 
13 // template <class... Types>
14 //   struct tuple_size<tuple<Types...>>
15 //     : public integral_constant<size_t, sizeof...(Types)> { };
16 
17 // UNSUPPORTED: c++03
18 
19 #include <array>
20 #include <tuple>
21 #include <type_traits>
22 #include <utility>
23 
24 #include "test_macros.h"
25 
26 template <class T, std::size_t Size = sizeof(std::tuple_size<T>)>
27 constexpr bool is_complete(int) { static_assert(Size > 0, ""); return true; }
28 template <class> constexpr bool is_complete(long) { return false; }
29 template <class T> constexpr bool is_complete() { return is_complete<T>(0); }
30 
31 struct Dummy1 {};
32 struct Dummy2 {};
33 
34 template <>
35 struct std::tuple_size<Dummy1> : public integral_constant<std::size_t, 0> {};
36 
37 template <class T>
38 void test_complete() {
39   static_assert(is_complete<T>(), "");
40   static_assert(is_complete<const T>(), "");
41   static_assert(is_complete<volatile T>(), "");
42   static_assert(is_complete<const volatile T>(), "");
43 }
44 
45 template <class T>
46 void test_incomplete() {
47   static_assert(!is_complete<T>(), "");
48   static_assert(!is_complete<const T>(), "");
49   static_assert(!is_complete<volatile T>(), "");
50   static_assert(!is_complete<const volatile T>(), "");
51 }
52 
53 
54 int main(int, char**)
55 {
56   test_complete<std::tuple<> >();
57   test_complete<std::tuple<int&> >();
58   test_complete<std::tuple<int&&, int&, void*>>();
59   test_complete<std::pair<int, long> >();
60   test_complete<std::array<int, 5> >();
61   test_complete<Dummy1>();
62 
63   test_incomplete<void>();
64   test_incomplete<int>();
65   test_incomplete<std::tuple<int>&>();
66   test_incomplete<Dummy2>();
67 
68   return 0;
69 }
70