Quantcast
Channel: User HolyBlackCat - Stack Overflow
Viewing all articles
Browse latest Browse all 1262

Answer by HolyBlackCat for C++ difference in forwarding references between template arguments and lambda's `auto` parameters

$
0
0

T will be &, const &, && or const && according to the value category

T is never deduced as an rvalue reference. It can be deduced as a non-reference though (for rvalue arguments), possibly const.

I don't know is if decltype(args) will resolve to the type "before" or "after" such computation

After, of course.

Which means when (the imaginary) T is non-reference, decltype receives T && instead. But std::forward treats T and T && in the same way, so your usage is ok.

Moreover, you don't even need forward and can just use decltype(args)(args) (a cast to the decltyped type), though some prefer to spell out the redundant std::forward for clarity.


Viewing all articles
Browse latest Browse all 1262

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>