From e32bf3976686c01fe9804086a8ca48aa0069b392 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 27 Dec 2018 17:38:26 -0500 Subject: [PATCH] [meta] Add enable_if --- src/hb-meta.hh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/hb-meta.hh b/src/hb-meta.hh index 6285d3966..62fc71a0c 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -30,6 +30,11 @@ #include "hb.hh" +/* + * C++ Template Meta-programming. + */ + + /* Void! For when we need a expression-type of void. */ struct hb_void_t { typedef void value; }; @@ -37,4 +42,15 @@ struct hb_true_t { enum { value = true }; }; struct hb_false_t { enum { value = false }; }; + +template +struct hb_enable_if {}; + +template +struct hb_enable_if { typedef T type; }; + +#define hb_enable_if(Cond) hb_enable_if::type* = nullptr +#define hb_enable_if_t(Type, Cond) hb_enable_if<(Cond), Type>::type + + #endif /* HB_META_HH */