精神 X3 无法传播可选<vector>类型的属性
spirit x3 cannot propagate attributes of type optional<vector>
一个简单的解析器,就像在Coliru上一样。解析器-(+x3::alpha)
应该能够像 Qi 一样传播类型 boost::optional<std::string>
的属性。但它不编译。
std::string const input = "abc";
boost::optional<std::string> attr;
if(x3::parse(boost::begin(input),boost::end(input),
-(+x3::alpha),
attr)) {
std::cout<<"match!"<<std::endl;
}
else {
std::cout<<"NOT match!"<<std::endl;
}
我不认为规范性声明"应该能够 [...]就像齐"砍柴一样。X3不是Qi的进化,原因非常好(比如这个(。
一个经常重复出现的模式是在更复杂的传播方案中需要类型提示。丑陋的冗长方式可能是这样的:
-(x3::rule<struct _, std::string> {} = +x3::alpha),
住在科里鲁
或者你可以使用我之前描述的技巧:
namespace {
template <typename T>
struct as_type {
template <typename Expr>
auto operator[](Expr&& expr) const {
return x3::rule<struct _, T>{"as"} = x3::as_parser(std::forward<Expr>(expr));
}
};
template <typename T> static const as_type<T> as = {};
}
住在科里鲁
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中用vector填充一个简单的动态数组
- vector.resize()中的分配错误
- 使用std::vector的OpenCL矩阵乘法
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 在某些循环内使用vector.push_back时出现分段错误
- 当vector是tje全局变量时,c++中vector的内存管理
- std::vector的包装器,使数组的结构看起来像结构的数组
- 为什么(-1)%vector::size()总是返回0
- 在C++中将类(带有Vector成员)保存为二进制文件
- 编译器如何区分std::vector的构造函数
- 将 int 数组转换为 std::vector<int*>
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- EASTL矢量<向量<int>>连续的
- 在std::vector上存储带有模板的类实例
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- 使用 std::vector<boost::shared_ptr<Base_Class>> 或 boost::p tr_vector 的性能注意事项是什么<Base>
- 将矩阵"shared_ptr<vector<vector>sp"的行"(*sp)[i]"<T>传递给接受"shared_ptr<vector<T>>
- 如何获取std::vector<DMatch>