c++ - What is the advantage of a move constructor over a copy constructor that takes a bool that says whether to copy or move? -
why need move constructor/assignment operator in c++ when can this:
foo(const foo& x, bool copy = false) { if (copy) { // copy } else { // move } }
or missing something?
move constructors implicitly written (unless block it).
move constructors called automatically in contexts, if have code written before existed.
move types can exist move constructors, , block copy-actions error @ compile time.
marking 'please move this' not require 2nd parameter, making perfect forwarding work. perfect forwarding works rvalues. (perfect forwarding imperfect, btw)
move assignment won't work well pattern.
the rvalue ref useful in contexts outside of move/assign.
honestly, comparing c++11 move , rvalue refs proposal asking why telsa better tricycle broken wheel. broken trike cheaper, grant it.
Comments
Post a Comment