Should I use std::for_each?

前端 未结 9 1314
自闭症患者
自闭症患者 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:42

    You can use for loop scoping C++11

    For example:

     T arr[5];
     for (T & x : arr) //use reference if you want write data
     {
     //something stuff...
     }
    

    Where T is every type you want.

    It works for every containers in STL and classic arrays.

提交回复
热议问题