[meta] Add integral_constant, true_t -> true_type, false_t -> false_type

This commit is contained in:
Behdad Esfahbod 2019-05-10 20:06:31 -07:00
parent 38e3a8bd53
commit 61d150c916
3 changed files with 20 additions and 21 deletions

View File

@ -243,8 +243,8 @@ template<typename Iter, typename Item>
struct hb_is_iterator_of
{
template <typename Item2 = Item>
static hb_true_t impl (hb_priority<2>, hb_iter_t<Iter, hb_type_identity<Item2>> *);
static hb_false_t impl (hb_priority<0>, const void *);
static hb_true_type impl (hb_priority<2>, hb_iter_t<Iter, hb_type_identity<Item2>> *);
static hb_false_type impl (hb_priority<0>, const void *);
public:
static constexpr bool value = decltype (impl (hb_prioritize, hb_declval (Iter*)))::value;
@ -260,10 +260,10 @@ struct hb_is_iterable
private:
template <typename U>
static auto impl (hb_priority<1>) -> decltype (hb_declval (U).iter (), hb_true_t ());
static auto impl (hb_priority<1>) -> decltype (hb_declval (U).iter (), hb_true_type ());
template <typename>
static hb_false_t impl (hb_priority<0>);
static hb_false_type impl (hb_priority<0>);
public:
static constexpr bool value = decltype (impl<T> (hb_prioritize))::value;
@ -278,10 +278,10 @@ struct hb_is_source_of
private:
template <typename Iter2 = Iter,
hb_enable_if (hb_is_convertible (typename Iter2::item_t, const Item &))>
static hb_true_t impl (hb_priority<2>);
static hb_true_type impl (hb_priority<2>);
template <typename Iter2 = Iter>
static auto impl (hb_priority<1>) -> decltype (hb_declval (Iter2) >> hb_declval (Item &), hb_true_t ());
static hb_false_t impl (hb_priority<0>);
static auto impl (hb_priority<1>) -> decltype (hb_declval (Iter2) >> hb_declval (Item &), hb_true_type ());
static hb_false_type impl (hb_priority<0>);
public:
static constexpr bool value = decltype (impl (hb_prioritize))::value;
@ -294,10 +294,10 @@ struct hb_is_sink_of
private:
template <typename Iter2 = Iter,
hb_enable_if (hb_is_convertible (typename Iter2::item_t, Item &))>
static hb_true_t impl (hb_priority<2>);
static hb_true_type impl (hb_priority<2>);
template <typename Iter2 = Iter>
static auto impl (hb_priority<1>) -> decltype (hb_declval (Iter2) << hb_declval (Item), hb_true_t ());
static hb_false_t impl (hb_priority<0>);
static auto impl (hb_priority<1>) -> decltype (hb_declval (Iter2) << hb_declval (Item), hb_true_type ());
static hb_false_type impl (hb_priority<0>);
public:
static constexpr bool value = decltype (impl (hb_prioritize))::value;

View File

@ -45,11 +45,10 @@ template<typename... Ts> using hb_void_tt = typename _hb_void_tt<Ts...>::type;
template<typename Head, typename... Ts> struct _hb_head_tt { typedef Head type; };
template<typename... Ts> using hb_head_tt = typename _hb_head_tt<Ts...>::type;
/* Bool! For when we need to evaluate type-dependent expressions
* in a template argument. */
template <bool b> struct hb_bool_constant { static constexpr bool value = b; };
typedef hb_bool_constant<true> hb_true_t;
typedef hb_bool_constant<false> hb_false_t;
template <typename T, T v> struct hb_integral_constant { static constexpr T value = v; };
template <bool b> using hb_bool_constant = hb_integral_constant<bool, b>;
using hb_true_type = hb_bool_constant<true>;
using hb_false_type = hb_bool_constant<false>;
/* Basic type SFINAE. */
@ -60,8 +59,8 @@ template <typename T> struct hb_enable_if<true, T> { typedef T ty
/* Concepts/Requires alias: */
#define hb_requires(Cond) hb_enable_if((Cond))
template <typename T, typename T2> struct hb_is_same : hb_false_t {};
template <typename T> struct hb_is_same<T, T> : hb_true_t {};
template <typename T, typename T2> struct hb_is_same : hb_false_type {};
template <typename T> struct hb_is_same<T, T> : hb_true_type {};
#define hb_is_same(T, T2) hb_is_same<T, T2>::value
/* Function overloading SFINAE and priority. */
@ -145,12 +144,12 @@ struct hb_is_convertible
static constexpr bool either_void = from_void || to_void;
static constexpr bool both_void = from_void && to_void;
static hb_true_t impl2 (hb_conditional<to_void, int, To>);
static hb_true_type impl2 (hb_conditional<to_void, int, To>);
template <typename T>
static auto impl (hb_priority<1>) -> decltype (impl2 (hb_declval (T)));
template <typename T>
static hb_false_t impl (hb_priority<0>);
static hb_false_type impl (hb_priority<0>);
public:
static constexpr bool value = both_void ||
(!either_void &&

View File

@ -55,7 +55,7 @@ struct _hb_null_size<T, hb_bool_constant<true || sizeof (T::min_size)>>
template <typename T>
struct hb_null_size
{ enum { value = _hb_null_size<T, hb_true_t>::value }; };
{ enum { value = _hb_null_size<T, hb_true_type>::value }; };
#define hb_null_size(T) hb_null_size<T>::value
/* These doesn't belong here, but since is copy/paste from above, put it here. */
@ -72,7 +72,7 @@ struct _hb_static_size<T, hb_bool_constant<true || sizeof (T::min_size)>>
template <typename T>
struct hb_static_size
{ enum { value = _hb_static_size<T, hb_true_t>::value }; };
{ enum { value = _hb_static_size<T, hb_true_type>::value }; };
#define hb_static_size(T) hb_static_size<T>::value