> The whole point of move constructors are observable side-effects.
> The whole point of move constructors are observable side-effects. Nonsense. > Furthermore move constructors often have to throw an exception due to the fact that moving an object should leave the original object in a valid state. Whether or not move constructors should leave objects in a 'valid state', whatever you mean by that, is hotly contested. Personally I'm of the opinion the only valid operations on a moved-from object should be to move-assign to it (otherwise literally every mutating algorithm is broken) and, obviously, to destroy it. > Often times leaving the original object in a valid state requires involves performing an operation that could potentially fail. Which is exactly why I'm of the above opinion. Making move non-throwing is more or less always trivial and cheap, whereas doing so while ensuring a moved-from object has a valid and useful state, where all class invariants have been maintained, can be expensive. You should definitely favour a noexcept move constructor that results in an unspecified state over a implementing a throwing move. Just don't do it. If your move constructor throws then doing anything useful with your class becomes very expensive (because classes like std::vector will start copying your objects to move them around). > In the case of std::map and std::list, a conforming implementation may have to allocate memory in order for the original object to be in a valid state. This is just wrong. Moving a std::list will not throw provided the associated memory allocator is noexcept move constructible (and std::allocator is). The same is true of std::map.
Posted by nly on Jul 20, 2015, 8:31 PM
Tags
Related issues
- Fake websites pretending to be legitimate websites in order to steal your passwords was considered a HUGE problem.
- 3.5 Flash was always too expensive for a "flash" model.
- I don't think the realistic alternative here was “hire a team for a month and get a better semantic conversion” For a rewrite of this si...
- I was hosting on a PC at home like 10 years ago.
- I live in walking distance of all these things, and the farthest I’ve gotten my kid to do things alone is to walk to and from school (a w...
- It was a long time ago, so I don't remember.
Raise real-world problems, find people facing the same issue, and discuss solutions.5,500 issues0 comments
pricing (E-commerce)
Fake websites pretending to be legitimate websites in order to steal your passwords was considered a HUGE problem.
3.5 Flash was always too expensive for a "flash" model.
I don't think the realistic alternative here was “hire a team for a month and get a better semantic conversion” For a rewrite of this si...
I was hosting on a PC at home like 10 years ago.
I live in walking distance of all these things, and the farthest I’ve gotten my kid to do things alone is to walk to and from school (a w...
It was a long time ago, so I don't remember.
I still like to buy my cheap and esoteric Chinese stuff from Amazon.
My local area used to be great to find old used woodworking tools for cheap.
> The whole point of move constructors are observable side-effects.
> The whole point of move constructors are observable side-effects. Nonsense. > Furthermore move constructors often have to throw an exception due to the fact that moving an object should leave the original object in a valid state. Whether or not move constructors should leave objects in a 'valid state', whatever you mean by that, is hotly contested. Personally I'm of the opinion the only valid operations on a moved-from object should be to move-assign to it (otherwise literally every mutating algorithm is broken) and, obviously, to destroy it. > Often times leaving the original object in a valid state requires involves performing an operation that could potentially fail. Which is exactly why I'm of the above opinion. Making move non-throwing is more or less always trivial and cheap, whereas doing so while ensuring a moved-from object has a valid and useful state, where all class invariants have been maintained, can be expensive. You should definitely favour a noexcept move constructor that results in an unspecified state over a implementing a throwing move. Just don't do it. If your move constructor throws then doing anything useful with your class becomes very expensive (because classes like std::vector will start copying your objects to move them around). > In the case of std::map and std::list, a conforming implementation may have to allocate memory in order for the original object to be in a valid state. This is just wrong. Moving a std::list will not throw provided the associated memory allocator is noexcept move constructible (and std::allocator is). The same is true of std::map.
Comments (0)
No comments yet. Start the discussion.