1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 // <optional>
12
13 // template <class T, class U> constexpr bool operator!=(const optional<T>& x, const optional<U>& y);
14
15 #include <optional>
16 #include <type_traits>
17 #include <cassert>
18
19 using std::optional;
20
21 struct X {
22 int i_;
23
XX24 constexpr X(int i) : i_(i) {}
25 };
26
operator !=(const X & lhs,const X & rhs)27 constexpr bool operator!=(const X& lhs, const X& rhs) {
28 return lhs.i_ != rhs.i_;
29 }
30
main()31 int main() {
32 {
33 typedef X T;
34 typedef optional<T> O;
35
36 constexpr O o1; // disengaged
37 constexpr O o2; // disengaged
38 constexpr O o3{1}; // engaged
39 constexpr O o4{2}; // engaged
40 constexpr O o5{1}; // engaged
41
42 static_assert(!(o1 != o1), "");
43 static_assert(!(o1 != o2), "");
44 static_assert((o1 != o3), "");
45 static_assert((o1 != o4), "");
46 static_assert((o1 != o5), "");
47
48 static_assert(!(o2 != o1), "");
49 static_assert(!(o2 != o2), "");
50 static_assert((o2 != o3), "");
51 static_assert((o2 != o4), "");
52 static_assert((o2 != o5), "");
53
54 static_assert((o3 != o1), "");
55 static_assert((o3 != o2), "");
56 static_assert(!(o3 != o3), "");
57 static_assert((o3 != o4), "");
58 static_assert(!(o3 != o5), "");
59
60 static_assert((o4 != o1), "");
61 static_assert((o4 != o2), "");
62 static_assert((o4 != o3), "");
63 static_assert(!(o4 != o4), "");
64 static_assert((o4 != o5), "");
65
66 static_assert((o5 != o1), "");
67 static_assert((o5 != o2), "");
68 static_assert(!(o5 != o3), "");
69 static_assert((o5 != o4), "");
70 static_assert(!(o5 != o5), "");
71 }
72 {
73 using O1 = optional<int>;
74 using O2 = optional<long>;
75 constexpr O1 o1(42);
76 static_assert(o1 != O2(101), "");
77 static_assert(!(O2(42) != o1), "");
78 }
79 {
80 using O1 = optional<int>;
81 using O2 = optional<const int>;
82 constexpr O1 o1(42);
83 static_assert(o1 != O2(101), "");
84 static_assert(!(O2(42) != o1), "");
85 }
86 }
87