I have a map where I want to call every data type object member function. I still know how to do it in any order, but is it possible to do it on a cooperative container?
I could get the most answers: but I can not promote in my project, so is there an STL option that I am missing for promotion? Bound?
If it is not possible, then I thought to create a temporary sequence for the data object for pointers and then, call it, something like this:
Class MyClass {Public: Zero Method () const; } Std :: map & lt; Int, MyClass & gt; Map; // ... std :: vector & lt; MyClass * & gt; Vector; Std :: transform (Map.begin (), Map.end (), std :: back_inserter (vector), std :: mem_fun_ref (& std :: map & lt; int, MyClass & gt; :: value_type :: second )); Std :: for_each (vector.bizin), vector.and (), std :: mem_fun (& MyClass :: method));
It looks pretty vague and I really do not like it. Any suggestions?
You can iterate through a std :: map
object . Each Iterator is a std :: pair and lt; Const T, S & gt;
where T
and s
you have your map
.
Here it will be:
(std :: map & lt; int, MyClass & gt; :: iterator = map.begin (); it! = Map.end (); ++ this) {it-> second.Method (); }
If you still want to use Example: and pass it to std :: for_each
, then pass a function that is std :: pair & lt; Const int, MyClass & gt;
zero columnimath (std :: pair and lt; const int, MyClass & gt; and pair) // might be a class static method Also in {pair.second.Method (); }
std :: for_each
:
std :: for_each (Map.begin () Map .end (), calligraphy);
Comments
Post a Comment