variadic: add filter call
This commit is contained in:
parent
cceadcba40
commit
86b1fa38c7
28
variadic.hpp
28
variadic.hpp
@ -20,6 +20,7 @@
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <tuple>
|
||||
|
||||
|
||||
namespace util::variadic {
|
||||
@ -53,7 +54,32 @@ namespace util::variadic {
|
||||
else
|
||||
return get<IndexV-1> (std::forward<TailT> (tail)...);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// returns a tuple of all arguments that satisfy the trait QueryT
|
||||
template <template <typename> class QueryT>
|
||||
auto filter () { return std::tuple {}; }
|
||||
|
||||
|
||||
/// returns a tuple of all arguments that satisfy the trait QueryT
|
||||
template <
|
||||
template <typename> class QueryT,
|
||||
typename HeadT,
|
||||
typename ...ArgsT
|
||||
>
|
||||
auto
|
||||
filter (HeadT &&head, ArgsT &&...args)
|
||||
{
|
||||
if constexpr (QueryT<HeadT>::value)
|
||||
return std::tuple_cat (
|
||||
std::tuple (std::forward<HeadT> (head)),
|
||||
filter<QueryT> (std::forward<ArgsT> (args)...)
|
||||
);
|
||||
else
|
||||
return filter<QueryT> (std::forward<ArgsT> (args)...);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user