Код: Выделить всё
template
constexpr auto get_n = [](/*tuple-like*/auto&& t, std::size_t index)
{
using variant_type = decltype(std::apply([](auto&&... v){
return std::variant{};
}, t));
constexpr auto size = std::tuple_size_v;
if constexpr(N > size)
return variant_type{};
else
{
if(N == index + 1)
return variant_type(std::in_place_index, std::get(t));
else
return get_n(t, index);
}
};
constexpr auto tuple_to_variant(/*tuple-like*/auto&& t, std::size_t index)
{
return get_n(std::forward(t), index);
}
Вот демо-версия Compiler Explorer
Подробнее здесь: https://stackoverflow.com/questions/787 ... t-problems