Lambda是否有不同类型? [英] Do lambdas have different types?

查看:49
本文介绍了Lambda是否有不同类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个lambda都应具有唯一的未知类型.是否保证同一作用域中的两个lambda具有不同的类型?

Every lambda should have a unique unknown type.. is it guaranteed that two lambdas into the same scope have different types?

int main() {
   auto l1 = [](){};
   auto l2 = [](){};   
  static_assert(std::is_same<decltype(l1), decltype(l2)>::value == false, "Types cannot be equal!");
}

这可行,但是我想知道是否可以保证断言永远不会触发.

This works but I'd like to know if it's guaranteed that the assert will never fire.

推荐答案

是的,每个lambda表达式都会产生一个唯一的类型([expr.prim.lambda]/3):

Yes, each lambda expression produces a unique type ([expr.prim.lambda]/3):

lambda表达式的类型(这也是闭包对象的类型)是唯一,未命名的ununion类类型(称为闭包类型),其属性如下所述.

The type of the lambda-expression (which is also the type of the closure object) is a unique, unnamed nonunion class type — called the closure type — whose properties are described below.

[已添加重点]

这篇关于Lambda是否有不同类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆