Boost logo

Boost :

Subject: [boost] [rfc] loop utility
From: Tim Blechmann (tim_at_[hidden])
Date: 2013-01-31 04:31:14

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?

10.times { puts 'hello world' }

supercollider: { "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 ...


prototype available at github:


Boost list run by bdawes at, gregod at, cpdaniel at, john at