cpp_weekly
cpp_weekly copied to clipboard
Do not disable the move and copy methods
Channel
C++ Weekly
Topics
It can have title like: "Do not disable the move and copy methods".
Context: I have used some C++ libraries that disable the move/copy methods for their structs while it is totally unnecessary. This has many disadvantages:
- I cannot store these structs inside std containers (like tuple)
- I cannot break my code into smaller functions, because I cannot return them in a tuple -> (I had to workaround this by using multiline macros instead of functions!!)
- ...
This feature should be only used for the core types like "unique_ptr`, but because C++ allows this for user-level types, some library authors do this in the name of optimization to prevent accidental copy/moves without knowing all the implications of it.
Length
5-10 min
I always disable (delete) copy/move ctors/assignments when I haven't implemented them yet or don't really plan to because I don't expect the object to be copied, to prevent accidental copies. Not sure if this is the best thing to do (maybe a static assertion yelling "TODO" would be better?)