Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Taking the argument by && in std::vector push_back() and std::map operator[] [duplicate]

I found this in std::vector::push_back() implementation:

void push_back(_Ty&& _Val)
{
    // some code here       
}

and this in std::map operator[] implementation:

mapped_type& operator[](key_type&& _Keyval)
{
    // some code here   
}

Why _Val and _Keyval is taking by the reference-by-reference? How does the taking of the argument by reference-by-reference working? What are the benefits of this approach in comparison with the taking by reference?

P.S. This is NOT the logical "AND", I understand this clearly.

like image 780
Netherwire Avatar asked Nov 01 '22 13:11

Netherwire


1 Answers

This is a C++11 feature - rvalue references... Here's some more info

like image 196
Tom Avatar answered Nov 10 '22 01:11

Tom