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