关于容器类对象的ForEach: stl 和boost

STL的foreach定义如下

_Fn1 for_each(_InIt _First, _InIt _Last, _Fn1 _Func)

void function_name(value_type tempVar)
{
  //your code here use tempVar
}

_container_type 取自 STL 提供的容器类型如: std::map std::vector std::list std::set ...

typedef std::_container_type<value_type> container_type;
container_type m_dataList;

std::foreach(m_dataList.bengin(),m_dataList.end(),function_name);

value_type 是map 等关联容器时换成 pair,或者container_type::value_type如 pair<int,std::string> mytype


Boost的BOOST_FOREACH


BOOST_FOREACH(value_type tempVar, m_dataList)
{
  //your code here use temVar
}
posted @ 2012-12-16 13:21  (soli)Tary  阅读(283)  评论(0编辑  收藏  举报