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
26template <class T, std::size_t Size = sizeof(std::tuple_size<T>)>
27constexpr bool is_complete(int) { static_assert(Size > 0, ""); return true; }
28template <class> constexpr bool is_complete(long) { return false; }
29template <class T> constexpr bool is_complete() { return is_complete<T>(0); }
30
31struct Dummy1 {};
32struct Dummy2 {};
33
34template <>
35struct std::tuple_size<Dummy1> : public integral_constant<std::size_t, 0> {};
36
37template <class T>
38void 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
45template <class T>
46void test_incomplete() {
47 static_assert(!is_complete<T>(), "");
48 // https://cplusplus.github.io/LWG/issue4040
49 // It is controversial whether these specializations are incomplete.
50 LIBCPP_STATIC_ASSERT(!is_complete<const T>(), "");
51 LIBCPP_STATIC_ASSERT(!is_complete<volatile T>(), "");
52 LIBCPP_STATIC_ASSERT(!is_complete<const volatile T>(), "");
53}
54
55
56int main(int, char**)
57{
58 test_complete<std::tuple<> >();
59 test_complete<std::tuple<int&> >();
60 test_complete<std::tuple<int&&, int&, void*>>();
61 test_complete<std::pair<int, long> >();
62 test_complete<std::array<int, 5> >();
63 test_complete<Dummy1>();
64
65 test_incomplete<void>();
66 test_incomplete<int>();
67 test_incomplete<std::tuple<int>&>();
68 test_incomplete<Dummy2>();
69
70 return 0;
71}
72

source code of libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_incomplete.pass.cpp