boost::spirit 指针属性是否用 nullptr 初始化?
Are boost::spirit pointer attributes initialized with nullptr?
我想我在某处的调试器中看到某个指针类型的 boost::spirit
属性被设置为 nullptr
,但我没有那样做。这只是巧合还是 boost::spirit
实际上负责初始化指针类型属性?
目前,当我需要确定时,我会在规则的开头放置一个 eps [ _val = nullptr ]
,但最好知道,所以我可以省略它。
does boost::spirit actually take care of initializing pointer-type attributes?
有效,是的。
精灵使用make_attribute
。评论似乎表明这只会发生在语义动作上,但它实际上也在 rule
解析器中使用(但传递给子解析器表达式的内容可能会被转换)。
make_attribute
使用 boost::value_initialized
trait:
Constructing and initializing objects in a generic way is difficult in C++. The problem is that there are several different rules that apply for initialization. Depending on the type, the value of a newly constructed object can be zero-initialized (logically 0), default-constructed (using the default constructor), or indeterminate. When writing generic code, this problem must be addressed. The template value_initialized provides a solution with consistent syntax for value initialization of scalar, union and class types. Moreover, value_initialized offers a workaround to various compiler issues regarding value-initialization. Furthermore, a const object, initialized_value is provided, to avoid repeating the type name when retrieving the value from a value_initialized object.
因此,除非您的代码中有任何自定义的特化,否则默认行为会提供值初始化。
我想我在某处的调试器中看到某个指针类型的 boost::spirit
属性被设置为 nullptr
,但我没有那样做。这只是巧合还是 boost::spirit
实际上负责初始化指针类型属性?
目前,当我需要确定时,我会在规则的开头放置一个 eps [ _val = nullptr ]
,但最好知道,所以我可以省略它。
does boost::spirit actually take care of initializing pointer-type attributes?
有效,是的。
精灵使用make_attribute
。评论似乎表明这只会发生在语义动作上,但它实际上也在 rule
解析器中使用(但传递给子解析器表达式的内容可能会被转换)。
make_attribute
使用 boost::value_initialized
trait:
Constructing and initializing objects in a generic way is difficult in C++. The problem is that there are several different rules that apply for initialization. Depending on the type, the value of a newly constructed object can be zero-initialized (logically 0), default-constructed (using the default constructor), or indeterminate. When writing generic code, this problem must be addressed. The template value_initialized provides a solution with consistent syntax for value initialization of scalar, union and class types. Moreover, value_initialized offers a workaround to various compiler issues regarding value-initialization. Furthermore, a const object, initialized_value is provided, to avoid repeating the type name when retrieving the value from a value_initialized object.
因此,除非您的代码中有任何自定义的特化,否则默认行为会提供值初始化。