brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 70e79d3 Raw
62 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++2610 11// <functional>12 13// class reference_wrapper14 15// [refwrap.comparisons], comparisons16// friend constexpr bool operator==(reference_wrapper, reference_wrapper);                                // Since C++2617 18#include <cassert>19#include <concepts>20#include <functional>21 22#include "test_comparisons.h"23#include "test_macros.h"24 25// Test SFINAE.26 27static_assert(HasOperatorEqual<std::reference_wrapper<EqualityComparable>>);28 29static_assert(!HasOperatorEqual<std::reference_wrapper<NonComparable>>);30 31// Test equality.32 33template <typename T>34constexpr void test() {35  T i{92};36  T j{84};37 38  std::reference_wrapper<T> rw1{i};39  std::reference_wrapper<T> rw2 = rw1;40  std::reference_wrapper<T> rw3{j};41  std::reference_wrapper<const T> crw1{i};42  std::reference_wrapper<const T> crw3{j};43 44  AssertEqualityReturnBool<decltype(rw1), decltype(rw2)>();45  assert(testEquality(rw1, rw2, true));46  assert(testEquality(rw1, rw3, false));47}48 49constexpr bool test() {50  test<int>();51  test<EqualityComparable>();52 53  return true;54}55 56int main(int, char**) {57  test();58  static_assert(test());59 60  return 0;61}62