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 #include <type_traits>
16a9e65961SEric Fiselier #include <cassert>
17a9e65961SEric Fiselier
187fc6a556SMarshall Clow #include "test_macros.h"
197fc6a556SMarshall Clow
20a9e65961SEric Fiselier using std::optional;
21a9e65961SEric Fiselier
22dc808af3SEric Fiselier struct X {
23a9e65961SEric Fiselier int i_;
24a9e65961SEric Fiselier
XX25a9e65961SEric Fiselier constexpr X(int i) : i_(i) {}
26a9e65961SEric Fiselier };
27a9e65961SEric Fiselier
operator ==(const X & lhs,const X & rhs)28dc808af3SEric Fiselier constexpr bool operator==(const X& lhs, const X& rhs) {
29dc808af3SEric Fiselier return lhs.i_ == rhs.i_;
30dc808af3SEric Fiselier }
31a9e65961SEric Fiselier
main(int,char **)322df59c50SJF Bastien int main(int, char**) {
33a9e65961SEric Fiselier {
34a9e65961SEric Fiselier typedef X T;
35a9e65961SEric Fiselier typedef optional<T> O;
36a9e65961SEric Fiselier
37a9e65961SEric Fiselier constexpr O o1; // disengaged
38a9e65961SEric Fiselier constexpr O o2; // disengaged
39a9e65961SEric Fiselier constexpr O o3{1}; // engaged
40a9e65961SEric Fiselier constexpr O o4{2}; // engaged
41a9e65961SEric Fiselier constexpr O o5{1}; // engaged
42a9e65961SEric Fiselier
43a9e65961SEric Fiselier static_assert(o1 == o1, "");
44a9e65961SEric Fiselier static_assert(o1 == o2, "");
45a9e65961SEric Fiselier static_assert(!(o1 == o3), "");
46a9e65961SEric Fiselier static_assert(!(o1 == o4), "");
47a9e65961SEric Fiselier static_assert(!(o1 == o5), "");
48a9e65961SEric Fiselier
49a9e65961SEric Fiselier static_assert(o2 == o1, "");
50a9e65961SEric Fiselier static_assert(o2 == o2, "");
51a9e65961SEric Fiselier static_assert(!(o2 == o3), "");
52a9e65961SEric Fiselier static_assert(!(o2 == o4), "");
53a9e65961SEric Fiselier static_assert(!(o2 == o5), "");
54a9e65961SEric Fiselier
55a9e65961SEric Fiselier static_assert(!(o3 == o1), "");
56a9e65961SEric Fiselier static_assert(!(o3 == o2), "");
57a9e65961SEric Fiselier static_assert(o3 == o3, "");
58a9e65961SEric Fiselier static_assert(!(o3 == o4), "");
59a9e65961SEric Fiselier static_assert(o3 == o5, "");
60a9e65961SEric Fiselier
61a9e65961SEric Fiselier static_assert(!(o4 == o1), "");
62a9e65961SEric Fiselier static_assert(!(o4 == o2), "");
63a9e65961SEric Fiselier static_assert(!(o4 == o3), "");
64a9e65961SEric Fiselier static_assert(o4 == o4, "");
65a9e65961SEric Fiselier static_assert(!(o4 == o5), "");
66a9e65961SEric Fiselier
67a9e65961SEric Fiselier static_assert(!(o5 == o1), "");
68a9e65961SEric Fiselier static_assert(!(o5 == o2), "");
69a9e65961SEric Fiselier static_assert(o5 == o3, "");
70a9e65961SEric Fiselier static_assert(!(o5 == o4), "");
71a9e65961SEric Fiselier static_assert(o5 == o5, "");
72dc808af3SEric Fiselier }
73dc808af3SEric Fiselier {
74dc808af3SEric Fiselier using O1 = optional<int>;
75dc808af3SEric Fiselier using O2 = optional<long>;
76dc808af3SEric Fiselier constexpr O1 o1(42);
77dc808af3SEric Fiselier static_assert(o1 == O2(42), "");
78dc808af3SEric Fiselier static_assert(!(O2(101) == o1), "");
79dc808af3SEric Fiselier }
80dc808af3SEric Fiselier {
81dc808af3SEric Fiselier using O1 = optional<int>;
82dc808af3SEric Fiselier using O2 = optional<const int>;
83dc808af3SEric Fiselier constexpr O1 o1(42);
84dc808af3SEric Fiselier static_assert(o1 == O2(42), "");
85dc808af3SEric Fiselier static_assert(!(O2(101) == o1), "");
86a9e65961SEric Fiselier }
872df59c50SJF Bastien
882df59c50SJF Bastien return 0;
89a9e65961SEric Fiselier }
90