Вот пример, демонстрирующий то, что я хотел бы сделать:
Код: Выделить всё
template
bool update_variant(std::variant& v, std::tuple& gen) {
return visit_with_index([&](auto& e) {
if (e.done()) {
// we are done with e
constexpr size_t next_index = Index + 1;
if constexpr (next_index == sizeof...(Ts)) {
// no more other work to do
return false;
} else {
// still have other work to do so we move on to the next variant alternative
v.emplace(
std::in_place_index_t{},
std::get(gen).create_worker()
);
return true;
}
} else {
// do some work on e, so e gets closer to the done state
e.do_some_work();
return true;
}
}, v);
}
Кроме написания моей собственной версии visit_with_index, которая фактически является написанием моей собственной версии std::visit, есть ли более простые способы добиться того, чего я хочу, не выполняя более одного поиска по индексу?
Подробнее здесь: https://stackoverflow.com/questions/791 ... isiting-it
Мобильная версия