【问题标题】:forward-declaring boost.type_erasure reference type前向声明 boost.type_erasure 引用类型
【发布时间】:2015-05-08 07:21:15
【问题描述】:

我在我的代码库中使用boost.type_erasure。到目前为止的经验, 考虑到它所启用的功能,非常好。

我希望能够为我的 API 前向声明“类型擦除引用类型”。这离开了usingtypedef,因为它们不允许 前向声明。

对于值类型,一切都很好:

class any_game_state : public
boost::type_erasure::any<
boost::mpl::vector<has_enter<void ()>,
                   has_update<bool (std::chrono::milliseconds)>,
                   has_exit<int ()>,
                   has_get_resolution<std::pair<int, int> (),
                                      const
                                      boost::type_erasure::_self>,
                   has_get_position<std::pair<int, int> (),
                                    const
                                    boost::type_erasure::_self>,
                   has_get_scene_root<boost::any (), const
                                      boost::type_erasure::_self>,
                   boost::type_erasure::copy_constructible<>,
                   boost::type_erasure::relaxed>> {
    using base = boost::type_erasure::any<...identical_contents>;

    using base::base;
};

但是当我尝试对其相应的参考做同样的事情时,它不起作用:

class any_game_state_ref : public
boost::type_erasure::any<
boost::mpl::vector<has_enter<void ()>,
                   has_update<bool (std::chrono::milliseconds)>,
                   has_exit<int ()>,
                   has_get_resolution<std::pair<int, int> (),
                                      const
                                      boost::type_erasure::_self>,
                   has_get_position<std::pair<int, int> (),
                                    const
                                    boost::type_erasure::_self>,
                   has_get_scene_root<boost::any (), const
                                      boost::type_erasure::_self>,
                   boost::type_erasure::copy_constructible<>,
                   boost::type_erasure::relaxed>,
                   boost::type_erasure::_self&> {
    using base = boost::type_erasure::any<...identical_contents>;

    using base::base;
};

如果我将using 用于“引用类型”,一切正常,但我失去了前向声明引用类型的能力。

我得到的错误如下:

在 src/barvie/controller/game_action_state.cpp:3 包含的文件中: 在 /usr/local/include/boost/type_erasure/any_cast.hpp:24 包含的文件中: /usr/local/include/boost/type_erasure/any.hpp:1290:12:错误:在 'boost::disable_if,has_update >),boost::type_erasure::_self>,has_exit,has_get_resolution 中没有名为 'type' 的类型(), const boost::type_erasure::_self>, has_get_position (), const boost::type_erasure::_self>, has_get_scene_root, boost::type_erasure::copy_constructible, boost::type_erasure::relaxed, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::mpl::vector, has_update >), boost::type_erasure::_self>, has_exit, has_get_resolution (), const boost::type_erasure::_self>, has_get_position (), const boost: :type_erasure::_self>, has_get_scene_root, boost::type_erasure::copy_constructible, boost::type_erasure::relaxed, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na> >, boost::is_const, mpl_::bool_, mpl_:: bool_, mpl_::bool_ >, void>'

::类型* = 0 ~~~^~~~ ../libbarvie/src/barvie/controller/any_game_state.hpp:95:17: 注意:在成员函数 'boost::type_erasure::any, has_update >), boost::type_erasure::_self>, has_exit, has_get_resolution (), const boost::type_erasure::_self>, has_get_position (), const boost::type_erasure::_self>, has_get_scene_root, boost::type_erasure::copy_constructible, boost::type_erasure::relaxed, mpl_::na , mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na , mpl_::na>, boost::type_erasure::_self &>::any' 在这里请求 使用基地::基地; ^ src/barvie/controller/game_action_state.cpp:291:18:注意:将推导的模板参数代入函数模板'any_game_state_ref' [with Concept2 = boost::mpl::vector, has_update >), boost::type_erasure::_self >, has_exit, has_get_resolution (), const boost::type_erasure::_self>, has_get_position (), const boost::type_erasure::_self>, has_get_scene_root, boost::type_erasure::copy_constructible, boost::type_erasure::relaxed, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, Tag2 = boost::type_erasure::_self] (这个, ^ 在 src/barvie/controller/game_action_state.cpp:3 包含的文件中: 在 /usr/local/include/boost/type_erasure/any_cast.hpp:24 包含的文件中: /usr/local/include/boost/type_erasure/any.hpp:1323:12:错误:在 'boost::disable_if,has_update >),boost::type_erasure::_self>,has_exit,has_get_resolution 中没有名为 'type' 的类型(), const boost::type_erasure::_self>, has_get_position (), const boost::type_erasure::_self>, has_get_scene_root, boost::type_erasure::copy_constructible, boost::type_erasure::relaxed, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::mpl::vector, has_update >), boost::type_erasure::_self>, has_exit, has_get_resolution (), const boost::type_erasure::_self>, has_get_position (), const boost: :type_erasure::_self>, has_get_scene_root, boost::type_erasure::copy_constructible, boost::type_erasure::relaxed, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na> >, boost::is_const, mpl_::bool_, mpl_:: bool_, mpl_::bool_ >, void>' ::类型 = 0 ~~~^~~~ ../libbarvie/src/barvie/controller/any_game_state.hpp:95:17: 注意:在成员函数 'boost::type_erasure::any, has_update >), boost::type_erasure::_self>, has_exit, has_get_resolution (), const boost::type_erasure::_self>, has_get_position (), const boost::type_erasure::_self>, has_get_scene_root, boost::type_erasure::copy_constructible, boost::type_erasure::relaxed, mpl_::na , mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na , mpl_::na>, boost::type_erasure::_self &>::any' 在这里请求 使用基地::基地; ^ src/barvie/controller/game_action_state.cpp:291:18:注意:将推导的模板参数代入函数模板'any_game_state_ref' [with Concept2 = boost::mpl::vector, has_update >), boost::type_erasure::_self >, has_exit, has_get_resolution (), const boost::type_erasure::_self>, has_get_position (), const boost::type_erasure::_self>, has_get_scene_root, boost::type_erasure::copy_constructible, boost::type_erasure::relaxed, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, Tag2 = boost::type_erasure::_self &] (*这个,

【问题讨论】:

    标签: c++ boost clang


    【解决方案1】:

    我找到了解决方案。解决方案是放弃引用类型的继承构造函数,而不是继承构造函数,我使用等效的手动继承构造函数。似乎模板与继承的构造函数混合在一起的效果不好:

    template <class...Args>
    any_game_state_ref(Args &&... args) : base(std::forward<Args>(args)...)
    {}
    

    这成功了,现在我也可以转发声明类型已擦除引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-16
      • 1970-01-01
      • 2011-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-11
      • 2015-03-01
      相关资源
      最近更新 更多