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
24int i = 0;
25int j = 1;
26
27namespace test_full_type {
28template <class T, class U, std::pair<T, U> P>
29struct test : std::false_type {};
30
31template <>
32struct test<int&, int, std::pair<int&, int>{i, 5}> : std::true_type {};
33
34static_assert(!test<int*, int*, std::pair<int*, int*>{}>::value);
35static_assert(!test<int*, int, std::pair<int*, int>{}>::value);
36static_assert(!test<int&, int*, std::pair<int&, int*>{i, nullptr}>::value);
37static_assert(!test<int&, int, std::pair<int&, int>{j, 0}>::value);
38static_assert(!test<int&, int, std::pair<int&, int>{j, 5}>::value);
39static_assert(!test<int&, int, std::pair<int&, int>{i, 0}>::value);
40static_assert(!test<int&, unsigned int, std::pair<int&, unsigned int>{j, 0}>::value);
41static_assert(test<int&, int, std::pair<int&, int>{i, 5}>::value);
42} // namespace test_full_type
43
44namespace test_ctad {
45template <std::pair P>
46struct test : std::false_type {};
47
48template <>
49struct test<std::pair<int&, int>{i, 10}> : std::true_type {};
50
51static_assert(!test<std::pair<int*, int*>{}>::value);
52static_assert(!test<std::pair<int*, int>{}>::value);
53static_assert(!test<std::pair<int&, int*>{i, nullptr}>::value);
54static_assert(!test<std::pair<int&, int>{j, 0}>::value);
55static_assert(!test<std::pair<int&, int>{j, 10}>::value);
56static_assert(!test<std::pair<int&, int>{i, 0}>::value);
57static_assert(!test<std::pair<int&, unsigned int>{j, 0}>::value);
58static_assert(test<std::pair<int&, int>{i, 10}>::value);
59} // namespace test_ctad
60
61namespace test_auto {
62template <auto P>
63struct test : std::false_type {};
64
65template <>
66struct test<std::pair<int&, int>{i, 15}> : std::true_type {};
67
68static_assert(!test<std::pair<int*, int*>{}>::value);
69static_assert(!test<std::pair<int*, int>{}>::value);
70static_assert(!test<std::pair<int&, int*>{i, nullptr}>::value);
71static_assert(!test<std::pair<int&, int>{j, 0}>::value);
72static_assert(!test<std::pair<int&, int>{j, 15}>::value);
73static_assert(!test<std::pair<int&, int>{i, 0}>::value);
74static_assert(!test<std::pair<int&, unsigned int>{j, 0}>::value);
75static_assert(test<std::pair<int&, int>{i, 15}>::value);
76} // namespace test_auto
77

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