I need to store objects of exactly two types in a vector, the both types have almost nothing in common.
After storing them in the vector, I want to iterate over that vector and perform an action, depending on the type.
my thoughts so far:
Polymorphism. Overkill, and wouldn't help me much, as I probably would do this:
if(dynamic_cast<T1>() != nullptr) { ... } else { ... }
Merge both types (methods and fields) and add a boolean, representing if its type 1 or 2.
Both patterns seem totally clumsy to me, there is propably a total simple solution, I simply don't see.
The first type is something like this :
struct PatternMatch {
int length;
int indexInDict;
}
The second one:
struct NoMatch {
std::string rawChars;
}