decltype-auto

Correctly propagating a `decltype(auto)` variable from a function

孤街浪徒 提交于 2019-12-20 16:46:40
问题 (This is a follow-up from "Are there any realistic use cases for `decltype(auto)` variables?" ) Consider the following scenario - I want to pass a function f to another function invoke_log_return which will: Invoke f ; Print something to stdout ; Return the result of f , avoiding unnecessary copies/moves and allowing copy elision. Note that, if f throws, nothing should be printed to stdout . This is what I have so far: template <typename F> decltype(auto) invoke_log_return(F&& f) { decltype

Are there any realistic use cases for `decltype(auto)` variables?

假如想象 提交于 2019-12-03 04:40:43
问题 Both from my personal experience and from consulting answers to questions like What are some uses of decltype(auto)? I can find plenty of valuable use cases for decltype(auto) as a function return type placeholder . However, I am seriously struggling to think of any valid (i.e. useful, realistic, valuable) use case for decltype(auto) variables. The only possibility that comes to mind is to store the result of a function returning decltype(auto) for later propagation, but auto&& could be used

Are there any realistic use cases for `decltype(auto)` variables?

房东的猫 提交于 2019-12-02 17:08:00
Both from my personal experience and from consulting answers to questions like What are some uses of decltype(auto)? I can find plenty of valuable use cases for decltype(auto) as a function return type placeholder . However, I am seriously struggling to think of any valid (i.e. useful, realistic, valuable) use case for decltype(auto) variables. The only possibility that comes to mind is to store the result of a function returning decltype(auto) for later propagation, but auto&& could be used there as well and it would be simpler. I've even searched throughout all my projects and experiments,