fork(1) download
  1. //Title of this code
  2.  
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <list>
  6.  
  7. template< typename T, typename F >
  8. std::list< T > make_range( size_t limit, F func )
  9. {
  10. std::list< T > result( limit );
  11. for( auto itr = result.begin(); itr != result.end(); ++itr )
  12. *itr = func();
  13.  
  14. return result;
  15. }
  16.  
  17. int main()
  18. {
  19. auto ls = make_range< int >( 10, []{ return 1; } );
  20.  
  21. for( auto i : ls )
  22. std::cout << i << " ";
  23.  
  24. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
1 1 1 1 1 1 1 1 1 1