equal.pass.cpp revision 2faa02fc3d44e081fb7e3f36b19de622959aeb8c
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// <optional>
11
12// template <class T> constexpr bool operator==(const optional<T>& x, const T& v);
13// template <class T> constexpr bool operator==(const T& v, const optional<T>& x);
14
15#include <optional>
16
17#if _LIBCPP_STD_VER > 11
18
19struct X
20{
21    int i_;
22
23    constexpr X(int i) : i_(i) {}
24};
25
26constexpr bool operator == ( const X &rhs, const X &lhs )
27    { return rhs.i_ == lhs.i_ ; }
28
29#endif
30
31int main()
32{
33#if _LIBCPP_STD_VER > 11
34    {
35    typedef X T;
36    typedef std::optional<T> O;
37
38    constexpr T val(2);
39    constexpr O o1;     // disengaged
40    constexpr O o2{1};  // engaged
41    constexpr O o3{val};  // engaged
42
43    static_assert ( !(o1 == T(1)), "" );
44    static_assert (   o2 == T(1),  "" );
45    static_assert ( !(o3 == T(1)), "" );
46    static_assert (   o3 == T(2) , "" );
47    static_assert (   o3 == val, "" );
48
49    static_assert ( !(T(1) == o1), "" );
50    static_assert (   T(1) == o2,  "" );
51    static_assert ( !(T(1) == o3), "" );
52    static_assert (   T(2) == o3 , "" );
53    static_assert ( val == o3 , "" );
54    }
55#endif
56}
57