Boost.Bind to access std::map elements in std::for_each

后端 未结 4 835
后悔当初
后悔当初 2020-12-16 03:49

I\'ve got a map that stores a simple struct with a key. The struct has two member functions, one is const the other not. I\'ve managed calling the const function using std::

4条回答
  •  有刺的猬
    2020-12-16 04:48

    If you are already depend on Boost, you may be willing to check Boost Foreach

    BOOST_FOREACH(MyMap::value_type const& val, MyMap)
    {
      val.second.someConstFunction();
    }
    

    Much much readable, though I don't know about performance issues.

    Also note that you can't use templated typed within the macro without "escaping" the , character:

    • either by a typedef before
    • or by using a second pair of parenthesis around the type

提交回复
热议问题