Are there any use cases for a class which is copyable but not movable?

前端 未结 5 1425
名媛妹妹
名媛妹妹 2020-12-18 20:22

After reading this recent question by @Mehrdad on which classes should be made non-movable and therefore non-copyable, I starting wondering if there are use

5条回答
  •  囚心锁ツ
    2020-12-18 20:46

    I currently know of no use cases for a deleted move constructor/assignment. If done carelessly it will needlessly prevent a type from being returned from a factory function or put into a std::vector.

    However deleted move members are legal nevertheless just in case someone might find a use for them. As an analogy, I knew of no use for const&& for years. People asked me if we shouldn't just outlaw it. But eventually a few use cases did show up after we got sufficient experience with the feature. The same might also happen with deleted move members, but to the best of my knowledge hasn't yet.

提交回复
热议问题