I'd like to ask the compiler to check if a tuple contain only "meta types".
By the way I'm completely new with C++ concepts.
template < typename T >
struct Type {
using type = T;
};
//! A type can be easily check with a small concept
template < typename T >
concept bool C_Type = requires {
typename T::type;
};
//! But how to apply it on a whole tuple?
template < typename T >
void foo(T tuple) {}
int main() {
constexpr auto test = std::make_tuple(Type<int>{}, Type<double>{});
foo(test);
}
So I want to be sure that every type inside the sequence (let's say only something Iterable for this example) is a "meta type".
I'm using Boost Hana if it can simplify the code.
At the moment I'm not even sure if it's possible. I hope it is, I guess I just need to learn more meta-programming stuff. So I'll continue to search and try, but if somebody already has the answer, thanks!
Concepts are by design too weak to perform metaprogramming, so to do this you need some "metaprogramming help" from the rest of the language. I would use template specialization to decompose a type into a template and its type parameters, and then require all of those parameters to satisfy
C_Type
:This works with
hana::tuple
, andstd::tuple
- any template that takes all type parameters.