equal.pass.cpp revision 06086258d3d8c48a916ec51c33e1ad8f46821b81
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 optional<T>& y);
13
14#include <experimental/optional>
15#include <type_traits>
16#include <cassert>
17
18#if _LIBCPP_STD_VER > 11
19
20using std::experimental::optional;
21
22struct X
23{
24    int i_;
25
26    constexpr X(int i) : i_(i) {}
27};
28
29constexpr bool operator == ( const X &lhs, const X &rhs )
30    { return lhs.i_ == rhs.i_ ; }
31
32#endif
33
34int main()
35{
36#if _LIBCPP_STD_VER > 11
37    {
38    typedef X T;
39    typedef optional<T> O;
40
41    constexpr O o1;     // disengaged
42    constexpr O o2;     // disengaged
43    constexpr O o3{1};  // engaged
44    constexpr O o4{2};  // engaged
45    constexpr O o5{1};  // engaged
46
47    static_assert (   o1 == o1 , "" );
48    static_assert (   o1 == o2 , "" );
49    static_assert ( !(o1 == o3), "" );
50    static_assert ( !(o1 == o4), "" );
51    static_assert ( !(o1 == o5), "" );
52
53    static_assert (   o2 == o1 , "" );
54    static_assert (   o2 == o2 , "" );
55    static_assert ( !(o2 == o3), "" );
56    static_assert ( !(o2 == o4), "" );
57    static_assert ( !(o2 == o5), "" );
58
59    static_assert ( !(o3 == o1), "" );
60    static_assert ( !(o3 == o2), "" );
61    static_assert (   o3 == o3 , "" );
62    static_assert ( !(o3 == o4), "" );
63    static_assert (   o3 == o5 , "" );
64
65    static_assert ( !(o4 == o1), "" );
66    static_assert ( !(o4 == o2), "" );
67    static_assert ( !(o4 == o3), "" );
68    static_assert (   o4 == o4 , "" );
69    static_assert ( !(o4 == o5), "" );
70
71    static_assert ( !(o5 == o1), "" );
72    static_assert ( !(o5 == o2), "" );
73    static_assert (   o5 == o3 , "" );
74    static_assert ( !(o5 == o4), "" );
75    static_assert (   o5 == o5 , "" );
76
77    }
78#endif
79}
80