Does [x = std::forward<decltype(x)>]
behave like you expect?
capturing perfectly-forwarded objects in lambdas
by Vittorio Romeo
From the article:
Perfect forwarding and forwarding references allow developers to write generic template functions that retain the lvalueness/rvalueness of passed arguments [...] Let's try to use auto&&, std::forward and C++14's generalized lambda capture syntax to implement our desired semantics. [...] What we really want to do is:
- Capture by copy if a is an rvalue reference.
- Capture by reference if a is an lvalue reference.
[...]
Add a Comment
Comments are closed.