简体   繁体   中英

Where is the fold expression ()?

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 ie () indicate a c++17 fold expression but I don't see any enclosing parentheses around the using statement. How will it fold?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM