4 ms·
It's very useful when you want to pass something by reference into a function that takes a varadic template parameters and uses perfect forwarding, i.e. https:/
by clappski 7y ago
It's very useful when you want to pass something by reference into a function that takes a varadic template parameters and uses perfect forwarding, i.e. https://godbolt.org/z/xlmwFw https://godbolt.org/z/xlmwFw
template <typename... Args> void foo( Args&&... args ) {
whiz( std::forward<Args>( args )... );
}
...
int i = 5;
double k = 2.3;
foo( std::ref( i ), k ); // take i by ref, k by value
I've also seen it a lot with std::thread, and basically anything else that takes a callable/functor where the developer chose not to use lambda's with reference captures.
Would agree that it isn't a major language feature, but I would expect competent developers to at least know about it and why you would want to/have to use it (if they had worked with a compiler that had >=C++11 support).