我有:
struct Mystruct
{
void Update(float Delta);
}
typedef std::map<int, Mystruct*> TheMap;
typedef TheMap::iterator TheMapIt;
TheMap Container;
Run Code Online (Sandbox Code Playgroud)
并且想做:
for(TheMapIt It = Container.begin(), Ite = Container.end(); It != Ite; ++It)
{
It->second->Update(Delta);
}
Run Code Online (Sandbox Code Playgroud)
使用std::for_each,怎么做?
我想我可以声明如下函数:
void Do(const std::pair<int, Mystruct*> Elem)
{
Elem->Update(/*problem!*/); ---> How to pass Delta in?
}
Run Code Online (Sandbox Code Playgroud)
或者制作另一个结构:
struct Doer
{
Doer(float Delta): d(Delta) {}
void operator(std::pair<int, Mystruct*> Elem)
{
Elem->Update(d);
}
}
Run Code Online (Sandbox Code Playgroud)
但这需要一个新的结构.
我想要实现的是使用简单std::for_each的东西std::bind_1st,std::mem_fun就像这样std::vector,有可能吗?
请std在使用前考虑使用方式boost …