Where is the fold expression ()?

Viewed 163

Reference fluentCPP article

The below code explanation says that this structure inherits from several lambdas, can be constructed from those lambdas, and folds over the using expression.

template<typename... Lambdas>
struct overloaded : public Lambdas...
{
    explicit overloaded(Lambdas... lambdas) : Lambdas(lambdas)... {}

    using Lambdas::operator()...;
};

My doubt is that parentheses i.e () indicate a c++17 fold expression but I don't see any enclosing parentheses around the using statement. How will it fold?

1 Answers

This isn't a fold expression. You cannot have any expression statements in class scope. And as you point out, there are no parentheses that are part of the fold expression syntax.

This is a declaration with a parameter pack expansion. Pack expansions can be used in many more context than just fold expressions.

what will this statement do?

It will declare

using L::operator();

for each type L in the parameter pack Lambdas.

Usually using is used same as typedef

That's not the only use case of that keyword. In this context, it is used to introduce a member (function) of a base class into the derived class.

Related