Boost.X3:不使用std :: optional <std :: string>编译

时间:2018-01-22 06:38:00

标签: boost-spirit-x3

当我对std::optional<std::string>规则的值使用-lexeme[+alpha]时,以下解析器无法编译:属性管理中存在中断。

如果我使用std::string代替int作为基本类型,语法工作正常,如果我使用两次std::string(即没有std::optional),它也可以正常工作。但是,它也不适用于boost::optional。在真正的语法中,缺少字符串和空字符串之间存在差异:我想要使用std :: optional(或其Boost前身)。

full example is available on Coliru,但这里是相关位:

struct pair_t
{
  std::string first;
  std::optional<std::string> second;
};

BOOST_FUSION_ADAPT_STRUCT(pair_t, first, second)

const auto pair_rule = lexeme[+alpha] >> -lexeme[+alpha] >> eoi;

for (std::string i: {"ab", "ab cd"})
  {
    auto res = pair_t{};
    auto first = i.cbegin();
    auto last = i.cend();
    auto r = x3::phrase_parse(first, last, pair_rule, space, res);
    if (r && first == last)
      std::cout << i << ": " << res << '\n';
    else
      std::cout << i << ": failed\n";
  }

我的编译器报告:

clang++-mp-5.0 -std=c++17   -isystem /opt/local/include/ x3-optional.cc && ./a.out 
In file included from x3-optional.cc:8:
In file included from /opt/local/include/boost/spirit/home/x3.hpp:14:
In file included from /opt/local/include/boost/spirit/home/x3/auxiliary.hpp:11:
In file included from /opt/local/include/boost/spirit/home/x3/auxiliary/any_parser.hpp:17:
/opt/local/include/boost/spirit/home/x3/support/traits/move_to.hpp:180:9: error: no matching function
      for call to 'move_to'
        detail::move_to(std::move(src), dest
        ^~~~~~~~~~~~~~~
/opt/local/include/boost/spirit/home/x3/char/char_parser.hpp:31:29: note: in instantiation of
      function template specialization 'boost::spirit::x3::traits::move_to<const char &,
      std::__1::basic_string<char> >' requested here
                x3::traits::move_to(*first, attr);
                            ^

0 个答案:

没有答案