Should I use std::for_each?

前端 未结 9 1315
自闭症患者
自闭症患者 2020-12-08 04:18

I\'m always trying to learn more about the languages I use (different styles, frameworks, patterns, etc). I\'ve noticed that I never use std::for_each so I thought that perh

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 04:29

    Boost.Range simplifies the use of standard algorithms. For your example you could write:

    boost::for_each(v, [](int n) { cout << n << endl; });
    

    (or boost::copy with an ostream iterator as suggested in other answers).

提交回复
热议问题