types/traits: add is_orderable trait

This commit is contained in:
Danny Robson 2018-11-19 15:35:05 +11:00
parent 3625a92977
commit e42f71f9af

View File

@ -470,4 +470,32 @@ namespace cruft {
template <typename T> template <typename T>
constexpr auto is_tuple_like_v = is_tuple_like<T>::value; constexpr auto is_tuple_like_v = is_tuple_like<T>::value;
}
///////////////////////////////////////////////////////////////////////////
/// Tests if a type is orderable; ie, if it supports the less than operator
///
/// We use void_t to detect the presence of an appropriate operator<
template <
typename ValueT,
typename = std::void_t<>
>
struct is_orderable : public std::false_type {};
//-------------------------------------------------------------------------
template <typename ValueT>
struct is_orderable<
ValueT,
std::void_t<
decltype (
std::declval<ValueT> () < std::declval<ValueT> ()
)
>
> : std::true_type {};
//-----------------------------------------------------------------------------------
template <typename ValueT>
constexpr auto is_orderable_v = is_orderable<ValueT>::value;
};