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) {
28dc808af3SEric Fiselier return lhs.i_ == rhs.i_;
29dc808af3SEric Fiselier }
30a9e65961SEric Fiselier
main(int,char **)312df59c50SJF Bastien int main(int, char**) {
32a9e65961SEric Fiselier {
33a9e65961SEric Fiselier typedef X T;
34a9e65961SEric Fiselier typedef optional<T> O;
35a9e65961SEric Fiselier
36a9e65961SEric Fiselier constexpr T val(2);
37a9e65961SEric Fiselier constexpr O o1; // disengaged
38a9e65961SEric Fiselier constexpr O o2{1}; // engaged
39a9e65961SEric Fiselier constexpr O o3{val}; // engaged
40a9e65961SEric Fiselier
41a9e65961SEric Fiselier static_assert(!(o1 == T(1)), "");
42a9e65961SEric Fiselier static_assert((o2 == T(1)), "");
43a9e65961SEric Fiselier static_assert(!(o3 == T(1)), "");
44a9e65961SEric Fiselier static_assert((o3 == T(2)), "");
45a9e65961SEric Fiselier static_assert((o3 == val), "");
46a9e65961SEric Fiselier
47a9e65961SEric Fiselier static_assert(!(T(1) == o1), "");
48a9e65961SEric Fiselier static_assert((T(1) == o2), "");
49a9e65961SEric Fiselier static_assert(!(T(1) == o3), "");
50a9e65961SEric Fiselier static_assert((T(2) == o3), "");
51a9e65961SEric Fiselier static_assert((val == o3), "");
52a9e65961SEric Fiselier }
53dc808af3SEric Fiselier {
54dc808af3SEric Fiselier using O = optional<int>;
55dc808af3SEric Fiselier constexpr O o1(42);
56dc808af3SEric Fiselier static_assert(o1 == 42l, "");
57dc808af3SEric Fiselier static_assert(!(101l == o1), "");
58dc808af3SEric Fiselier }
59dc808af3SEric Fiselier {
60dc808af3SEric Fiselier using O = optional<const int>;
61dc808af3SEric Fiselier constexpr O o1(42);
62dc808af3SEric Fiselier static_assert(o1 == 42, "");
63dc808af3SEric Fiselier static_assert(!(101 == o1), "");
64dc808af3SEric Fiselier }
652df59c50SJF Bastien
662df59c50SJF Bastien return 0;
67a9e65961SEric Fiselier }
68