I want to create a class specialization that has the same implementation if it gets passed any std::variant or any boost::variant. I tried to play around with std::enable_if, std::disjunction and std::is_same but I couldn't make it compile. Here is a code sample to show what I want to achieve.
#include <variant>
#include <iostream>
#include <boost/variant.hpp>
template <typename T>
struct TypeChecker;
template <typename T>
struct TypeChecker<T>
{
void operator()()
{
std::cout << "I am other type\n";
}
}
template <typename ... Ts> // I want to be able to capture Ts... in TypeChecker scope
struct TypeChecker<std::variant<Ts...> or boost::variant<Ts...>> // what to insert here?
{
void operator()()
{
std::cout << "I am either std::variant or boost::variant\n";
}
}
int main()
{
TypeChecker<std::variant<int, float>>{}();
TypeChecker<boost::variant<int, float>>{}();
TypeChecker<int>{}();
}
Expected result:
I am either std::variant or boost::variant
I am either std::variant or boost::variant
I am other type
or
keyword/operator in C++ – Redolentor
keyword in C++ and it's synonymous to||
, but it cannot be used directly here without some metaprogramming. – Elstan