Boost logo

Boost :

Subject: Re: [boost] [filesystem] C++11 range-based for statement and BOOST_FOREACH support
From: Beman Dawes (bdawes_at_[hidden])
Date: 2012-07-13 07:16:36


On Thu, Jul 12, 2012 at 1:39 PM, Nathan Ridge <zeratul976_at_[hidden]> wrote:
>
>> Support for the C++11 range-based for statement and BOOST_FOREACH for
>> directory_iterator and recursive_directory_iterator has been added to
>> trunk. This clears feature requests 5896 and 6521.
>>
>> The range-based for has been tested against gcc 4.6, which works, and
>> against VC++2012 RC, which ICEs the compiler. The ICE has been
>> reported to Microsoft.
>>
>> If anyone gives either C++11 range-based for or BOOST_FOREACH a try,
>> I'd appreciate hearing about any problems. Both of these are new to
>> me, and I'm nervous about getting the enabler free functions right.
>>
>> Here is what usage looks like:
>>
>> for (directory_entry& x : directory_iterator("."))
>> {
>> std::cout << " " << x.path() << "\n";
>> }
>>
>> BOOST_FOREACH(directory_entry& x, directory_iterator("."))
>> {
>> std::cout << " " << x.path() << "\n";
>> }
>
> I'm a little surprised to see a function that returns a range named
> "directory_iterator".
>
> Other Boost libraries, such as Boost.Iterator and Boost.Range, distinguish
> between the concepts of an iterator, which denotes a single position in a
> range, and a range, which is defined by iterators at is beginning and its
> end.

directory_iterator is like std::istream_iterator in that a
directory_iterator object identifies the end of a range simply by
being equal to directory_iterator(). Thus these iterators are a little
odd in that they self-identify both the beginning and the end of the
range. So there is no real distinction between an my_iterator and
begin(my_iterator). The only reason the function is there is to meet
the range-based for statement requirements. Ditto for BOOST_FOREACH
range helper functions.

> Have you considered naming the function "directory_range" to be consistent
> with other Boost libraries?

"directory_iterator" is the constructor for class directory_iterator.
I'm happy with that as a name since it identifies the primary use of
the class.

--Beman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk