Re: key / value lookup

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Tom Widmer (tom_usenet_at_hotmail.com)
Date: 10/13/04


Date: Wed, 13 Oct 2004 18:21:44 +0100

On Wed, 13 Oct 2004 09:01:32 -0700, "Priyesh"
<PriyeshPadmavilasom@cougarmtn.com> wrote:

>I need lookups from values to keys in a map. I end up creating a second map
>with keys as the first map's values. Is there an easy way to deal with this
>situation?

Yes, use the multi-indexing container library from:
http://www.jobmanager.com/engineering/boost/nightly/
It will be included in the next official boost (www.boost.org)
release. You might be able to find a downloadable zip of just that
library somewhere.

>For eg:
>I have <column type> to <column index> map as an map<int, int> ( used to
>find the type of a column from it's displayed index)
>
>I come across situations where i need to find the column type of a column
>index, so i end up creating a second map for this purpose as <column index>
>to <column type>.

If you don't need to do that look-up often, you could just use
std::find_if with a suitable predicate to compare against the value.

Tom