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) {
27dc808af3SEric Fiselier return lhs.i_ >= rhs.i_;
28dc808af3SEric Fiselier }
29a9e65961SEric Fiselier
main(int,char **)302df59c50SJF Bastien int main(int, char**) {
31a9e65961SEric Fiselier {
32a9e65961SEric Fiselier typedef optional<X> O;
33a9e65961SEric Fiselier
34a9e65961SEric Fiselier constexpr O o1; // disengaged
35a9e65961SEric Fiselier constexpr O o2; // disengaged
36a9e65961SEric Fiselier constexpr O o3{1}; // engaged
37a9e65961SEric Fiselier constexpr O o4{2}; // engaged
38a9e65961SEric Fiselier constexpr O o5{1}; // engaged
39a9e65961SEric Fiselier
40a9e65961SEric Fiselier static_assert((o1 >= o1), "");
41a9e65961SEric Fiselier static_assert((o1 >= o2), "");
42a9e65961SEric Fiselier static_assert(!(o1 >= o3), "");
43a9e65961SEric Fiselier static_assert(!(o1 >= o4), "");
44a9e65961SEric Fiselier static_assert(!(o1 >= o5), "");
45a9e65961SEric Fiselier
46a9e65961SEric Fiselier static_assert((o2 >= o1), "");
47a9e65961SEric Fiselier static_assert((o2 >= o2), "");
48a9e65961SEric Fiselier static_assert(!(o2 >= o3), "");
49a9e65961SEric Fiselier static_assert(!(o2 >= o4), "");
50a9e65961SEric Fiselier static_assert(!(o2 >= o5), "");
51a9e65961SEric Fiselier
52a9e65961SEric Fiselier static_assert((o3 >= o1), "");
53a9e65961SEric Fiselier static_assert((o3 >= o2), "");
54a9e65961SEric Fiselier static_assert((o3 >= o3), "");
55a9e65961SEric Fiselier static_assert(!(o3 >= o4), "");
56a9e65961SEric Fiselier static_assert((o3 >= o5), "");
57a9e65961SEric Fiselier
58a9e65961SEric Fiselier static_assert((o4 >= o1), "");
59a9e65961SEric Fiselier static_assert((o4 >= o2), "");
60a9e65961SEric Fiselier static_assert((o4 >= o3), "");
61a9e65961SEric Fiselier static_assert((o4 >= o4), "");
62a9e65961SEric Fiselier static_assert((o4 >= o5), "");
63a9e65961SEric Fiselier
64a9e65961SEric Fiselier static_assert((o5 >= o1), "");
65a9e65961SEric Fiselier static_assert((o5 >= o2), "");
66a9e65961SEric Fiselier static_assert((o5 >= o3), "");
67a9e65961SEric Fiselier static_assert(!(o5 >= o4), "");
68a9e65961SEric Fiselier static_assert((o5 >= o5), "");
69a9e65961SEric Fiselier }
70dc808af3SEric Fiselier {
71dc808af3SEric Fiselier using O1 = optional<int>;
72dc808af3SEric Fiselier using O2 = optional<long>;
73dc808af3SEric Fiselier constexpr O1 o1(42);
74dc808af3SEric Fiselier static_assert(o1 >= O2(42), "");
75dc808af3SEric Fiselier static_assert(!(O2(11) >= o1), "");
76dc808af3SEric Fiselier }
77dc808af3SEric Fiselier {
78dc808af3SEric Fiselier using O1 = optional<int>;
79dc808af3SEric Fiselier using O2 = optional<const int>;
80dc808af3SEric Fiselier constexpr O1 o1(42);
81dc808af3SEric Fiselier static_assert(o1 >= O2(42), "");
82dc808af3SEric Fiselier static_assert(!(O2(1) >= o1), "");
83dc808af3SEric Fiselier }
842df59c50SJF Bastien
852df59c50SJF Bastien return 0;
86a9e65961SEric Fiselier }
87