|
Boost : |
Subject: [boost] BOOST_FOREACH like macro for map
From: mobi phil (mobi_at_[hidden])
Date: 2009-10-20 12:06:23
Hello,
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"];
process(s);
I should write:
map<string, string>::const_iterator it=aStringMap.find("key")
if( it != aStringMap.end() ) {
process(it->second)
}
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
-- rgrds, mobi phil being mobile, but including technology http://mobiphil.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk