Debian Codegraph @

libcxx/test/std/utilities/utility/pairs/pairs.pair/nttp.equivalence.compile.pass.cpp

raw
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 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: clang-17
11
12 // <utility>
13
14 // LWG-3382 NTTP for pair and array:
15 // Two values p1 and p2 of type pair<T, U> are template-argument-equivalent ([temp.type]) if and only if
16 // p1.first and p2.first are template-argument-equivalent and p1.second and p2.second are template-argument-equivalent.
17
18 #include <utility>
19
20 #include <type_traits>
21
22 int i = 0;
23 int j = 1;
24
25 namespace test_full_type {
26 template <class T, class U, std::pair<T, U> P>
27 struct test : std::false_type {};
28
29 template <>
30 struct test<int&, int, std::pair<int&, int>{i, 5}> : std::true_type {};
31
32 static_assert(!test<int*, int*, std::pair<int*, int*>{}>::value);
33 static_assert(!test<int*, int, std::pair<int*, int>{}>::value);
34 static_assert(!test<int&, int*, std::pair<int&, int*>{i, nullptr}>::value);
35 static_assert(!test<int&, int, std::pair<int&, int>{j, 0}>::value);
36 static_assert(!test<int&, int, std::pair<int&, int>{j, 5}>::value);
37 static_assert(!test<int&, int, std::pair<int&, int>{i, 0}>::value);
38 static_assert(!test<int&, unsigned int, std::pair<int&, unsigned int>{j, 0}>::value);
39 static_assert(test<int&, int, std::pair<int&, int>{i, 5}>::value);
40 } // namespace test_full_type
41
42 namespace test_ctad {
43 template <std::pair P>
44 struct test : std::false_type {};
45
46 template <>
47 struct test<std::pair<int&, int>{i, 10}> : std::true_type {};
48
49 static_assert(!test<std::pair<int*, int*>{}>::value);
50 static_assert(!test<std::pair<int*, int>{}>::value);
51 static_assert(!test<std::pair<int&, int*>{i, nullptr}>::value);
52 static_assert(!test<std::pair<int&, int>{j, 0}>::value);
53 static_assert(!test<std::pair<int&, int>{j, 10}>::value);
54 static_assert(!test<std::pair<int&, int>{i, 0}>::value);
55 static_assert(!test<std::pair<int&, unsigned int>{j, 0}>::value);
56 static_assert(test<std::pair<int&, int>{i, 10}>::value);
57 } // namespace test_ctad
58
59 namespace test_auto {
60 template <auto P>
61 struct test : std::false_type {};
62
63 template <>
64 struct test<std::pair<int&, int>{i, 15}> : std::true_type {};
65
66 static_assert(!test<std::pair<int*, int*>{}>::value);
67 static_assert(!test<std::pair<int*, int>{}>::value);
68 static_assert(!test<std::pair<int&, int*>{i, nullptr}>::value);
69 static_assert(!test<std::pair<int&, int>{j, 0}>::value);
70 static_assert(!test<std::pair<int&, int>{j, 15}>::value);
71 static_assert(!test<std::pair<int&, int>{i, 0}>::value);
72 static_assert(!test<std::pair<int&, unsigned int>{j, 0}>::value);
73 static_assert(test<std::pair<int&, int>{i, 15}>::value);
74 } // namespace test_auto