From 01e279f2517d5c174f0579499615cf0af371a13b Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 17 Jun 2020 20:31:49 -0500 Subject: [PATCH] Add typelist::any and typelist::wrapped typelist::any determines whether any type in the list passes a predicate. typelist::wrapped wraps an uninstantiated template in a type so it can be handled within a typelist. --- include/fc/reflect/typelist.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/fc/reflect/typelist.hpp b/include/fc/reflect/typelist.hpp index d1d3e0d7a..f7f67bc43 100644 --- a/include/fc/reflect/typelist.hpp +++ b/include/fc/reflect/typelist.hpp @@ -128,6 +128,20 @@ struct zip, list> { using type = typename concat>, typename zip, list>::type>::type; }; +template class> struct any; +template class Predicate> +struct any, Predicate> { + constexpr static bool value = false; +}; +template class Predicate> +struct any, Predicate> { + constexpr static bool value = Predicate::value; +}; +template class Predicate> +struct any, Predicate> { + constexpr static bool value = Predicate::value || any, Predicate>::value; +}; + template Ret dispatch_helper(Callable& c) { return c(T()); } @@ -224,6 +238,17 @@ using zip = typename impl::zip::type; template using index = typename impl::zip()>::type, List>::type; +/// Determine whether any type in list passes predicate +template class Predicate> +constexpr static bool any = impl::any::value; + +/// A wrapper which wraps an uninstantiated template in a type so it can be handled in a typelist +template class Template> +struct wrapped { + template + using unwrap = Template; +}; + /// This namespace contains some utilities that provide runtime operations on typelists namespace runtime { /// Type wrapper object allowing arbitrary types to be passed to functions as information rather than data