The method insert() for std::list has 2 method signatures. One takes a const lvalue reference as so:
iterator insert( const_iterator pos, const T& value );
The other takes a rvalue reference as so:
iterator insert( const_iterator pos, T&& value );
- However I was wondering why the second method signature was even necessary? A const lvalue reference can bind to rvalues.
I am aware that it may be faster to move rvalues instead of copy them.
- However, how will the second method signature that takes a rvalue reference implement a move instruction on
valuethat differs from the first that takes a const lvalue reference?
The assignment operator on rvalues will simply call the move constructor while on an lvalue it will call the copy constructor. So simply using an assignment operator in the first function should suffice right?
Thank you