Why forwarding reference does not deduce to rvalue reference in case of rvalue?

后端 未结 1 1980
广开言路
广开言路 2021-01-12 12:33

I understand that, given an expression initializing a forwarding/universal reference,lvalues are deduced to be of type T& and rvalues of type T

相关标签:
1条回答
  • 2021-01-12 13:05

    Because at the time, deducing rvalue A arguments as A&& instead of A was seen as an unnecessary complication and departure from the 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 really didn't even know if we could get one exception of the deduction rules (for the lvalue A case), and it never even occurred to us that we would dare ask for two exceptions. To do so, the benefit would have had to have been: It makes what is impossible, possible.

    After all, without the single special deduction rule for the lvalue case, perfect forwarding is impossible, as N1385 so aptly demonstrated.

    Even with today's hindsight, adding another special deduction rule so that the client can avoid having to negate a template constraint, does not seem like a very high benefit/cost ratio. Especially compared to the benefit/cost ratio we were shooting for in 2002.

    0 讨论(0)
提交回复
热议问题