C++ 非默认构造boost::proto终端

C++ 非默认构造boost::proto终端,c++,boost,boost-proto,C++,Boost,Boost Proto,我试图使用boost::proto定义一个非常有限的解析器组合器库,并想知道是否可以通过任何方式定义一个非默认构造的proto终端 我有一个这样的结构: struct symbol { symbol(const string &str): str_(str) {} bool operator()(const string &str) const { return (str == str_); } string str_; }; proto:

我试图使用boost::proto定义一个非常有限的解析器组合器库,并想知道是否可以通过任何方式定义一个非默认构造的proto终端

我有一个这样的结构:

struct symbol
{
   symbol(const string &str): str_(str) {}
   bool operator()(const string &str) const {
      return (str == str_);
   }

   string str_;
};
proto::terminal<symbol>::type sym;
我想在proto表达式中用作boost proto终端。我能够在BOOST_PROTO_DEFINE_操作符的帮助下使其工作,但我发现经常需要将其包装在PROTO::lit的PROTO表达式中有些不方便:

match(symbol("abc") >> (proto::lit(symbol("xyz")) | symbol("klm")))
我想知道我是否可以创建一个这样的原型终端:

struct symbol
{
   symbol(const string &str): str_(str) {}
   bool operator()(const string &str) const {
      return (str == str_);
   }

   string str_;
};
proto::terminal<symbol>::type sym;
这将以某种方式获得一个字符串参数,并将其传递给symbol的构造函数

注意:我知道Spirit,但我的编译器不太支持它

您可以将名称sym设置为返回终端的函数:

proto::terminal<symbol>::type sym(std::string const& s)
{ return { symbol(s) }; }
与lit非常相似的是,函数模板将其参数转换为终端。

您可以将名称sym设置为返回终端的函数:

proto::terminal<symbol>::type sym(std::string const& s)
{ return { symbol(s) }; }
与lit非常相似的是,函数模板将其参数转换为终端