No assignment of copy by value in lambda

c++, c++11, clang, lambda

Solution

Because the `operator()` of lambdas is `const` by default. You need to use the `mutable` keyword to make it non-const:

auto blub = [test]() mutable {
    test = std::make_shared<bool>(false);
};

Problem

Can someone explain to me why the following does not work (`test` is `const` inside of `blub`). Since `test` is copied by value I was assuming, I could set it since it is functor local. ``` #include <memory> int main() { std::shared_ptr<bool> test; auto blub = [test]() { test = std::make_shared<bool>(false); }; return 0; } ``` To make this working, first I have to introduce a new `shared_ptr`, assign `test` and then I can normally assign the other `shared_ptr`. BTW: I am using clang 3.1

Original source