Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move string into vector

Is there a way to move the content from a std::string into a std::vector? I think with now having rvalue-references in the language this operation would be very useful sometimes.

like image 712
cooky451 Avatar asked Oct 09 '22 06:10

cooky451


1 Answers

It is theoretically possible to move from one object type to another. However, those object types have to be designed to allow this. vector and string are not.

A good clue that an object allows it would be if std::vector has a constructor that takes a std::string&&. It has no such constructor. Also, vector would have to be a friend of string to get at its internals.

like image 63
Nicol Bolas Avatar answered Oct 12 '22 11:10

Nicol Bolas