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 optional<U>& y);
13a9e65961SEric Fiselier
14a9e65961SEric Fiselier #include <optional>
15a9e65961SEric Fiselier
167fc6a556SMarshall Clow #include "test_macros.h"
177fc6a556SMarshall Clow
18a9e65961SEric Fiselier using std::optional;
19a9e65961SEric Fiselier
20dc808af3SEric Fiselier struct X {
21a9e65961SEric Fiselier int i_;
22a9e65961SEric Fiselier
XX23a9e65961SEric Fiselier constexpr X(int i) : i_(i) {}
24a9e65961SEric Fiselier };
25a9e65961SEric Fiselier
operator >(const X & lhs,const X & rhs)26dc808af3SEric Fiselier constexpr bool operator>(const X& lhs, const X& rhs) { return lhs.i_ > rhs.i_; }
27a9e65961SEric Fiselier
main(int,char **)282df59c50SJF Bastien int main(int, char**) {
29a9e65961SEric Fiselier {
30a9e65961SEric Fiselier typedef optional<X> O;
31a9e65961SEric Fiselier
32a9e65961SEric Fiselier constexpr O o1; // disengaged
33a9e65961SEric Fiselier constexpr O o2; // disengaged
34a9e65961SEric Fiselier constexpr O o3{1}; // engaged
35a9e65961SEric Fiselier constexpr O o4{2}; // engaged
36a9e65961SEric Fiselier constexpr O o5{1}; // engaged
37a9e65961SEric Fiselier
38a9e65961SEric Fiselier static_assert(!(o1 > o1), "");
39a9e65961SEric Fiselier static_assert(!(o1 > o2), "");
40a9e65961SEric Fiselier static_assert(!(o1 > o3), "");
41a9e65961SEric Fiselier static_assert(!(o1 > o4), "");
42a9e65961SEric Fiselier static_assert(!(o1 > o5), "");
43a9e65961SEric Fiselier
44a9e65961SEric Fiselier static_assert(!(o2 > o1), "");
45a9e65961SEric Fiselier static_assert(!(o2 > o2), "");
46a9e65961SEric Fiselier static_assert(!(o2 > o3), "");
47a9e65961SEric Fiselier static_assert(!(o2 > o4), "");
48a9e65961SEric Fiselier static_assert(!(o2 > o5), "");
49a9e65961SEric Fiselier
50a9e65961SEric Fiselier static_assert((o3 > o1), "");
51a9e65961SEric Fiselier static_assert((o3 > o2), "");
52a9e65961SEric Fiselier static_assert(!(o3 > o3), "");
53a9e65961SEric Fiselier static_assert(!(o3 > o4), "");
54a9e65961SEric Fiselier static_assert(!(o3 > o5), "");
55a9e65961SEric Fiselier
56a9e65961SEric Fiselier static_assert((o4 > o1), "");
57a9e65961SEric Fiselier static_assert((o4 > o2), "");
58a9e65961SEric Fiselier static_assert((o4 > o3), "");
59a9e65961SEric Fiselier static_assert(!(o4 > o4), "");
60a9e65961SEric Fiselier static_assert((o4 > o5), "");
61a9e65961SEric Fiselier
62a9e65961SEric Fiselier static_assert((o5 > o1), "");
63a9e65961SEric Fiselier static_assert((o5 > o2), "");
64a9e65961SEric Fiselier static_assert(!(o5 > o3), "");
65a9e65961SEric Fiselier static_assert(!(o5 > o4), "");
66a9e65961SEric Fiselier static_assert(!(o5 > o5), "");
67a9e65961SEric Fiselier }
68dc808af3SEric Fiselier {
69dc808af3SEric Fiselier using O1 = optional<int>;
70dc808af3SEric Fiselier using O2 = optional<long>;
71dc808af3SEric Fiselier constexpr O1 o1(42);
72dc808af3SEric Fiselier static_assert(o1 > O2(1), "");
73dc808af3SEric Fiselier static_assert(!(O2(42) > o1), "");
74dc808af3SEric Fiselier }
75dc808af3SEric Fiselier {
76dc808af3SEric Fiselier using O1 = optional<int>;
77dc808af3SEric Fiselier using O2 = optional<const int>;
78dc808af3SEric Fiselier constexpr O1 o1(42);
79dc808af3SEric Fiselier static_assert(o1 > O2(1), "");
80dc808af3SEric Fiselier static_assert(!(O2(42) > o1), "");
81dc808af3SEric Fiselier }
822df59c50SJF Bastien
832df59c50SJF Bastien return 0;
84a9e65961SEric Fiselier }
85