Boost logo

Boost :

From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2004-03-16 08:44:07

Hi Darren,

Darren Cook ha escrito:

> I tried indexed_set with g++ 3.2.3 ("gcc version 3.2 20020903 (Red Hat Linux
> 8.0 3.2-7)") and it compiled all the examples.

Good! Thanx for trying it.

> The reference docs need an "up" link (back to libs/indexed_set/doc/index.html).

Yep, why not. I'll try to add such a link if I have time (review starts 20 and
I'll polishing the last details on the docs.)

> Your tutorial did not deal with using an index in reversed order; I think it
> is worth adding something showing using rbegin()/rend() (I modified
> basic.cpp to print ages oldest first and it worked first time :-).

I've added nothing about rbegin/rend cause they are entirely equivalent
to their analogues in STL containers.

> I found a reverse() function in sequenced.cpp: it seems you apply this to
> the indexed_set container, not to the index, but when I tried it on the
> container in basic.cpp I get a compile error.
> So I tried the sequenced example using rbegin/rend and it worked:
> tc.reverse();
> std::copy(tc.begin(),tc.end(),
> std::ostream_iterator<std::string>(std::cout," "));
> tc.reverse(); /* undo */
> std::copy(tc.rbegin(),tc.rend(),
> std::ostream_iterator<std::string>(std::cout," "));
> Can you explain the thinking behind reverse()? Is it any more/less efficient
> than using rbegin/rend? If not, I think it should either be dropped or
> extended to regular indices as well.

reverse is not a member function of indexed_set, but rather of
sequenced indices. The line:


works because the indexed_set inherits the public interface of
its first index. So this is but an abbreviation of:


(This particular point of indexed_set inheriting index #0 interface
has originated some perplexities in other readers.)
Now, reverse is a memfun of sequenced indices for the simple
reason that it is also present in std::list (and sequenced indices
mimic its interface as closely as possible.) As std::sets do not
have a reverse operation, neither do regular indices (furthermore,
this op does not make sense for such indices.)
So, your options for reverse traversal are:

* Regular indices: use rbegin/rend
* Sequenced indices: rbegin/rend *or* reverse followed
by begin/end. reverse does only affect the sequenced index,
it does not alter other indices in any manner. rbegin/rend
is more efficient (no modifications to the index required.)

Please note that there's nothing new about all this: the
options described are exactly the same you have at your
disposal when working with std::sets (in the case of
regular indices) and std::lists (in the case of sequenced indices.)

Does this solve your doubts? If not, please tell me so.

Shortly before review (in a couple of days maximum) I'll
upload the final version of the docs, which hopefully will
shed more light on the different types of indices available.

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

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