Home | History | Annotate | Download | only in optional.relops
      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
     11 // <optional>
     12 
     13 // template <class T> constexpr bool operator<= (const optional<T>& x, const optional<T>& y);
     14 
     15 #include <experimental/optional>
     16 
     17 using std::experimental::optional;
     18 
     19 struct X
     20 {
     21     int i_;
     22 
     23     constexpr X(int i) : i_(i) {}
     24 };
     25 
     26 constexpr bool operator < ( const X &lhs, const X &rhs )
     27     { return lhs.i_ < rhs.i_ ; }
     28 
     29 int main()
     30 {
     31     {
     32     typedef optional<X> O;
     33 
     34     constexpr O o1;     // disengaged
     35     constexpr O o2;     // disengaged
     36     constexpr O o3{1};  // engaged
     37     constexpr O o4{2};  // engaged
     38     constexpr O o5{1};  // engaged
     39 
     40     static_assert (  (o1 <= o1), "" );
     41     static_assert (  (o1 <= o2), "" );
     42     static_assert (  (o1 <= o3), "" );
     43     static_assert (  (o1 <= o4), "" );
     44     static_assert (  (o1 <= o5), "" );
     45 
     46     static_assert (  (o2 <= o1), "" );
     47     static_assert (  (o2 <= o2), "" );
     48     static_assert (  (o2 <= o3), "" );
     49     static_assert (  (o2 <= o4), "" );
     50     static_assert (  (o2 <= o5), "" );
     51 
     52     static_assert ( !(o3 <= o1), "" );
     53     static_assert ( !(o3 <= o2), "" );
     54     static_assert (  (o3 <= o3), "" );
     55     static_assert (  (o3 <= o4), "" );
     56     static_assert (  (o3 <= o5), "" );
     57 
     58     static_assert ( !(o4 <= o1), "" );
     59     static_assert ( !(o4 <= o2), "" );
     60     static_assert ( !(o4 <= o3), "" );
     61     static_assert (  (o4 <= o4), "" );
     62     static_assert ( !(o4 <= o5), "" );
     63 
     64     static_assert ( !(o5 <= o1), "" );
     65     static_assert ( !(o5 <= o2), "" );
     66     static_assert (  (o5 <= o3), "" );
     67     static_assert (  (o5 <= o4), "" );
     68     static_assert (  (o5 <= o5), "" );
     69     }
     70 }
     71