下面的代码来自于Boost.Spirit x3 documentation。它使用了一种我从未见过的有趣的C++语法,几乎不可能在不知道正确术语的情况下通过搜索查询进行描述。这是类的前向声明的速记吗?在C++标准中提到了这个特性吗?
namespace parser
{
using x3::eps;
using x3::lit;
using x3::_val;
using x3::_attr;
using ascii::char_;
auto set_zero = [&](auto& ctx){ _val(ctx) = 0; };
auto add1000 = [&](auto& ctx){ _val(ctx) += 1000; };
auto add = [&](auto& ctx){ _val(ctx) += _attr(ctx); };
// What is this? This is the very first use of the identifier `roman`.
x3::rule<class roman, unsigned> const roman = "roman";
// ^^^^^^^^^^^
auto const roman_def =
eps [set_zero]
>>
(
-(+lit('M') [add1000])
>> -hundreds [add]
>> -tens [add]
>> -ones [add]
)
;
BOOST_SPIRIT_DEFINE(roman);
}
using MyType = TaggedThing<struct UniqueTag>;
标签有助于将每个标签作为新类型,这对于将该类型别名为一行非常有用。在此处放置struct
是我的个人偏好,它也可以是class
、union
、enum
或enum class
(及其变体),就我所知。 - chris