mardi 23 février 2021

Make decision depending on variadic types

I know I have made the title as blurry as possible, but the sample will hopefully set the goals.

I have a Base class and families of Derived classes (classy OOD, nothing more).
Furthermore I have a function which takes variadic templates and I want to make decision depending on those templates.

template<typename... Ts>
void do_smth(std::vector<std::shared_ptr<Base>>& vec) {
    for (auto&& ptr: vec) {
        if the static type of ptr is one of Ts.. then do smth.
    }
}

And I intend to call the function as this:

do_smth<Deived1, Derived2>(vec);

I know I could forward the Ts... to std::variant check with hold_alternative or smth like this, but I have only types not values. And to complicate the matters, my compiler is limitied with C++14 support.
Can someone please suggest some tiny/elegant solution to this?

Aucun commentaire:

Enregistrer un commentaire