Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2004-03-27 10:55:30

I've been working on my review of indexed set and I've run into a problem. I
suspect it is my fault, but I'm having trouble figuring it out. The compiler
errors are just not helping....

The basic premise is to setup a bi-directional map using a date and a string
as the 2 index types. When I iterate over the first index (a date) everything
is fine. But I'm not able to figure out how iterate over the string (second)
index. First I used the map_itr as defined below, but that didn't work. I
presume that's because the first itr type is for the first index type. But
then I haven't been able to figure out the magic to get an iterator type for
the second index.

I'll send you the compiler errors if you want, but I'm guessing you'll know
what I'm doing wrong without this. I'm using gcc 3.3.1 on Mandrake Linux 9.2
and I've already successfully built and run the tests.

#include "boost/date_time/gregorian/gregorian.hpp"
#include "bimap.hpp" //includes the bidirectional_map template from examples
#include <string>
#include <iostream>

using namespace boost::gregorian;

typedef bidirectional_map<date, std::string>::type date_to_string_bimap;
typedef date_to_string_bimap::value_type map_vt;
typedef date_to_string_bimap::const_iterator map_itr; //works fine for date
// why doesn't this work?
//typedef nth_iterator_type<date_to_string_bimap,2>::type to_map_itr;

  date_to_string_bimap ds_map;
  date d1(2004,Mar, 27);
  std::string s1("String 1");
  ds_map.insert(map_vt(d1,s1)); //fine here

  //presumably this needs to be an nth_iterator type?
  //Not able to iterate over the string side of this...
  to_map_itr i2 = ds_map.get<to>().begin();
  while (i2 != ds_map.get<to>().end())
    std::cout << "string: " << i2->first
              << " date: " << i2->second << std::endl;

  return 0;

Boost list run by bdawes at, gregod at, cpdaniel at, john at