加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 为什么basic_stringbuf和basic_filebuf移动构造函数具有实

发布时间:2020-12-16 07:33:10 所属栏目:百科 来源:网络整理
导读:从我的C标准副本[§27.8.2.1p4]: basic_stringbuf(basic_stringbuf rhs); Effects: Move constructs from the rvalue rhs. It is implementation-defined whether the sequence pointers in *this (eback(),gptr(),egptr(),pbase(),pptr(),epptr()) obtain
从我的C标准副本[§27.8.2.1p4]:

basic_stringbuf(basic_stringbuf&& rhs);

Effects: Move constructs from the rvalue rhs. It is
implementation-defined whether the sequence pointers in *this
(eback(),gptr(),egptr(),pbase(),pptr(),epptr()) obtain the values
which rhs had
. Whether they do or not,*this and rhs reference
separate buffers (if any at all) after the construction. The openmode,
locale and any other state of rhs is also copied.

类似的句子也用于basic_filebuf(basic_filebuf&& rhs);.

我想知道为什么这是实现定义?您是否有理由不想复制指针?

解决方法

有两种明显的实现技术可以处理标准流缓冲区中的缓冲区:

>您可以将缓冲区嵌入到对象中,为对象创建更大的占用空间,但避免为小字符串或文件分配内存.
>您可以指向堆上分配的缓冲区,并以内存分配为代价处理可能较大的缓冲区.

根据缓冲区所在位置的实现选择,您需要一组新的指针值,或者您希望按原样继承指针.这两种策略都不是“更好”,我可以想象结合策略的变化.因此,而不是做出选择实现可以选择.如果你的问题是为什么实施应该[忘记]记录它做出的选择:这显然超出了我.我个人的猜测是,假设“实施定义”阶段将提供选择的自由,并且忽略了影响是实施需要陈述其选择(因为有关于引用的辩论:1.3.10) [defns.impl.defined] – 奇怪的是没有段落编号).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读