Boost logo

Boost Users :

From: Dwight Kelly (dkelly_at_[hidden])
Date: 2008-02-20 10:35:48


Hello,

I've encountered a problem compiling code that uses boost
multi_index_container. I'm using both Microsoft Visual Studio 2005 and
Apple's gcc 4.0.1. Visual Studio was very picky about how I used
namespaces. I finally got it working with the code below.

The key to success was the 'using namespace boost::multi_index' line. If
I attempted to prefix the members directly, eg.

typedef typename boost::multi_index::nth_index_const_iterator<0>::type
left_const_iterator;

or

namespace mi=boost::multi_index;
typedef typename mi::nth_index_const_iterator<0>::type left_const_iterator;

it would fail to compile.

However, when I attempt to compile the same code on Mac OS X using gcc
4.0.1 I get the following errors. Does anyone know why?

src.cpp:98:error: wrong number of template arguments (1, should be 2)
/boost/boost/multi_index_container_fwd.hpp:46: error: provided for
'template<class MultiIndexContainer, int N> struct
boost::multi_index::nth_index_const_iterator'
src.cpp:98: error: expected ';' before 'left_const_iterator'
src.cpp:99: error: wrong number of template arguments (1, should be 2)
/boost/boost/multi_index_container_fwd.hpp:46: error: provided for
'template<class MultiIndexContainer, int N> struct
boost::multi_index::nth_index_const_iterator'
src.cpp:99: error: expected ';' before 'right_const_iterator'

-----code----

   using namespace boost::multi_index;

   88 template<class A, class B=String>
   89 class SimpleBiMap : public multi_index_container<
   90 pair<A,B>,
   91 indexed_by<
   92 ordered_unique<member<pair<A,B>, A,
&pair<A,B>::first> >,
   93 ordered_unique<member<pair<A,B>, B,
&pair<A,B>::second> >
   94 > >
   95 {
   96 public:
   97 typedef pair<A,B> mytype;
   98 typedef typename nth_index_const_iterator<0>::type
left_const_iterator;
   99 typedef typename nth_index_const_iterator<1>::type
right_const_iterator;
  100
  101 SimpleBiMap(const mytype init[], int N) {
  102 for (int i=0; i<N; i++) {
  103 insert(init[i]);
  104 }
  105 }
  106
  107 left_const_iterator find(const A &key) const { return
get<0>().find(key); }
  108 right_const_iterator find(const B &key) const { return
get<1>().find(key); }
  109
  110 left_const_iterator left_end() const { return
get<0>().end(); }
  111 right_const_iterator right_end() const { return
get<1>().end(); }
  112
  113 const B &operator[](const A &key) const { return
get<0>().find(key)->second; }
  114 const A &operator[](const B &key) const { return
get<1>().find(key)->first; }
  115 };

---code---

Thank you,
Dwight Kelly
Apago, Inc.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net