Use of for_each on map elements

前端 未结 11 732
北荒
北荒 2021-01-30 10:29

I have a map where I\'d like to perform a call on every data type object member function. I yet know how to do this on any sequence but, is it possible to do it on an associativ

11条回答
  •  野的像风
    2021-01-30 10:54

    For fellow programmers who stumble upon this question from google, there is a good way using boost.

    Explained here : Is it possible to use boost::foreach with std::map?

    Real example for your convenience :

    // typedef in include, given here for info : 
    typedef std::map Wt::WEnvironment::CookieMap
    
    Wt::WEnvironment::CookieMap cookie_map = environment.cookies();
    
    BOOST_FOREACH( const Wt::WEnvironment::CookieMap::value_type &cookie, cookie_map )
    {
        std::cout << "cookie : " << cookie.first << " = " << cookie.second << endl;
    }
    

    enjoy.

提交回复
热议问题