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:38:26

On Fri, Jul 13, 2012 at 4:45 AM, Thorsten Ottosen
<thorsten.ottosen_at_[hidden]> wrote:
> On 12-07-2012 16:10, Beman Dawes 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.
> Well, if you post the code, I'll take a look.

See below for my implementation.

> I'd expect boost::filesystem::begin( ... ) and end() to be implemented in
> terms of the std:: mechanism.
> We ought to add a macro in Boost.Range to do just that.

If a macro will cut the boilerplate required to support both C++11
range-based for and C++03 BOOST_FOREACH, I'm all for it.



  // enable C++11 range-base for statement use

  // begin() and end() are only used by a range-based for statement
in the context of
  // auto - thus the top-level const is stripped - so returning const
is harmless and
  // emphasizes begin() is just a pass through.
  const directory_iterator& begin(const directory_iterator& iter)
{return iter;}
  directory_iterator end(const directory_iterator&) {return

  // enable BOOST_FOREACH

  directory_iterator& range_begin(directory_iterator& iter) {return iter;}
  directory_iterator range_begin(const directory_iterator& iter) {return iter;}
  directory_iterator range_end(const directory_iterator&) {return
  } // namespace filesystem

  // namespace boost template specializations
  struct range_mutable_iterator<boost::filesystem::directory_iterator>
    { typedef boost::filesystem::directory_iterator type; };
  struct range_const_iterator <boost::filesystem::directory_iterator>
    { typedef boost::filesystem::directory_iterator type; };

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