Lambda Expressions
Lambda Expressions
本文关键字:Expressions Lambda 更新时间:2023-10-16
ISO草案n3290第5.1.2节第19点:
与关联的闭包类型lambda表达式已删除(8.4.3)默认构造函数和已删除副本分配运算符。它具有隐式声明的副本构造函数(12.8),并且可能具有隐式声明的move构造函数(12.8).[注:复制/移动构造函数是在中隐式定义的与任何其他隐含方式相同声明的复制/移动构造函数将可以隐式定义--尾注]
谁能请。。。。讲一些例子来理解这一点?
是否有任何机会/方法来检查闭包对象(类型)?
与lambda表达式关联的闭包类型有一个已删除的(8.4.3)默认构造函数
int main() {
auto closure = [](){};
typedef decltype(closure) ClosureType;
ClosureType closure2; // <-- not allowed
return 0;
}
以及一个已删除的拷贝分配运算符。它有一个隐式声明的复制构造函数(12.8),也可能有一个隐含声明的移动构造函数(12.8)
#include <utility>
int main() {
auto closure = [](){};
typedef decltype(closure) ClosureType;
ClosureType closure2 = closure; // <-- copy constructor
ClosureType closure3 = std::move(closure); // <-- move constructor
closure2 = closure3; // <-- copy assignment (not allowed)
return 0;
}
struct LambdaExample{
// deleted operations = not allowed
LambdaExample() = delete;
LambdaExample& operator=(LambdaExample const&) = delete;
// generated by the compiler:
LambdaExample(LambdaExample const& other);
LambdaExample(LambdaExample&& other);
// anything else a lambda needs
};
对于第二个问题,如果你的意思是可以研究实现,那么不可能。它是由编译器动态创建的。如果你想得到lambda的类型,请确定:
auto l = [](){};
typedef decltype(l) closure_type;
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 可组合的lambda/std::函数与std::可选
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何建立使用模板函数的lambda函数的尾部返回类型
- 如何将lambda作为模板类的成员函数参数
- C++从其他 constexpr 创建 lambda 不能按顺序执行 Constexpr
- 在 lambda 捕获中声明的变量的类型推导
- 我可以将调用类的"this"传递给 lambda 函数吗?
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- 模板函数指针和lambda
- 两组使用lambda函数的大括号
- 使lambda不可复制/不可移动
- FLTK:按下哪个按钮 - 将数字传递给按钮的回调 (lambda)
- 尝试将lambda函数放在队列中时出现一般分配器错误(可能是与unique_ptr有关的错误)
- 将带有unique_ptr的可变 lambda 传递给 const&std::function
- AWS Lambda C++运行时权限被拒绝
- 捕获lambda中的std::数组
- 这 4 个 lambda 表达式之间有什么区别?
- 在实现文件中使用头文件的通用 lambda
- Lambda Expressions