Lambda表达式

use*_*747 17 c++ lambda c++11

从ISO草案n3290第5.1.2节第19点开始:

与lambda表达式关联的闭包类型具有已删除(8.4.3)的默认构造函数和已删除的复制赋值运算符.它有一个隐式声明的复制构造函数(12.8),并且可能有一个隐式声明的移动构造函数(12.8).[注意:复制/移动构造函数的隐式定义方式与隐式定义任何其他隐式声明的复制/移动构造函数的方式相同. - 尾注]

可以请任何人......告诉一些这方面的例子可以理解吗?

有没有机会/方法来检查Closure对象(类型)?

ken*_*ytm 30

与lambda表达式关联的闭包类型具有已删除(8.4.3)的默认构造函数

int main() {
    auto closure = [](){};
    typedef decltype(closure) ClosureType;

    ClosureType closure2;   // <-- not allowed

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

和删除的复制赋值运算符.它有一个隐式声明的复制构造函数(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;
}
Run Code Online (Sandbox Code Playgroud)