brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 153cbbd 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 E2> friend constexpr bool operator==(const expected& x, const unexpected<E2>& e);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<EqualityComparable, EqualityComparable>, std::unexpected<int>>);25static_assert(HasOperatorEqual<std::expected<EqualityComparable, int>, std::unexpected<EqualityComparable>>);26static_assert(!HasOperatorEqual<std::expected<EqualityComparable, NonComparable>, std::unexpected<int>>);27#endif28 29constexpr bool test() {30  // x.has_value()31  {32    const std::expected<EqualityComparable, EqualityComparable> e1(std::in_place, 5);33    std::unexpected<int> un2(10);34    std::unexpected<int> un3(5);35    assert(e1 != un2);36    assert(e1 != un3);37  }38 39  // !x.has_value()40  {41    const std::expected<EqualityComparable, EqualityComparable> e1(std::unexpect, 5);42    std::unexpected<int> un2(10);43    std::unexpected<int> un3(5);44    assert(e1 != un2);45    assert(e1 == un3);46  }47 48  return true;49}50 51int main(int, char**) {52  test();53  static_assert(test());54  return 0;55}56