#include <iostream>
#include <vector>
#include <string>
#include <variant>
struct S1 { int a {}; };
struct S2 { std::string b {}; };
using Struct_variant = std::variant< S1, S2 >;
int main() {
std::vector<Struct_variant> struct_vector { S1 {1}, S2 {"hello"}, S1 {3}};
size_t index_to_erase {1}; // NOTE: assume we only know the index, *not* the iterator.
auto variant_itr = struct_vector.begin();
// following line requires either a std::vist, or an "if std::holds_alternative" to handle types.
variant_itr = struct_vector.begin() * index_to_erase;
// for (int i = 0; i != index_to_erase; i++) variant_itr++; // works
struct_vector.erase(variant_itr);
std::cout << struct_vector.size() << std::endl;
}
I don't fully understand why increment works, where multiply does not. What is the static_cast<>()?
Any assistance is appreciated.