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