0

我有一些使用 Boost Qi 和 Phoenix 来解析命令行参数的 C++ 代码。以下代码适用于 Boost 1.56。

namespace qi = boost::spirit::qi;
namespace phx = boost::phoenix;
using boost::spirit::repository::distinct;

int type;
unsigned pause, siteID;
bool testMode, log;
std::string filePath;

auto fileName = qi::lexeme[+qi::char_("0-9a-zA-Z_/.:")];
auto grammar = boost::proto::deep_copy(
    distinct(qi::alpha)["/pause="][phx::ref(type) = 0] >> qi::uint_[phx::ref(pause) = qi::_1] |
    distinct(qi::alpha)["/id="][phx::ref(type) = 1] >> qi::uint_[phx::ref(siteID) = qi::_1] |
    distinct(qi::alpha)["/testmode="][phx::ref(type) = 2] >> qi::uint_[phx::ref(testMode) = (qi::_1 != FALSE)] |
    distinct(qi::alpha)["/log="][phx::ref(type) = 3] >> qi::uint_[phx::ref(log) = (qi::_1 != FALSE)] |
    distinct(qi::alpha)["/ini="][phx::ref(type) = 4] >> fileName[phx::ref(filePath) = qi::_1]
);

最近我搬到了 Boost 1.71,但现在我得到了以下编译时错误,全部来自 boost.1.71.0.0\lib\native\include\boost\proto\transform\default.hpp,第 154 行:

Error C2955 'boost::type': use of class template requires template argument list
Error C2955 'boost::mpl::if_c': use of class template requires template argument list
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'T' (or there is no acceptable conversion)
Error C2672 'boost::proto::detail::check_reference': no matching overloaded function
Error C2238 unexpected token(s) preceding ';'
Error C2062 type 'unknown-type' unexpected
Error C2039 'type': is not a member of 'boost::proto::detail::default_assign<Grammar>::impl<Expr     &,State,Data>::nested_and_hidden_nested_result_type'
Error C2039 'type': is not a member of 'boost::proto::detail::default_assign<Grammar>::impl<Expr &,State,Data>::nested_result_type'

我已经解决了问题是代码fileName[phx::ref(filePath) = qi::_1]。当 _1 是子表达式的结果时,phx::ref 不能再分配 qi::_1 的值。

qi::uint_[phx::ref(pause) = qi::_1] \\ This is fine
fileName[phx::ref(filePath) = "test"] \\ This is fine
fileName[phx::ref(filePath) = qi::_1] \\ Compile error

我怎样才能解决这个问题?谢谢

4

0 回答 0