From b14745278ad16fe7f4e838b685029e3fdda516ca Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 10 May 2019 21:42:59 -0700 Subject: [PATCH] [met]a Add is_constructible, ... --- src/hb-meta.hh | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test-meta.cc | 23 ++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/src/hb-meta.hh b/src/hb-meta.hh index f676231..0ab7179 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -292,4 +292,77 @@ template <> struct hb_int_max : hb_integral_constant::value +template +struct _hb_is_constructible : hb_false_type {}; +template +struct _hb_is_constructible, Ts...> : hb_true_type {}; +template +using hb_is_constructible = _hb_is_constructible; +#define hb_is_constructible(...) hb_is_constructible<__VA_ARGS__>::value + +template +using hb_is_default_constructible = hb_is_constructible; +#define hb_is_default_constructible(T) hb_is_default_constructible::value + +template +using hb_is_copy_constructible = hb_is_constructible>>; +#define hb_is_copy_constructible(T) hb_is_copy_constructible::value + +template +using hb_is_move_constructible = hb_is_constructible>>; +#define hb_is_move_constructible(T) hb_is_move_constructible::value + +template +struct _hb_is_assignable : hb_false_type {}; +template +struct _hb_is_assignable> : hb_true_type {}; +template +using hb_is_assignable = _hb_is_assignable; +#define hb_is_assignable(T,U) hb_is_assignable::value + +template +using hb_is_copy_assignable = hb_is_assignable, + hb_add_lvalue_reference>>; +#define hb_is_copy_assignable(T) hb_is_copy_assignable::value + +template +using hb_is_move_assignable = hb_is_assignable, + hb_add_rvalue_reference>; +#define hb_is_move_assignable(T) hb_is_move_assignable::value + +/* Trivial versions. */ + +template union hb_trivial { T value; }; + +/* Don't know how to do the following. */ +//template +//using hb_is_trivially_constructible= hb_is_constructible, hb_trivial...>; +//#define hb_is_trivially_constructible(...) hb_is_trivially_constructible<__VA_ARGS__>::value + +template +using hb_is_trivially_default_constructible= hb_is_default_constructible>; +#define hb_is_trivially_default_constructible(T) hb_is_trivially_default_constructible::value + +template +using hb_is_trivially_copy_constructible= hb_is_copy_constructible>; +#define hb_is_trivially_copy_constructible(T) hb_is_trivially_copy_constructible::value + +template +using hb_is_trivially_move_constructible= hb_is_move_constructible>; +#define hb_is_trivially_move_constructible(T) hb_is_trivially_move_constructible::value + +/* Don't know how to do the following. */ +//template +//using hb_is_trivially_assignable= hb_is_assignable, hb_trivial>; +//#define hb_is_trivially_assignable(T,U) hb_is_trivially_assignable::value + +template +using hb_is_trivially_copy_assignable= hb_is_copy_assignable>; +#define hb_is_trivially_copy_assignable(T) hb_is_trivially_copy_assignable::value + +template +using hb_is_trivially_move_assignable= hb_is_move_assignable>; +#define hb_is_trivially_move_assignable(T) hb_is_trivially_move_assignable::value + + #endif /* HB_META_HH */ diff --git a/src/test-meta.cc b/src/test-meta.cc index 6fb8e4f..af1ca2e 100644 --- a/src/test-meta.cc +++ b/src/test-meta.cc @@ -27,6 +27,8 @@ #include "hb.hh" #include "hb-meta.hh" +#include + int main (int argc, char **argv) @@ -94,5 +96,26 @@ main (int argc, char **argv) static_assert (hb_is_base_of (X, const Y), ""); static_assert (!hb_is_base_of (Y, X), ""); + static_assert (hb_is_constructible (int), ""); + static_assert (hb_is_constructible (int, int), ""); + static_assert (hb_is_constructible (int, char), ""); + static_assert (hb_is_constructible (int, long), ""); + static_assert (!hb_is_constructible (int, X), ""); + static_assert (!hb_is_constructible (int, int, int), ""); + static_assert (hb_is_constructible (X), ""); + static_assert (!hb_is_constructible (X, int), ""); + static_assert (hb_is_constructible (X, X), ""); + static_assert (!hb_is_constructible (X, X, X), ""); + static_assert (hb_is_constructible (X, Y), ""); + static_assert (!hb_is_constructible (Y, X), ""); + + static_assert (hb_is_trivially_default_constructible (X), ""); + static_assert (hb_is_trivially_default_constructible (Y), ""); + static_assert (hb_is_trivially_copy_constructible (X), ""); + static_assert (hb_is_trivially_copy_constructible (Y), ""); + static_assert (hb_is_trivially_move_constructible (X), ""); + static_assert (hb_is_trivially_move_constructible (Y), ""); + /* TODO Add more meaningful tests. */ + return 0; } -- 2.7.4