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// REQUIRES: std-at-least-c++17
10
11// <utility>
12
13// template<class T1, class T2>
14// pair(T1, T2) -> pair<T1, T2>;
15
16// Test that the explicit deduction guide for std::pair correctly decays function lvalues and
17// behaves different from std::make_pair.
18
19#include <cassert>
20#include <functional>
21#include <type_traits>
22#include <utility>
23
24#include "test_macros.h"
25
26void dummy() {}
27
28constexpr void test_decay() {
29 char arr[1]{};
30 std::pair pr(arr, dummy);
31
32 ASSERT_SAME_TYPE(decltype(pr), std::pair<char*, void (*)()>);
33
34 assert(pr == std::make_pair(arr, dummy));
35}
36
37TEST_CONSTEXPR_CXX20 void test_unwrap() {
38 int n = 0;
39 std::pair pr(std::ref(t&: n), dummy);
40
41 ASSERT_SAME_TYPE(decltype(pr), std::pair<std::reference_wrapper<int>, void (*)()>);
42 static_assert(!std::is_same_v<decltype(pr), decltype(std::make_pair(x: std::ref(t&: n), y&: dummy))>);
43
44 assert(&(pr.first.get()) == &n);
45 assert(pr.second == dummy);
46}
47
48constexpr bool test() {
49 test_decay();
50 if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED)
51 test_unwrap();
52 return true;
53}
54
55int main(int, char**) {
56 test();
57 static_assert(test());
58
59 return 0;
60}
61

source code of libcxx/test/std/utilities/utility/pairs/pairs.pair/explicit_deduction_guides.pass.cpp