Is it possible to emplace some void* pointer into variant with a runtime generated index.
Can this nice solution (from here link), be updated to get index and pointer to emplace?
#include <variant>
template <typename... Ts, std::size_t... Is>
void next(std::variant<Ts...>& v, std::index_sequence<Is...>)
{
using Func = void (*)(std::variant<Ts...>&);
Func funcs[] = {
+[](std::variant<Ts...>& v){ v.template emplace<(Is + 1) % sizeof...(Is)>(); }...
};
funcs[v.index()](v);
}
template <typename... Ts>
void next(std::variant<Ts...>& v)
{
next(v, std::make_index_sequence<sizeof...(Ts)>());
}
It is possible to get the required data type, but don't think it helps anyway
Func funcs[] = {
[](MessageTypesVariant& v) {
auto y = std::get<(Is)>(v);
auto z = std::forward<decltype(y)>(y);
v.template emplace<(Is)>(); }...
};