
2013/1/31 Tim Blechmann <tim@klingt.org>
hi all,
since c++11 has lambda functions, writing functors is easier than never before ... so, i wonder, what do people think about a small utility function, that calls a functor N times?
ruby: 10.times { puts 'hello world' }
supercollider: 10.do { "hello world".postln }
c++11/boost proposal: boost::loop(10, [] { printf("hello world\n"); }); boost::loop(10, [](int index) { printf("hello %d\n, index); });
personally, i find this coding style more elegant than for loops, as it avoids the visual noise of explicitly counting a loop variable ... not sure, if it is worth a separate library, maybe it could just be added to boost/utility ...
thoughts?
Then how about some class like "looper" that takes a function to run. e.g. looper x10(10); x10([] { printf("hello world\n"); }); x10([](int index) { printf("hello %d\n, index); }); Or with user-defined literals: 10_times([] { printf("hello world\n"); });