是否可以将项目移出std :: set? [英] Is it possible to move an item out of a std::set?

查看:43
本文介绍了是否可以将项目移出std :: set?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个仅允许仅移动语义的对象-是否可以从集合中移动项目?我似乎找不到解决方法。

If I have an object that only allows move-only semantics - is it possible to move items from a set? I can't seem to find a way to do this.

推荐答案

不,这不可能。无法获得对集合中的元素的非常量访问,并且移动需要非常量引用。允许非常量访问将使其很容易打破 set 的不变式。

No, it is not possible. There is no way to get non-const access to elements in a set, and move requires non-const references. Allowing non-const access would make it trivially easy to break the invariants for set.

这篇关于是否可以将项目移出std :: set?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆