I've been stuck on this for a while and I ran out of ideas, help appreciated!
The following segments are example code, to simplify.
Assume the following:
class Base;
class DerivedA : public Base;
class DerivedB : public Base;
and this:
class Manager {
public:
std::map<std::type_index, Base*> container;
template<typename ...T>
void remove() {
// Iterate through templates somehow and...
container.erase(typeid(T));
}
}
Basically I'm storing, in a container, unique instances of derived classes, by using the std::type_index as a key. Allowing me to do something like:
manager.remove<DerivedA>();
With that said, I'd like to be able to do the same thing, but allow multiple templates directly to remove multiple instances at once, as such:
manager.remove<DerivedA, DerivedB>()
I know it is possible to iterate through variadic templates as described here, but I keep getting compilation errors...
error C2440: 'initializing': cannot convert from 'initializer-list' to 'std::initializer_list'
error C3535: cannot deduce type for 'auto' from 'initializer-list'
...when I try to run this code:
template<typename ...T>
void remove() {
// Iterate through templates somehow and...
auto list = {(container.erase(typeid(T)))... };
}
Any ideas? Thank you very much.