Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typelist::any and typelist::wrapped #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions include/fc/reflect/typelist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ struct zip<list<A, As...>, list<B, Bs...>> {
using type = typename concat<list<list<A, B>>, typename zip<list<As...>, list<Bs...>>::type>::type;
};

template<typename, template<typename> class> struct any;
template<template<typename> class Predicate>
struct any<list<>, Predicate> {
constexpr static bool value = false;
};
template<typename T, template<typename> class Predicate>
struct any<list<T>, Predicate> {
constexpr static bool value = Predicate<T>::value;
};
template<typename T1, typename T2, typename... Ts, template<typename> class Predicate>
struct any<list<T1, T2, Ts...>, Predicate> {
constexpr static bool value = Predicate<T1>::value || any<list<T2, Ts...>, Predicate>::value;
};

template<typename Callable, typename Ret, typename T>
Ret dispatch_helper(Callable& c) { return c(T()); }

Expand Down Expand Up @@ -224,6 +238,17 @@ using zip = typename impl::zip<ListA, ListB>::type;
template<typename List>
using index = typename impl::zip<typename impl::make_sequence<length<List>()>::type, List>::type;

/// Determine whether any type in list passes predicate
template<typename List, template<typename> class Predicate>
constexpr static bool any = impl::any<List, Predicate>::value;

/// A wrapper which wraps an uninstantiated template in a type so it can be handled in a typelist
template<template<typename...> class Template>
struct wrapped {
template<typename... Ts>
using unwrap = Template<Ts...>;
};

/// 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
Expand Down