Boost logo

Boost Users :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2005-12-31 08:08:09


Hello Evan,

----- Mensaje original -----
De: Evan Carew <carew_at_[hidden]>
[...]
> int main(){
> const people_set::nth_index<2>::type& resstreet_index=ps.get<2>();
> pair<people_set::iterator, people_set::iterator> range;
> range = resstreet_index.equal_range((*domoItor).first);
> }
>
> The above code doesn't compile.
>
> - ---Fourth entry:
> By changing the pair instance to:
>
> pair<people_set::nth_index<2>::type::iterator,
> people_set::nth_index<2>::type::iterator> range;
>
> I finally got it to compile. I managed this not by reading the
> tutorialfor the library (the information isn't there)

Well, you're right there's no explicit mention to this issue
in the tutorial. The info can be extracted from the reference,
though.
In any case, I'll try to improve the docs on this and add some
comments on how to obtain index iterators. Thanks for the
feedback!

> but from
> reading the
> rather prodigious code in multi_index.

Wow, this is quite an achievement. The code can look very
unintelligible.

>
> - ---Fifth entry:
> Am I headed in the right direction, or is there specific interface
> that
> defines the iterator types in a less painful/safe way?
>

You've used one of several syntaxes for getting the type
of the index #2 iterator. Other possibilities are:

people_set::index<resstreetnum>::type::iterator
people_set::nth_index_iterator<2>::type
people_set::index_iterator<resstreetnum>::type

nth_index<people_set,2>::type::iterator
index<people_set,resstreetnum>::type::iterator
nth_index_iterator<people_set,2>::type
index_iterator<people_set,resstreetnum>::type

Since you've assigned tags to your indices, it is probably
nicer to use some of the tag variations instead of
those based on the index ordinal. Other than this,
no syntax is particularly clearer or more concise.
You may also want to follow Todd Day's suggestion in
another reply to your post, and use some typedef's
in order to increase code readability. For instance,
if you define

typedef people_set::index<resstreetnum>::type resstreet_index_type;

then the iterator you're looking for is simply

resstreet_index_type::iterator

which looks quite obvious, since it follows exactly the
same pattern as you'd adopt for an STL container.

HTH

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