Boost logo

Boost :

Subject: Re: [boost] [rfc] loop utility
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2013-01-31 06:34:18

On 01/31/2013 12:16 PM, Tim Blechmann wrote:
> 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 "". 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 ;)
And this is exactly what Boost.Range does ;)
Honestly, I don't see the added advantage the proposed boost::loop gives
since for_each is a more or less standardized name for a function
iterating over some range, where boost.range gives you the facilities to
loop over a range of integers. Also my visual preferences don't see the
extra few characters you need to type as visual noise. True it adds
verbosity, however, the added verbosity highlights the intend (this is
also true for the range based for loops in C++11 as Andrey proposed).
Additionally, the boost range solution gives you the flexibility to use
any range (from adapting the start of the range to specifying the step).
> cheers, tim
> _______________________________________________
> Unsubscribe& other changes:

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