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// type_traits
10
11// extent
12
13#include <type_traits>
14
15#include "test_macros.h"
16
17template <class T, unsigned A>
18void test_extent()
19{
20 static_assert((std::extent<T>::value == A), "");
21 static_assert((std::extent<const T>::value == A), "");
22 static_assert((std::extent<volatile T>::value == A), "");
23 static_assert((std::extent<const volatile T>::value == A), "");
24#if TEST_STD_VER > 14
25 static_assert((std::extent_v<T> == A), "");
26 static_assert((std::extent_v<const T> == A), "");
27 static_assert((std::extent_v<volatile T> == A), "");
28 static_assert((std::extent_v<const volatile T> == A), "");
29#endif
30}
31
32template <class T, unsigned A>
33void test_extent1()
34{
35 static_assert((std::extent<T, 1>::value == A), "");
36 static_assert((std::extent<const T, 1>::value == A), "");
37 static_assert((std::extent<volatile T, 1>::value == A), "");
38 static_assert((std::extent<const volatile T, 1>::value == A), "");
39#if TEST_STD_VER > 14
40 static_assert((std::extent_v<T, 1> == A), "");
41 static_assert((std::extent_v<const T, 1> == A), "");
42 static_assert((std::extent_v<volatile T, 1> == A), "");
43 static_assert((std::extent_v<const volatile T, 1> == A), "");
44#endif
45}
46
47class Class
48{
49public:
50 ~Class();
51};
52
53int main(int, char**)
54{
55 test_extent<void, 0>();
56 test_extent<int&, 0>();
57 test_extent<Class, 0>();
58 test_extent<int*, 0>();
59 test_extent<const int*, 0>();
60 test_extent<int, 0>();
61 test_extent<double, 0>();
62 test_extent<bool, 0>();
63 test_extent<unsigned, 0>();
64
65 test_extent<int[2], 2>();
66 test_extent<int[2][4], 2>();
67 test_extent<int[][4], 0>();
68
69 test_extent1<int, 0>();
70 test_extent1<int[2], 0>();
71 test_extent1<int[2][4], 4>();
72 test_extent1<int[][4], 4>();
73
74 return 0;
75}
76

source code of libcxx/test/std/utilities/meta/meta.unary.prop.query/extent.pass.cpp