c++ - Should I move a temporary into a variable? -
if have existing non-trivial variable , want re-assign new contents declare on same line assignment, should utilize move semantics?
my question comes next scenario:
std::vector<string> existing = { ... }; int main(int argc, char *argv[]){ const char *bunch_of_strings = ... ; std::stringstream ss(bunch_of_string); existing = std::move(std::vector<std::string>(std::istream_iterator<std::string>(ss), {})); }
should doing this, compiler optimize if don't, or improve not to?
std::move
redundant there. purpose of move
treat variable temporary (more accurately, rvalue) when it's not (or might not be). if it's rvalue, moved if possible anyway.
c++ c++11 move-semantics c++14
No comments:
Post a Comment