I have a template class that takes std::variant
as a template parameter:
template<class T>
class X
{
};
X<std::variant<int, float>> x;
I want to add a constraint for T
to be derived from std::variant
.
Then I want to extract template parameters of this variant to use them inside the class.
Like this:
template<class T, std::enable_if_t<
std::is_base_of_v<std::variant<T::_Types>, T>, // _Types = int, float
bool> = true>
class X
{
std::tuple<T::_Types> t; // std::tuple<int, float>
};
X<std::variant<int, float>> x;
The problem is that I cannot get these int, float
parameters from the variant
type.
Is there a way to do this in C++17?
This variant comes from return type of a function.
Because of this I cannot change it for something like variant parameters instead (to take int, float
directly).