Re: STL: how to get the sequence number of a newly added item into a
set
On May 25, 7:05 pm, Sam <s...@email-scan.com> wrote:
bilgekhan writes:
After doing a succcessful insert() or find() on a set<T> container
is it possible to get the item number of this item in the set?
(ie. its zero-based sequence number (position/location/rank/index)
within the sorted collection)
There are no "sequence numbers" for members of a set.
Individual members of sets are accessed via iterators.
A set has a defined order, so there is a defined and guaranteed
bijection between elements of the set and the set of integers in
[0...s.size()).
Additional info: insert() returns a pair<T> and find()
returns an iterator. Using any of these two objects is it
possible to get the sequence number of the item these
objects point to?
No, because there is no such a concept as a "sequence number".
Anytime you have a defined order, there is a concept of sequence
number. Set doesn't support it directly, for reasons explained
by Jerry Coffin, but the concept definitly exists.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34