简体   繁体   English

折叠表达式 () 在哪里?

[英]Where is the fold expression ()?

Reference fluentCPP article参考fluentCPP文章

The below code explanation says that this structure inherits from several lambdas, can be constructed from those lambdas, and folds over the using expression.下面的代码解释说这个结构继承自几个 lambda,可以从这些 lambda 构造,并折叠using表达式。

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.我怀疑括号 ie () 表示 c++17 折叠表达式,但我没有看到 using 语句周围有任何括号。 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.您不能在 class scope 中包含任何表达式语句。正如您所指出的,折叠表达式语法中没有括号。

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 .对于参数包Lambdas中的每个类型L

Usually using is used same as typedef通常使用与 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.在此上下文中,它用于将基类 class 的成员(函数)引入到派生的 class 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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