Add HB_RETURN

pull/1674/head
Behdad Esfahbod 6 years ago
parent 6745a600bf
commit c67a0d581f
  1. 13
      src/hb-algs.hh
  2. 34
      src/hb-meta.hh

@ -50,7 +50,7 @@ struct
{
private:
template <typename T> auto
impl (const T& v, hb_priority<1>) const HB_AUTO_RETURN (hb_deref_pointer (v).hash ())
impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, hb_deref_pointer (v).hash ())
template <typename T,
hb_enable_if (hb_is_integer (T))> auto
@ -63,7 +63,7 @@ struct
public:
template <typename T> auto
operator () (const T& v) const HB_AUTO_RETURN ((uint32_t) impl (v, hb_prioritize))
operator () (const T& v) const HB_RETURN (uint32_t, impl (v, hb_prioritize))
} HB_FUNCOBJ (hb_hash);
struct
@ -114,11 +114,10 @@ struct
public:
template <typename Pred, typename Val> auto
operator () (Pred&& p, Val &&v) const HB_AUTO_RETURN
(
(bool) impl (hb_forward<Pred> (p),
hb_forward<Val> (v),
hb_prioritize)
operator () (Pred&& p, Val &&v) const HB_RETURN (bool,
impl (hb_forward<Pred> (p),
hb_forward<Val> (v),
hb_prioritize)
)
} HB_FUNCOBJ (hb_has);

@ -34,8 +34,27 @@
* C++ template meta-programming & fundamentals used with them.
*/
/* Void! For when we need a expression-type of void. */
struct hb_void_t { typedef void value; };
/* Void meta-function ala std::void_t
* https://en.cppreference.com/w/cpp/types/void_t */
template<typename... Ts> struct _hb_void_tt { typedef void type; };
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_tt { enum { value = b }; };
typedef hb_bool_tt<true> hb_true_t;
typedef hb_bool_tt<false> hb_false_t;
/* Function overloading SFINAE and priority. */
#define HB_RETURN(Ret, E) -> hb_head_tt<Ret, decltype ((E))> { return (E); }
#define HB_AUTO_RETURN(E) -> decltype ((E)) { return (E); }
#define HB_VOID_RETURN(E) -> hb_void_tt<decltype ((E))> { (E); }
@ -45,6 +64,7 @@ template <> struct hb_priority<0> {};
#define HB_FUNCOBJ(x) static_const x HB_UNUSED
struct
{
template <typename T>
@ -98,20 +118,6 @@ struct
} HB_FUNCOBJ (hb_deref_pointer);
/* Void! For when we need a expression-type of void. */
struct hb_void_t { typedef void value; };
/* Void meta-function ala std::void_t
* https://en.cppreference.com/w/cpp/types/void_t */
template<typename... Ts> struct _hb_void_tt { typedef void type; };
template<typename... Ts> using hb_void_tt = typename _hb_void_tt<Ts...>::type;
/* Bool! For when we need to evaluate type-dependent expressions
* in a template argument. */
template <bool b> struct hb_bool_tt { enum { value = b }; };
typedef hb_bool_tt<true> hb_true_t;
typedef hb_bool_tt<false> hb_false_t;
template<bool B, typename T = void> struct hb_enable_if {};
template<typename T> struct hb_enable_if<true, T> { typedef T type; };
#define hb_enable_if(Cond) typename hb_enable_if<(Cond)>::type* = nullptr

Loading…
Cancel
Save