boost :: variant单个存储保证 [英] boost::variant single storage guarantee

查看:176
本文介绍了boost :: variant单个存储保证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是确保所有变体类型的单一储存空间:根据'永不为空'保证从Boost :: variant ,我们需要重写
boost :: has_nothrow_copy 为每个有界类型。但稍后
文档提到了一些关于'boost :: blank',如果
类型是bound,variant将设置该值,而不是尝试不要
默认复制构造函数。

My goal is to guarantee single storage on all my variant types: according to 'never empty' guarantee from Boost::variant, we need to override boost::has_nothrow_copy for each bounded type. But a bit later the documentation mentions something about 'boost::blank' and if that type is bound, variant will set that value rather than try to nothrow default copy constructors.

什么不清楚是如果在有界类型列表
中添加boost :: blank将避免要求

what is not clear is if adding boost::blank in the bounded type list will avoid the requirement of overriding/specializing has_nothrow_copy with the other types?

推荐答案

p>我相信很清楚。以下是boost文档中的相关部分:

I believe that is made clear. Here is the relevant section from the boost documentation:


因此,variant设计为启用以下优化
一旦满足以下条件满足其有界类型:

Accordingly, variant is designed to enable the following optimizations once the following criteria on its bounded types are met:

对于不是可拷贝构造的每个有界类型T(作为由boost :: has_nothrow_copy指示的
),库变体
将只使用单个存储和T的就地构造。

For each bounded type T that is nothrow copy-constructible (as indicated by boost::has_nothrow_copy), the library guarantees variant will use only single storage and in-place construction for T.

如果任何
有界类型不是默认可构造的
boost :: has_nothrow_constructor),库保证变体将
只使用单个存储和就地构造为变量中的每个有界的
类型。然而,请注意,在赋值
失败的情况下,在左侧操作数中默认构造一个未指定的nothrow默认可构造的有界类型
,以便
保留never - 空保证。

If any bounded type is nothrow default-constructible (as indicated by boost::has_nothrow_constructor), the library guarantees variant will use only single storage and in-place construction for every bounded type in the variant. Note, however, that in the event of assignment failure, an unspecified nothrow default-constructible bounded type will be default-constructed in the left-hand side operand so as to preserve the never-empty guarantee.

由于 boost :: blank ishrow默认构造,第二条适用。它听起来像Boost有特殊的这种特殊类型被选择赞成所有其他,所以,而不是它是未指定的默认可构造类型将实例化类型保证 boost ::空白(如果是选项)。

Since boost::blank is nothrow default constructible, the second clause applies. And it sounds like Boost has special-cased this particular type to be chosen in favor of all others, so that instead of it being unspecified which default constructible type will be instantiated the type is guaranteed to be boost::blank if that's an option.

这篇关于boost :: variant单个存储保证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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