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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14
10// <optional>
11
12// template <class T, class U> constexpr bool operator<=(const optional<T>& x, const U& v);
13// template <class T, class U> constexpr bool operator<=(const U& v, const optional<T>& x);
14
15#include <optional>
16
17#include "test_macros.h"
18
19using std::optional;
20
21struct X {
22 int i_;
23
24 constexpr X(int i) : i_(i) {}
25};
26
27constexpr bool operator<=(const X& lhs, const X& rhs) {
28 return lhs.i_ <= rhs.i_;
29}
30
31int main(int, char**) {
32 {
33 typedef X T;
34 typedef optional<T> O;
35
36 constexpr T val(2);
37 constexpr O o1; // disengaged
38 constexpr O o2{1}; // engaged
39 constexpr O o3{val}; // engaged
40
41 static_assert((o1 <= T(1)), "");
42 static_assert((o2 <= T(1)), ""); // equal
43 static_assert(!(o3 <= T(1)), "");
44 static_assert((o2 <= val), "");
45 static_assert((o3 <= val), ""); // equal
46 static_assert((o3 <= T(3)), "");
47
48 static_assert(!(T(1) <= o1), "");
49 static_assert((T(1) <= o2), ""); // equal
50 static_assert((T(1) <= o3), "");
51 static_assert(!(val <= o2), "");
52 static_assert((val <= o3), ""); // equal
53 static_assert(!(T(3) <= o3), "");
54 }
55 {
56 using O = optional<int>;
57 constexpr O o1(42);
58 static_assert(o1 <= 42l, "");
59 static_assert(!(101l <= o1), "");
60 }
61 {
62 using O = optional<const int>;
63 constexpr O o1(42);
64 static_assert(o1 <= 42, "");
65 static_assert(!(101 <= o1), "");
66 }
67
68 return 0;
69}
70

source code of libcxx/test/std/utilities/optional/optional.comp_with_t/less_equal.pass.cpp