-2

According to this assign doesn't have a r-value overload. The kind of function signature I was expecting is:

basic_string::assign(basic_string::basic_string &&param);

I checked the implementation for MSVC-2014 and CGI's implementation which do not provide this overload. The obvious advantage of this would be in cases like

string final; 
while(true){
    string tmp;
    // do some operation on tmp
    if (ConditionSatisfied){
       final.assign(move(tmp));
       break;
    } 
}    
// do further operations on final

Is it because the use cases of this would be rare? Or is there is any design flaw to include the overload.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
bashrc
  • 4,725
  • 1
  • 22
  • 49

1 Answers1

1

The same very page you linked does show the overload you're looking for:

basic_string& assign( basic_string&& str );

4) Replaces the contents with those of str using move semantics. str is in undefined state after the operation.

Second, your claim that it's not implemented in MSVC (as of 2013) is dubious, considering that it's documented on MSDN.

basic_string(
    basic_string&& _Right
);

There is no Visual Studio 2014, there is however "14" CTP, which isn't meant for production environments. Visual Studio 2015 is version 14.0. The actual compiler number is 19.00.

user5434961
  • 281
  • 1
  • 4