MCVE : http://coliru.stacked-crooked.com/a/ef442eca9b74c8f1
I want to move parameter in lambda function by following a tutorial in Move capture in lambda.
#include <string>
#include <iostream>
#include <functional>
class B{};
void f(B&& b){}
int main(){
B b;
auto func_lambda=[b{std::move(b)}](){
//f(std::move(b)); // also fails
f(b); // also fails
};
//: std::function<void()> func_cache=func_lambda();
// will be stored and called after 'b' is out of scope
}
I got this error :-
main.cpp: In lambda function: main.cpp:10:11: error: cannot bind rvalue reference of type 'B&&' to lvalue of type 'const B' main.cpp:5:12: note: initializing argument 1 of 'void f(B&&)'
I have also tried [b=std::move(b)]
but fail (link= Passing a lambda with moved capture to function).
How to move the parameter correctly?