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

Why non-mutable lambda captures can be moved?

AFAIK 非可变 lambda 将变量捕获为常量。这让我想知道为什么他们还能被感动?

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

AFAIK non-mutable lambdas capture variables as const.

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

与以下内容没有区别:

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

  void operator() const {p->reset();}
};