C++ Boost Spirit x3未编译

C++ Boost Spirit x3未编译,c++,boost,boost-spirit-x3,C++,Boost,Boost Spirit X3,我正在关注boost网站上的x3文档,并且我已经尝试使用后面的注释示例中解释的内容来扩展如何组织代码的示例。 编译项目时(使用g++或MSVC)出现以下错误: 错误:调用“boost::spirit::x3::unused_type::get()”时没有匹配的函数 在函数的第一行中,使用以下代码显示“成功”: // tag used to get the position cache from the context struct annotate_position { template

我正在关注boost网站上的x3文档,并且我已经尝试使用后面的注释示例中解释的内容来扩展如何组织代码的示例。 编译项目时(使用g++或MSVC)出现以下错误:

错误:调用“boost::spirit::x3::unused_type::get()”时没有匹配的函数

在函数的第一行中,使用以下代码显示“成功”:

// tag used to get the position cache from the context
struct annotate_position
{
    template <typename T, typename Iterator, typename Context>
    inline void on_success(const Iterator &first, const Iterator &last, T &ast, const Context &context)
    {
        auto &position_cache = x3::get<position_cache_tag>(context).get();
        position_cache.annotate(ast, first, last);
    }
};
//用于从上下文获取位置缓存的标记
结构注释位置
{
模板
成功时内联无效(常量迭代器&第一个、常量迭代器&最后一个、T&ast、常量上下文&上下文)
{
auto&position_cache=x3::get(上下文).get();
位置\缓存注释(ast、第一个、最后一个);
}
};
可以在此处找到代码:


注释示例几乎是完全相同的代码,只是在一个文件中,因此我无法找出错误所在…

注释使用
with
指令。这将修改这些规则的上下文

但是,上下文已在
config.hpp
中硬编码,因为这样可以使规则定义在各自的翻译单元(源文件)中分离

要直接修复它,请执行以下操作:

struct position_cache_tag;
using position_cache = boost::spirit::x3::position_cache<std::vector<iterator_type>>;

using simple_context_type = x3::phrase_parse_context<x3::ascii::space_type>::type;

using context_type = boost::spirit::x3::context<
    client::parser::position_cache_tag,
    std::reference_wrapper<position_cache>, 
    simple_context_type
>;
这将足以缓解问题,但很明显,
on\u success
中的注释代码将无法编译。如果你愿意,你可以让自己摆脱困境,但我只是从
main.cpp
中删除了未使用的代码

奖金 作为奖励,您现在可以不使用
reference\u包装器
,因为我看到您使用的是Boost 1.70

with指令中的可变状态过去需要引用包装器,但我最近发现()不再需要它。因此,您可以简化上下文:

using context_type = boost::spirit::x3::context<
    client::parser::position_cache_tag,
    position_cache, 
    simple_context_type
>;

顺便说一句,谢谢你的回复,我忘了早点做。它帮助我有点记得如何在C++中思考代码,我已经用了一段时间了……我可以想象:我忘记了我每天不用的任何细节。
using context_type = boost::spirit::x3::context<
    client::parser::position_cache_tag,
    position_cache, 
    simple_context_type
>;
auto &position_cache = x3::get<position_cache_tag>(context); // NOTE: no more .get()
auto const parser =
    with<position_cache_tag>(positions)[client::employees()];
commit 2d1d553afab53d7a83620406c2dcd50967bf2765
Date:   Wed Jul 31 22:50:49 2019 +0200

    Build tweaks

    Make it compile on my linux box, and adding some minimum
    debug/sanitizer/diagnostics flags

commit 98a989bb165d0b25b6919449d4dd09f7656168c8
Date:   Wed Jul 31 22:51:50 2019 +0200

    Various compiler wanrings, no impact

commit 91f5c607c10a489e2d7b9e45dca55438d05419a2
Date:   Wed Jul 31 22:53:46 2019 +0200

    Fixed style issues in main.cpp

     - using namespace (my first hunch was with `ref` being std::ref instead
     of boost::ref, but that turned out a red herring. Better to be explicit
     though

     - added condition on use of ast[1]

commit 084700c80023d4fb291bee36f41cb99f23f7dffa
Date:   Wed Jul 31 22:51:20 2019 +0200

    Fix the context_type in config.hpp

commit df7f9505e042b93bcd62167090e89008788218de (HEAD -> master, sehe/master)
Date:   Wed Jul 31 22:56:20 2019 +0200

    Simplify the with directive

    1.70.0 no longer requires manual ref() for with directives with mutable
    context items.