Re: set< pair<string, string> > or multiset?

From: Igor Tandetnik (itandetnik_at_mvps.org)
Date: 09/14/04


Date: Tue, 14 Sep 2004 10:06:13 -0400


"Mario Contestabile" <mario@zks.net> wrote in message
news:eSJ%23BImmEHA.1904@TK2MSFTNGP09.phx.gbl
> Buddy of mine's code has a set<> (this is with the dinkum library
> 2.32) and in it he places a pair<> of strings.
>
> This is what it looks like: set< pair<string, string> >
>
> I was wondering just how will his set<> be ordered ? Will it be
> ordered on the string comparison for the pair.first or pair.second?

Lexicographically: ordered by firsts, but if firsts are equal for two
pairs, they are then ordered by seconds.

> Wouldn't the use of a multiset be better suited?

That's for you to decide. Do the algorithms you are going to run against
this collection require that duplicate elements be preserved?

> The way he has it written, items are inserted into the set like so
>
> x = std::make_pair( strKey, strValue );
> hisSet.insert( x );
>
> but strKey is not unique at all, there are several instances of the
> same string.

Two pairs will only be considered duplicate in this code if both
components are equal.

-- 
With best wishes,
    Igor Tandetnik
"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage