Boost logo

Boost Users :

Subject: Re: [Boost-users] printing data sorted based on a specific key in boostmulti-index container
From: joaquin_at_[hidden]
Date: 2008-10-10 08:31:38


Ramesh escribió:
> Hi Joaquin,
>
> Supposing I have a container having three unique keys, Is there a way
> I can print data sorted by one of they keys?
> At the moment I tried a raw dump - it shows fields based on the first
> key (which is key1).
>

Hi Ramesh,

Just use the iterators provided by the second or third index. For
instance (not compiled, beware typos):

  for (MyMap::index_iterator<Key2>::type it =
MyContainer.get<Key2>().begin(),
       itend = MyContainer.get<Key2>().end();
       it != itend;++it) {
    cout << it->Key1;
    cout << it->Key2;
    cout << it->Key3;
  }

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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