brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 4824151 Raw
54 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// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 11// template<class E2>12// friend constexpr bool operator==(const unexpected& x, const unexpected<E2>& y);13//14// Mandates: The expression x.error() == y.error() is well-formed and its result is convertible to bool.15//16// Returns: x.error() == y.error().17 18#include <cassert>19#include <concepts>20#include <expected>21#include <utility>22 23struct Error {24  int i;25  friend constexpr bool operator==(const Error&, const Error&) = default;26  friend constexpr bool operator==(const Error& lhs, int rhs) noexcept { return lhs.i == rhs; }27};28 29constexpr bool test() {30  std::unexpected<Error> unex1(Error{2});31  std::unexpected<Error> unex2(Error{3});32  std::unexpected<Error> unex3(Error{2});33 34  assert(unex1 == unex3);35  assert(unex1 != unex2);36  assert(unex2 != unex3);37 38  std::unexpected<int> unex_i1(1);39  std::unexpected<int> unex_i2(2);40 41  assert(unex1 != unex_i1);42  assert(unex_i1 != unex1);43  assert(unex1 == unex_i2);44  assert(unex_i2 == unex1);45 46  return true;47}48 49int main(int, char**) {50  test();51  static_assert(test());52  return 0;53}54