brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · d580e04 Raw
61 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// REQUIRES: std-at-least-c++1710 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 and17// 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(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(std::ref(n), 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