Reputation: 2399
I am restrained to use C++17 and I want to pass a type to a lambda by passing in a type tag, which I can in the following way in C++ 20 and C++17.
template<typename T>
struct Type
{
using type = T;
};
auto lambda20 = []<typename T>(Type<T>){
static_assert(std::is_same_v<T, int>);
};
auto lambda17 = [](auto tag){
static_assert(std::is_same_v<typename decltype(tag)::type, int>);
};
void test()
{
lambda20(Type<int>{});
lambda17(Type<int>{});
}
Is there a shorter syntax than the typename decltype(tag)::type I can use to extract the type from the type tag in C++ 17?
Upvotes: 2
Views: 158