Add tests making sure that optional<T>s can be compared at compile time; this functionality was enabled by N3789
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@192051 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
79d8c99a62
commit
2faa02fc3d
@ -14,11 +14,25 @@
|
|||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
#if _LIBCPP_STD_VER > 11
|
||||||
|
|
||||||
|
struct X
|
||||||
|
{
|
||||||
|
int i_;
|
||||||
|
|
||||||
|
constexpr X(int i) : i_(i) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr bool operator == ( const X &rhs, const X &lhs )
|
||||||
|
{ return rhs.i_ == lhs.i_ ; }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
#if _LIBCPP_STD_VER > 11
|
#if _LIBCPP_STD_VER > 11
|
||||||
{
|
{
|
||||||
typedef int T;
|
typedef X T;
|
||||||
typedef std::optional<T> O;
|
typedef std::optional<T> O;
|
||||||
|
|
||||||
constexpr T val(2);
|
constexpr T val(2);
|
||||||
@ -26,16 +40,16 @@ int main()
|
|||||||
constexpr O o2{1}; // engaged
|
constexpr O o2{1}; // engaged
|
||||||
constexpr O o3{val}; // engaged
|
constexpr O o3{val}; // engaged
|
||||||
|
|
||||||
static_assert ( !(o1 == 1), "" );
|
static_assert ( !(o1 == T(1)), "" );
|
||||||
static_assert ( o2 == 1, "" );
|
static_assert ( o2 == T(1), "" );
|
||||||
static_assert ( !(o3 == 1), "" );
|
static_assert ( !(o3 == T(1)), "" );
|
||||||
static_assert ( o3 == 2 , "" );
|
static_assert ( o3 == T(2) , "" );
|
||||||
static_assert ( o3 == val, "" );
|
static_assert ( o3 == val, "" );
|
||||||
|
|
||||||
static_assert ( !(1 == o1), "" );
|
static_assert ( !(T(1) == o1), "" );
|
||||||
static_assert ( 1 == o2, "" );
|
static_assert ( T(1) == o2, "" );
|
||||||
static_assert ( !(1 == o3), "" );
|
static_assert ( !(T(1) == o3), "" );
|
||||||
static_assert ( 2 == o3 , "" );
|
static_assert ( T(2) == o3 , "" );
|
||||||
static_assert ( val == o3 , "" );
|
static_assert ( val == o3 , "" );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -23,22 +23,9 @@ struct X
|
|||||||
constexpr X(int i) : i_(i) {}
|
constexpr X(int i) : i_(i) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace std
|
constexpr bool operator < ( const X &rhs, const X &lhs )
|
||||||
{
|
{ return rhs.i_ < lhs.i_ ; }
|
||||||
|
|
||||||
template <>
|
|
||||||
struct less<X>
|
|
||||||
{
|
|
||||||
constexpr
|
|
||||||
bool
|
|
||||||
operator()(const X& x, const X& y) const
|
|
||||||
{
|
|
||||||
return x.i_ < y.i_;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
@ -15,11 +15,25 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#if _LIBCPP_STD_VER > 11
|
||||||
|
|
||||||
|
struct X
|
||||||
|
{
|
||||||
|
int i_;
|
||||||
|
|
||||||
|
constexpr X(int i) : i_(i) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr bool operator == ( const X &rhs, const X &lhs )
|
||||||
|
{ return rhs.i_ == lhs.i_ ; }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
#if _LIBCPP_STD_VER > 11
|
#if _LIBCPP_STD_VER > 11
|
||||||
{
|
{
|
||||||
typedef int T;
|
typedef X T;
|
||||||
typedef std::optional<T> O;
|
typedef std::optional<T> O;
|
||||||
|
|
||||||
constexpr O o1; // disengaged
|
constexpr O o1; // disengaged
|
||||||
|
@ -22,21 +22,8 @@ struct X
|
|||||||
constexpr X(int i) : i_(i) {}
|
constexpr X(int i) : i_(i) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace std
|
constexpr bool operator < ( const X &rhs, const X &lhs )
|
||||||
{
|
{ return rhs.i_ < lhs.i_ ; }
|
||||||
|
|
||||||
template <>
|
|
||||||
struct less<X>
|
|
||||||
{
|
|
||||||
constexpr
|
|
||||||
bool
|
|
||||||
operator()(const X& x, const X& y) const
|
|
||||||
{
|
|
||||||
return x.i_ < y.i_;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user