Boost multi_index_container,按标签获取索引会导致编译器错误

发布于 2024-10-07 22:32:10 字数 1923 浏览 0 评论 0原文

所以,我试图涉足 multi_index_container 并遇到一个相当奇怪的编译器错误,首先这里是演示我的问题的最简单的示例(我可能错过了一些愚蠢简单的东西)...

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/mem_fun.hpp>

namespace multi_index = boost::multi_index;

template <typename _IdType>
class A
{
public:
  typedef _IdType IdType;
  IdType getId() const { return id; }

private:
  IdType id;
};

struct id_index{};

template <typename Traits>
class Container
{
  typedef typename Traits::AType AType;
  typedef typename AType::IdType IdType;

  typedef typename multi_index::multi_index_container<
    AType,
    multi_index::indexed_by<
      // sort by Id
      multi_index::ordered_non_unique<multi_index::tag<id_index>, BOOST_MULTI_INDEX_CONST_MEM_FUN(AType, IdType, getId) >
    >
  > ASet;

  typedef typename ASet::template index<id_index>::type::const_iterator a_it;
  typedef typename ASet::template index<id_index>::type::reverse_iterator a_rit;

  typedef typename ASet::template index<id_index>::type id_index_t;

public:

  bool addA(AType const& cA)
  {
    const id_index_t& os = _cSet.get<id_index>(); // line 1: errors occur here
    // .. do stuff
    return true;
  }

private:
  // Instance of the container...
  ASet _cSet;
};

struct ATraits
{
  typedef A<int> AType;
};

int main(void)
{
  Container<ATraits> container;

  ATraits::AType a;

  container.addA(a);

  return 0;
}

g++(gcc 4.4.4,linux)报告的错误是:

error: expected primary-expression before ‘>’ token (@ line 1)
error: expected primary-expression before ‘)’ token (@ line 1)

所以这工作正常,直到我将容器转换为类模板,在此之后,我收到此错误,并且无法弄清楚为什么......

任何想法都会受到赞赏...

So, I'm trying to dabble with the multi_index_container and am having a rather strange compiler error, first here is the simplest example to demonstrate my problem (I'm probably missing something stupidly simple)...

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/mem_fun.hpp>

namespace multi_index = boost::multi_index;

template <typename _IdType>
class A
{
public:
  typedef _IdType IdType;
  IdType getId() const { return id; }

private:
  IdType id;
};

struct id_index{};

template <typename Traits>
class Container
{
  typedef typename Traits::AType AType;
  typedef typename AType::IdType IdType;

  typedef typename multi_index::multi_index_container<
    AType,
    multi_index::indexed_by<
      // sort by Id
      multi_index::ordered_non_unique<multi_index::tag<id_index>, BOOST_MULTI_INDEX_CONST_MEM_FUN(AType, IdType, getId) >
    >
  > ASet;

  typedef typename ASet::template index<id_index>::type::const_iterator a_it;
  typedef typename ASet::template index<id_index>::type::reverse_iterator a_rit;

  typedef typename ASet::template index<id_index>::type id_index_t;

public:

  bool addA(AType const& cA)
  {
    const id_index_t& os = _cSet.get<id_index>(); // line 1: errors occur here
    // .. do stuff
    return true;
  }

private:
  // Instance of the container...
  ASet _cSet;
};

struct ATraits
{
  typedef A<int> AType;
};

int main(void)
{
  Container<ATraits> container;

  ATraits::AType a;

  container.addA(a);

  return 0;
}

The errors reported by g++ (gcc 4.4.4, linux) is:

error: expected primary-expression before ‘>’ token (@ line 1)
error: expected primary-expression before ‘)’ token (@ line 1)

So this was working fine till I converted the Container to a class template, after this, I get this error, and can't work out why..

Any ideas will be appreciated...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So要识趣 2024-10-14 22:32:10
  bool addA(AType const& cA)
  {
    const id_index_t& os = _cSet.template get<id_index>(); // line 1: errors occur here
    // .. do stuff
    return true;
  }
  bool addA(AType const& cA)
  {
    const id_index_t& os = _cSet.template get<id_index>(); // line 1: errors occur here
    // .. do stuff
    return true;
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文