Reference collapsing Rules, Universal Reference and the implementation of Std::forward () and Std::move ()

Source: Internet
Author: User

For reference collapsing, you can see this link. (It also speaks of the implementation of Std::forward () and Std::move ())

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

It is important to note that in the case of Auto-type deduction and Template-type deduction, there will be reference-stripping: (from Scott Meyers)

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

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

         int x;         ...         int&& r1 = ten;                   R1 ' s type is int&&         int& r2 = x;                     R2 ' s type is int&

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

         f (R1);         f (R2);

The deduced type for both and is r1 r2 int& . Why? First the reference parts of r1 ' s r2 and ' s types is stripped off (yielding int in both cases), then, because each is a lvalue, each are treated as int& during type deduction for the Universal reference parameter 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::move ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.