brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · f19ea23 Raw
98 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++1410// <optional>11 12// template <class T, class U> constexpr bool operator> (const optional<T>& x, const optional<U>& y);13 14#include <optional>15 16#include "test_comparisons.h"17#include "test_macros.h"18 19#if TEST_STD_VER >= 2620 21// Test SFINAE.22static_assert(HasOperatorGreaterThan<std::optional<ThreeWayComparable>>);23static_assert(HasOperatorGreaterThan<std::optional<ThreeWayComparable>, std::optional<int>>);24 25static_assert(!HasOperatorGreaterThan<std::optional<NonComparable>>);26static_assert(!HasOperatorGreaterThan<std::optional<EqualityComparable>>);27static_assert(!HasOperatorGreaterThan<std::optional<ThreeWayComparable>, std::optional<NonComparable>>);28 29#endif30 31using std::optional;32 33struct X {34  int i_;35 36  constexpr X(int i) : i_(i) {}37};38 39constexpr bool operator>(const X& lhs, const X& rhs) { return lhs.i_ > rhs.i_; }40 41int main(int, char**) {42  {43    typedef optional<X> O;44 45    constexpr O o1;    // disengaged46    constexpr O o2;    // disengaged47    constexpr O o3{1}; // engaged48    constexpr O o4{2}; // engaged49    constexpr O o5{1}; // engaged50 51    static_assert(!(o1 > o1), "");52    static_assert(!(o1 > o2), "");53    static_assert(!(o1 > o3), "");54    static_assert(!(o1 > o4), "");55    static_assert(!(o1 > o5), "");56 57    static_assert(!(o2 > o1), "");58    static_assert(!(o2 > o2), "");59    static_assert(!(o2 > o3), "");60    static_assert(!(o2 > o4), "");61    static_assert(!(o2 > o5), "");62 63    static_assert((o3 > o1), "");64    static_assert((o3 > o2), "");65    static_assert(!(o3 > o3), "");66    static_assert(!(o3 > o4), "");67    static_assert(!(o3 > o5), "");68 69    static_assert((o4 > o1), "");70    static_assert((o4 > o2), "");71    static_assert((o4 > o3), "");72    static_assert(!(o4 > o4), "");73    static_assert((o4 > o5), "");74 75    static_assert((o5 > o1), "");76    static_assert((o5 > o2), "");77    static_assert(!(o5 > o3), "");78    static_assert(!(o5 > o4), "");79    static_assert(!(o5 > o5), "");80  }81  {82    using O1 = optional<int>;83    using O2 = optional<long>;84    constexpr O1 o1(42);85    static_assert(o1 > O2(1), "");86    static_assert(!(O2(42) > o1), "");87  }88  {89    using O1 = optional<int>;90    using O2 = optional<const int>;91    constexpr O1 o1(42);92    static_assert(o1 > O2(1), "");93    static_assert(!(O2(42) > o1), "");94  }95 96  return 0;97}98