Reference Collapsing Rules, Universal Reference and the implementation of std::forward() and std::mo

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Reference Collapsing Rules, Universal Reference and the implementation of std::forward() and std::mo相关的知识,希望对你有一定的参考价值。

关于reference collapsing,可以看这个链接。(里面也讲了std::forward()和std::move()的实现)

                http://thbecker.net/articles/rvalue_references/section_08.html

需要注意的是,在做auto-type deduction和template-type deduction的时候,在会有reference-stripping 发生:(来自scott meyers)

Note that when doing reference collapsing, reference would be stripped first:

           Things get subtler when deducing the type for a variable that is itself a reference. In that case, the reference part of the type is ignored.  For example, given

         int x;

         ...

         int&& r1 = 10;                   // r1’s type is int&&

         int& r2 = x;                     // r2’s type is int&

           the type for both r1 and r2 is considered to be int in a call to the template f.  This reference-stripping behavior is independent of the rule that, during type deduction for universal references, lvalues are deduced to be of type T& and rvalues of type T, so given these calls,

         f(r1);

         f(r2);

          the deduced type for both r1 and r2 is int&. Why? First the reference parts of r1’s and r2’s types are stripped off (yielding int in both cases), then, because each is an lvalue, each is treated as int& during type deduction for the universal reference parameter in the call to f.( from:  "Nitty Gritty Detail" of    https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers )

以上是关于Reference Collapsing Rules, Universal Reference and the implementation of std::forward() and std::mo的主要内容,如果未能解决你的问题,请参考以下文章

Visual Studio 2017 Collapsing 也删除了未使用的使用

外边距塌陷 margin collapsing

odoo Reference 选择model 然后选择record

为啥 `white-space-collapsing` CSS3 属性的引入推迟到 CSS-text-4(可能是 `text-space-collapse`)?

CRM SFA Determine the Type of Claim Rule Template to Use

SpringCloud(Hoxton.SR3)基础篇:第五章Hystrix-request collapsing(请求合并)