【发布时间】:2010-01-04 18:21:52
【问题描述】:
我有以下使用 for 循环的代码,我想使用 transform,或者至少使用 for_each,但我不知道如何使用。
typedef std::list<boost::function<void(void) > CallbackList;
CallbackList callbacks_;
//...
for(OptionsMap::const_iterator itr = options.begin(); itr != options.end(); ++itr)
{
callbacks_.push_back(boost::bind(&ClassOutput::write_option_,this,*itr));
}
在后面的代码中,我实际上想调用这个空函数对象的集合。我在这里也使用了 for 循环,看来我应该能够以某种方式使用 for_each。
for(CallbackList::iterator itr = callbacks_.begin(); itr != callbacks_.end(); ++itr)
{
(*itr)();
}
【问题讨论】:
标签: c++ stl boost-bind boost-function