xref: /llvm-project/libcxx/test/std/utilities/optional/optional.comp_with_t/greater.pass.cpp (revision 31cbe0f240f660f15602c96b787c58a26f17e179)
1a9e65961SEric Fiselier //===----------------------------------------------------------------------===//
2a9e65961SEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a9e65961SEric Fiselier //
7a9e65961SEric Fiselier //===----------------------------------------------------------------------===//
8a9e65961SEric Fiselier 
9*31cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
10a9e65961SEric Fiselier // <optional>
11a9e65961SEric Fiselier 
12e3bdfe63SCasey Carter // template <class T, class U> constexpr bool operator>(const optional<T>& x, const U& v);
13e3bdfe63SCasey Carter // template <class T, class U> constexpr bool operator>(const U& v, const optional<T>& x);
14a9e65961SEric Fiselier 
15a9e65961SEric Fiselier #include <optional>
16a9e65961SEric Fiselier 
177fc6a556SMarshall Clow #include "test_macros.h"
187fc6a556SMarshall Clow 
19a9e65961SEric Fiselier using std::optional;
20a9e65961SEric Fiselier 
21dc808af3SEric Fiselier struct X {
22a9e65961SEric Fiselier   int i_;
23a9e65961SEric Fiselier 
XX24a9e65961SEric Fiselier   constexpr X(int i) : i_(i) {}
25a9e65961SEric Fiselier };
26a9e65961SEric Fiselier 
operator >(const X & lhs,const X & rhs)27dc808af3SEric Fiselier constexpr bool operator>(const X& lhs, const X& rhs) { return lhs.i_ > rhs.i_; }
28a9e65961SEric Fiselier 
main(int,char **)292df59c50SJF Bastien int main(int, char**) {
30a9e65961SEric Fiselier   {
31a9e65961SEric Fiselier     typedef X T;
32a9e65961SEric Fiselier     typedef optional<T> O;
33a9e65961SEric Fiselier 
34a9e65961SEric Fiselier     constexpr T val(2);
35a9e65961SEric Fiselier     constexpr O o1;      // disengaged
36a9e65961SEric Fiselier     constexpr O o2{1};   // engaged
37a9e65961SEric Fiselier     constexpr O o3{val}; // engaged
38a9e65961SEric Fiselier 
39a9e65961SEric Fiselier     static_assert(!(o1 > T(1)), "");
40a9e65961SEric Fiselier     static_assert(!(o2 > T(1)), ""); // equal
41a9e65961SEric Fiselier     static_assert((o3 > T(1)), "");
42a9e65961SEric Fiselier     static_assert(!(o2 > val), "");
43a9e65961SEric Fiselier     static_assert(!(o3 > val), ""); // equal
44a9e65961SEric Fiselier     static_assert(!(o3 > T(3)), "");
45a9e65961SEric Fiselier 
46a9e65961SEric Fiselier     static_assert((T(1) > o1), "");
47a9e65961SEric Fiselier     static_assert(!(T(1) > o2), ""); // equal
48a9e65961SEric Fiselier     static_assert(!(T(1) > o3), "");
49a9e65961SEric Fiselier     static_assert((val > o2), "");
50a9e65961SEric Fiselier     static_assert(!(val > o3), ""); // equal
51a9e65961SEric Fiselier     static_assert((T(3) > o3), "");
52a9e65961SEric Fiselier   }
53dc808af3SEric Fiselier   {
54dc808af3SEric Fiselier     using O = optional<int>;
55dc808af3SEric Fiselier     constexpr O o1(42);
56dc808af3SEric Fiselier     static_assert(o1 > 11l, "");
57dc808af3SEric Fiselier     static_assert(!(42l > o1), "");
58dc808af3SEric Fiselier   }
59dc808af3SEric Fiselier   {
60dc808af3SEric Fiselier     using O = optional<const int>;
61dc808af3SEric Fiselier     constexpr O o1(42);
62dc808af3SEric Fiselier     static_assert(o1 > 11, "");
63dc808af3SEric Fiselier     static_assert(!(42 > o1), "");
64dc808af3SEric Fiselier   }
652df59c50SJF Bastien 
662df59c50SJF Bastien   return 0;
67a9e65961SEric Fiselier }
68