vector<int> vec;
//a
auto foo = [&vec](){
//do something
};
//b
auto foo = [&v = vec](){
//do something
};
Do I understand it right that only difference between a and b is creation of alias "v" for "vec" in b case or is there more to it?
In this case there is no real difference. However, if you were to capture by value there would be a difference:
const std::vector<int> vec; // note const
auto foo = [vec]() mutable {
// can't change vec here since it is captured with cv-qualifiers
};
auto bar = [v = vec]() mutable {
// can change v here since it is captured by auto deduction rules
// (cv-qualifiers dropped)
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With