gpt4 book ai didi

c++ - boost::spirit 指针属性是否用 nullptr 初始化?

转载 作者:行者123 更新时间:2023-11-30 03:21:08 24 4
gpt4 key购买 nike

我想我在某个调试器中看到某个指针类型的 boost::spirit 属性被设置为 nullptr,但我没有那样做。这只是巧合还是 boost::spirit 实际上负责初始化指针类型属性?

目前,当我需要确定时,我会在规则的开头放置一个 eps [ _val = nullptr ],但最好知道这样我就可以省略它。

最佳答案

does boost::spirit actually take care of initializing pointer-type attributes?

有效,是的。

Spirit 使用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.

因此,除非您的代码中有任何自定义的特化,否则默认行为会提供值初始化。

关于c++ - boost::spirit 指针属性是否用 nullptr 初始化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52303985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com