Boost logo

Boost Users :

From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2004-11-18 17:43:55


On Thu, 18 Nov 2004 15:21:06 -0700, Chris Goller
<cgoller_at_[hidden]> wrote:
> David-
>
> Thanks.
>
> Upon reading my poorly phrased email I realized this:
>
> I want unique keys so that if the data looks like this:
>
> key value
> 3 1
> 1 2
> 1 4
> 4 3
> 5 5
> 5 9
>
> So, what I would like to do is to a print each value for a particular
> key in such a way:
>
> key: value:
> 1----
> |------2
> |------4
> 3----
> |------1
> 4----
> |------3
> 5----
> |------5
> |------9
>

Chris - the C++ standard says (about associative containers)

"The fundamental property of iterators of associative containers is
that they iterate through the containers in the nondescending order of
keys where nondescending is defined by the comparison that was used to
construct them."

which says to me

So, I guess you could construct a (forward-only)
filtering&transforming iterator based on a multimap iterator that knew
the last key it visited and skip any keys of equal ordering, using the
maps ordering predicate (I'm assuming operator < here, which is wrong
- use the multimap's predicate) :

template<typename KeyType>
bool KeysAreTheSame(KeyType k1, KeyType k2)
{
   return !(k1<k2 || k2<k1);
}

It's a bit messy and would have to be forward-only and there's
probably a better way of doing it...but I think it'd do what you want.

Stuart Dootson


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