C++ 为什么可以移动不可变的lambda捕获?

C++ 为什么可以移动不可变的lambda捕获?,c++,lambda,c++14,move-semantics,C++,Lambda,C++14,Move Semantics,AFAIK不可变lambdas将变量捕获为常量。这让我想知道为什么他们还能被移动 auto p = std::make_unique<int>(0); auto f = [p = std::move(p)](){ p->reset(); }; // Error, p is const auto f2 = std::move(f); // OK, the pointer stored inside lambda is moved autop=std::使_唯一(0); 自动f=

AFAIK不可变lambdas将变量捕获为常量。这让我想知道为什么他们还能被移动

auto p = std::make_unique<int>(0);
auto f = [p = std::move(p)](){ p->reset(); }; // Error, p is const
auto f2 = std::move(f); // OK, the pointer stored inside lambda is moved
autop=std::使_唯一(0);
自动f=[p=std::move(p)](){p->reset();};//错误,p是常数
自动f2=标准::移动(f);//好的,存储在lambda中的指针被移动
AFAIK不可变lambdas将变量捕获为常量

不,他们没有。它们的
operator()
重载是
const
。实际的成员变量不是

这与:

class A
{
  unique_ptr<int> p
public:
  //Insert constructors here.

  void operator() const {p->reset();}
};
A类
{
唯一的
公众:
//在这里插入构造函数。
void运算符()常量{p->reset();}
};