
hi thomas & andrey,
int main() { boost::for_each(boost::irange(0, 10), [] (int) { std::cout << "hello world\n";}); boost::for_each(boost::irange(0, 10), [] (int index) { std::cout << "hello world from " << index << "\n";}); } ========8<========8<========8<========8<========8<========8<======== IMHO, a regular loop looks simpler than either of these variants:
for (int i = 0; i < 10; ++i) std::cout << "hello world from " << i << "\n";
also, I guess this should also work:
for (auto i: boost::irange(0, 10)) std::cout << "hello world from " << i << "\n";
of course, these variants all work, though they have the visual noise, that i was referring to: a: boost::for_each(boost::irange(0, X), b: for (int i = 0; i < X; ++i) c: for (auto i: boost::irange(0, X)) d: for (auto i: boost::times(X)) e: boost::loop (X, or if one uses namespace boost: a: for_each(irange(0, X), b: for (int i = 0; i < X; ++i) c: for (auto i: irange(0, X)) d: for (auto i: times(X)) e: loop (X, in both cases my proposal is the most compact one, though still not as compact as "X.do". using a lot of higher-level languages these days, writing loops in c++ just feels too verbose for this century ... range-based for loops avoid the manual handling of iterators ... iac, if we want to do something N times, we just want to loop without thinking about integer ranges or incrementing integers ;) cheers, tim