http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0644r1.html says
There are two ways that you can forward a variable: you can use std::forward or you can use static_cast directly (as this proposal's forwarding operator does):
template <class X, class Y> decltype(auto) foo(X&& x, Y&& y) { return std::forward<X>(x)(std::forward<Y>(y)); // with std::forward return static_cast<X&&>(x)(static_cast<Y&&>(y)); // with static_cast, exactly equivalent }
Does the "exactly equivalent" apply because X and Y are template parameters and so X&& and Y&& are forwarding references? Or for some other reason?
I assume it doesn't always apply because if it did
- I would expect
std::forward's documentation to say so, asstd::move's does; - There would be no reason for the 14% compilation speedup from replacing one with another.
My current best guess is that:
std::forwarddoesn't compile in some casesstatic_castdoes;- But not vice versa: if
std::forwardcompiles, so doesstatic_cast; - If it compiles, both have the same result.
But I am far from confident it is correct.