For template functions I use perfect forwarding like this:
template<typename T>
void f (T && v)
{
g (std::forward<T> (v));
}
How do I perfect forward auto &&
parameters in C++14
lambda expressions?
auto f = [] (auto && v)
{
g (std::forward<??> (v));
};
(Tried to google for it but didn't get any good hits on the keywords I picked)
Yes, they can be perfect-forwarded by means of decltype()
specifier:
auto f = [](auto&& v)
{
g(std::forward<decltype(v)>(v));
// ~~~~~~~~~~^
};
DEMO
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