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

From: Mario Contestabile (mario_at_zks.net)
Date: 09/14/04


Date: Tue, 14 Sep 2004 09:52:43 -0400

Greetings,

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> >

Since the default comparison function for set is less, as seen here from
<functional>

template<class _Ty>
 struct less : binary_function<_Ty, _Ty, bool> {
 bool operator()(const _Ty& _X, const _Ty& _Y) const
  {return (_X < _Y); }
 };

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?

Wouldn't the use of a multiset be better suited? A multiset is for
(possibly) non unique keys, and a set is for unique keys.

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.

thanx



Relevant Pages

  • Re: C (functional programming) VS C++ (object oriented programming)
    ... The crucial difference between strcmp and strncmp is that the former ... (which needn't, but could be, a string), and a string. ... At the very least I'd say it's a sub-string comparison function. ...
    (comp.lang.c)
  • Re: sorting dates
    ... >The string method runs about 60 times faster, so if speed does matter, ... Your date array appears to hold entries such as 13-Apr-05. ... Your string sort first converts those to 2005-04-13 (the hyphens are a ... Object array, and use a comparison function that subtracts the Objects, ...
    (comp.lang.javascript)
  • RE: Combined natural and unnatural list sorting
    ... > I looked for a while at using comparison functions with sort but I ... Of course a comparison function will work - you just have to write it ... I'll using DSU for this example. ... Split the string into two parts. ...
    (comp.lang.python)
  • Re: portability and small glitch in predicates
    ... The string= comparison function is defined as: ... (Self slap in the face.) ...
    (comp.lang.scheme)
  • Re: help developing function
    ... I now have to write a comparison function that when ... given two pointers to Digital_camera objects decides which of the two should ... Where megapixels are the same, ... string fourth = b.getMake; ...
    (comp.lang.cpp)