提升精神:内置终端应该使用什么类型名称
boost spirit: What type names should be used for the built in terminals?
我正在重构我现有的一个类型系统(类型模型),它使用 spirit 进行字符串序列化。我正在使用类型特征的编译时建模结构。
template<>
type_traits<int4_type>
{
typedef boost::spirit::qi::int_parser<boost::int32_t> string_parser;
}
template<>
type_traits<string_type>
{
typedef boost::spirit::ascii::string string_parser;
}
在这个例子中,我展示了原始解析器,但我也希望加入规则。
int4 类型有效,但这是因为 (home/qi/numeric/int.hpp +27):
namespace tag
{
template <typename T, unsigned Radix, unsigned MinDigits
, int MaxDigits>
struct int_parser {};
}
namespace qi
{
///////////////////////////////////////////////////////////////////////
// This one is the class that the user can instantiate directly in
// order to create a customized int parser
template <typename T = int, unsigned Radix = 10, unsigned MinDigits = 1
, int MaxDigits = -1>
struct int_parser
: spirit::terminal<tag::int_parser<T, Radix, MinDigits, MaxDigits> >
{};
}
字符串 Typedef 不起作用,EPS 也不起作用。我无法弄清楚引用字符串解析器的原因。但是,在eps的情况下,它归结为:
#define BOOST_SPIRIT_TERMINAL(name)
namespace tag { struct name {}; }
typedef boost::proto::terminal<tag::name>::type name##_type;
name##_type const name = {{}};
inline void silence_unused_warnings__##name() { (void) name; }
/***/
这意味着我无法键入它,它是一个原型终端构造,或者说得不透明,一个 const 全局定义。
我的问题:如何键入定义规则,语法,原始解析器?
注意:我已经开始努力给我所有的"类型"一个封装规则的函子,然后使其成为类型特征。
我不确定它是否在所有情况下都有效,但我对 Skipper 所做的是使用 BOOST_TYPEOF :
typedef BOOST_TYPEOF(boost::spirit::ascii::space - (boost::spirit::qi::eol | boost::spirit::qi::eoi)) SkipperT;
所以你的例子将是
typedef BOOST_TYPEOF(boost::spirit::ascii::string) string_parser;
可能有一种更好/更优雅的方式,但它目前适用于我需要的。
相关文章:
- 静态自动 constexpr t = { "red" , "black" , "green" } 是什么类型;派生到?
- 这是什么类型的C++语法,我应该采取什么步骤来理解这一点
- 当你只使用 return 时,函数返回什么类型;在 c++ 中
- 这在C++是什么类型的错误?
- 如果在 C++ 构造函数中以错误的顺序初始化对象数据,会发生什么类型的错误
- 重载运算符返回什么类型的值(对于用户定义的类型):右值还是左值?
- int(int)& 或 int(int) const &是什么类型?
- 它>首先给出什么类型?
- ``n = 1u;'有什么类型
- 访问和存储/解析性std :: Chrono ::持续时间:: milliseconds(cpprest)时使用什么类型
- 二进制要找到什么类型的序列化
- 我如何找出3D容器的元素是什么类型
- C++ - 函数中的局部指针变量具有什么类型的存储持续时间以及它们存储在哪里?
- 将 lambda 作为模板参数传递:实际推导出什么类型
- 在 c 和 c++ 中,二维数组的元素是什么类型?
- 什么类型会使"std::has_unique_object_representations"返回 false?
- 这个 lambda 的参数是什么类型?
- 转换逻辑目标是什么类型
- 由值持有的成员的get函数应该具有什么类型
- C++中使用什么类型来定义数组大小