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> constexpr bool operator==(const optional<T>& x, const T& v);
14 // template <class T> constexpr bool operator==(const T& v, const optional<T>& x);
15
16 #include <optional>
17
18 using std::optional;
19
20 struct X
21 {
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
main()30 int main()
31 {
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)), "" );
43 static_assert ( !(o3 == T(1)), "" );
44 static_assert ( (o3 == T(2)), "" );
45 static_assert ( (o3 == val), "" );
46
47 static_assert ( !(T(1) == o1), "" );
48 static_assert ( (T(1) == o2), "" );
49 static_assert ( !(T(1) == o3), "" );
50 static_assert ( (T(2) == o3), "" );
51 static_assert ( (val == o3), "" );
52 }
53 }
54