Are move semantics incomplete?

前端 未结 3 1141
暗喜
暗喜 2021-01-02 06:59

Move semantics replace copy semantics in situations where copying is inefficient. Copy semantics deals fully with copyable objects, including const objects.

Already,

3条回答
  •  佛祖请我去吃肉
    2021-01-02 07:39

    Sorry, but the premise is flawed.

    An unordered_set doesn't actually hold const objects. It's just not giving you write access to the contained elements. That's a property of the accessors only.

    It would be possible to add an key erase(iterator) function which just moves the element out to a temporary. I'm not sure why you'd want a key&& there.

    As for const MyClass&& ~MyClass() const, that doesn't make sense for three reasons: dtors have neither return types nor CV classification, nor is overload resolution done for them.

提交回复
热议问题