Answers for "varint index"

C++
0

varint index

template <typename> struct tag { };

template <typename T, typename V>
struct variant_index;

template <typename T, typename... Ts> 
struct variant_index<T, std::variant<Ts...>>
    : std::integral_constant<size_t, std::variant<tag<Ts>...>(tag<T>()).index()>
{ };

// Use as: variant_index<TYPE, VARIANT>::value
Posted by: Guest on April-19-2020

Browse Popular Code Answers by Language