mizonokuchi

10.times(hoge)

Sep 10th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. template <int N> class Numerable{
  8.  public:
  9.   template <typename F> static void times(F func){
  10.     for(int i=0;i<N;i++){
  11.       func(i);
  12.     }
  13.   }
  14. };
  15.  
  16. int main(){
  17.   vector<int> v;
  18.  
  19.   Numerable<10>::times([&v](int x)->void { v.push_back(x); });
  20.   for_each(v.begin(), v.end(), [v](int x)->void { cout << v[x] << endl;} );
  21.  
  22.   return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment