Use of for_each on map elements

前端 未结 11 752
北荒
北荒 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条回答
  •  猫巷女王i
    2021-01-30 11:03

    Will it work for you ?

    class MyClass;
    typedef std::pair MyPair;
    class MyClass
    {
      private:
      void foo() const{};
    public:
    static void Method(MyPair const& p) 
    {
        //......
            p.second.foo();
    };
    }; 
    // ...
    std::map Map;
    //.....
    std::for_each(Map.begin(), Map.end(), (&MyClass::Method));
    

提交回复
热议问题