I have a datastructure meta_array
which is instantiated with a variant as type T parameter. The requirement is that the std::variant specialization must contain the type meta_array_head_t
as this is is used for tracking information. Can I somehow state this as a requirement using type traits (C++17)?
#include <cstdio>
#include <variant>
#include <array>
struct meta_array_head_t {
// end_;
// remaining_;
// prev_;
};
template <typename T, size_t S> // make sure T = std::variant<... , meta_array_head_t, ...>
struct meta_array
{
std::array<T, S> data_;
};
using val = std::variant<std::monostate, int, double, meta_array_head_t>;
int main()
{
meta_array<val, 100> marray;
}
First, determine that
T
is of typestd::variant
, then use fold expression to detect whether the alternative type containsmeta_array_head_t
.Demo