c++ - Why forwarding reference does not deduce to rvalue reference in case of rvalue? -
i understand that, given expression initializing forwarding/universal reference,lvalues deduced of type t& , rvalues of type t (and not t&&).
thus,to allow rvalues, 1 need write
template<class t, enable_if<not_<is_lvalue_reference<t> >,otherconds... > = yes> void foo(t&& x) {}
and not,
template<class t, enable_if<is_rvalue_reference<t>,otherconds... > = yes> void foo(t&& x) {}
my question , why forwarding references, rvalues deduced of type t
, not t&&
? guess, if deduced t&& same referencing collapsing rule works t&& &&
same t&&
.
because @ time, deducing rvalue a
arguments a&&
instead of a
seen unnecessary complication , departure normal rules of deduction:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1385.htm
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1377.htm
we didn't know if 1 exception of deduction rules (for lvalue a
case), , never occurred dare ask 2 exceptions. so, benefit have had have been: makes impossible, possible.
after all, without single special deduction rule lvalue case, perfect forwarding impossible, n1385 aptly demonstrated.
even today's hindsight, adding special deduction rule client can avoid having negate template constraint, not seem high benefit/cost ratio. compared benefit/cost ratio shooting in 2002.
Comments
Post a Comment