iterate through unordered_map using boost_foreach

2019-09-09 22:21发布

问题:

In my class I've got such soundmap

class SoundSubSystem
{
private:
    boost::unordered_map<string, ISoundEngine*> soundmap;
....
};

But how to iterate through it using BOOST_FOREACH?

SoundSubSystem::~SoundSubSystem()
{
    BOOST_FOREACH(/*?*/ item, soundmap) {
        item.second->drop();
    }
};

What value type should item have?

回答1:

Try this :-

typedef boost::unordered_map<string, ISoundEngine*> myhash;

BOOST_FOREACH(myhash::value_type& item, soundmap) {
        item.second->drop();
    }


标签: c++ boost