mercredi 30 décembre 2015

Call method on parameter pack [duplicate]

This question already has an answer here:

I am trying to pass a parameter pack to a function. This function then needs to call a method on each element of the parameter pack. My (non-compiling) attempt here is this:

template <typename... TYPES>
void function_caller(const TYPES &... entries)
{
    // Doesn't compile!
    (entries...).some_method();
}

struct Foo { void some_method() { } };
struct Bar { void some_method() { } };

int main()
{
    Foo foo;
    Bar bar;

    function_caller(foo, bar);

    return 0;
}

clang++ doesn't like my parameter pack expansion. Is there a way to fix this without adding helper functions?

Aucun commentaire:

Enregistrer un commentaire