Boost logo

Boost :

Subject: [boost] BOOST_FOREACH like macro for map
From: mobi phil (mobi_at_[hidden])
Date: 2009-10-20 12:06:23


new to this list... did not find anything similar on net.

One of the annoyances with std::map is that if you work with const maps, then
there is no "one line" code to get an element knowing the key.

given the map

const map<string, string> aStringMap;

I cannot write

const string &s = aStringMap["key"];

I should write:

map<string, string>::const_iterator it=aStringMap.find("key")
if( it != aStringMap.end() ) {

so would be nice to have a macro like

BOOST_CONSTMAPFIND(aStringMap, "key", data)
      processResult( data );

the version

if(BOOST_CONSTMAPFIND(l_map, l_key, l_data) )


Seems to be impossible to implement

mobi phil
being mobile, but including technology

Boost list run by bdawes at, gregod at, cpdaniel at, john at