gpt4 book ai didi

c++ - 类型推导 lambda 引用资料

转载 作者:行者123 更新时间:2023-11-27 22:58:25 26 4
gpt4 key购买 nike

我看到了this answer但我不满意:“auto”的类型推导不考虑默认参数的标准在哪里写的?

int main() {
auto lambda = [] (auto subl = [] {}) {};
lambda();
}

最佳答案

auto 根据模板参数推导使用规则([dcl.spec.auto]/p7):

If the placeholder is the auto type-specifier, the deduced type is determined using the rules for template argument deduction.

当默认参数的类型是推导模板参数时,默认参数是明确的非推导上下文 ([temp.deduct.type]/p5):

The non-deduced contexts are:

— The nested-name-specifier of a type that was specified using a qualified-id.

— The expression of a decltype-specifier.

— A non-type template argument or an array bound in which a subexpression references a template parameter.

A template parameter used in the parameter type of a function parameter that has a default argument that is being used in the call for which argument deduction is being done.

关于c++ - 类型推导 lambda 引用资料,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30240851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com