brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 16c6986 Raw
56 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 T2> friend constexpr bool operator==(const expected& x, const T2& v);12 13#include <cassert>14#include <concepts>15#include <expected>16#include <type_traits>17#include <utility>18 19#include "test_comparisons.h"20#include "test_macros.h"21 22#if TEST_STD_VER >= 2623// https://wg21.link/P3379R024static_assert(HasOperatorEqual<std::expected<int, int>, int>);25static_assert(HasOperatorEqual<std::expected<int, int>, EqualityComparable>);26static_assert(!HasOperatorEqual<std::expected<int, int>, NonComparable>);27#endif28 29constexpr bool test() {30  // x.has_value()31  {32    const std::expected<EqualityComparable, int> e1(std::in_place, 5);33    int i2 = 10;34    int i3 = 5;35    assert(e1 != i2);36    assert(e1 == i3);37  }38 39  // !x.has_value()40  {41    const std::expected<EqualityComparable, int> e1(std::unexpect, 5);42    int i2 = 10;43    int i3 = 5;44    assert(e1 != i2);45    assert(e1 != i3);46  }47 48  return true;49}50 51int main(int, char**) {52  test();53  static_assert(test());54  return 0;55}56