Use mutable.
auto bar = [=] () mutable -> bool ....
Without mutable you are declaring the operator () of the lambda object const.
More Related Contents:
- Declaring lambda with int type not working [closed]
- C++ lambda with captures as a function pointer
- Move capture in lambda
- Passing capturing lambda as function pointer
- const vs constexpr on variables
- Does const mean thread-safe in C++11?
- What is the type of lambda when deduced with “auto” in C++11?
- How is std::function implemented?
- Why can lambdas be better optimized by the compiler than plain functions?
- Bind Vs Lambda?
- const& , & and && specifiers for member functions in C++
- C++11 lambda implementation and memory model
- Can lambda functions be templated?
- Error: variable “cannot be implicitly captured because no default capture mode has been specified”
- Lambda capture and parameter with same name – who shadows the other? (clang vs gcc)
- why do lambda functions in c++11 not have function types?
- Why can’t I create a vector of lambdas (of the same type) in C++11?
- Why can’t I capture this by-reference (‘&this’) in lambda?
- Lambda expressions as class template parameters
- How to immediately invoke a C++ lambda?
- constexpr vs. static const: Which one to prefer?
- Do c++11 lambdas capture variables they don’t use?
- How do static variables in lambda function objects work?
- Should I still return const objects in C++11? [duplicate]
- Lambdas and capture by reference local variables : Accessing after the scope
- Passing a lambda into a function template
- What is the purpose of std::function and how to use it?
- In lambda functions syntax, what purpose does a ‘capture list’ serve?
- Lambdas and std::function
- Explicit Return Type of Lambda