
On Fri, Jul 13, 2012 at 4:45 AM, Thorsten Ottosen <thorsten.ottosen@dezide.com> 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. Thanks, --Beman // 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. inline const directory_iterator& begin(const directory_iterator& iter) {return iter;} inline directory_iterator end(const directory_iterator&) {return directory_iterator();} // enable BOOST_FOREACH ------------------------------------------------------------// inline directory_iterator& range_begin(directory_iterator& iter) {return iter;} inline directory_iterator range_begin(const directory_iterator& iter) {return iter;} inline directory_iterator range_end(const directory_iterator&) {return directory_iterator();} } // namespace filesystem // namespace boost template specializations template<> struct range_mutable_iterator<boost::filesystem::directory_iterator> { typedef boost::filesystem::directory_iterator type; }; template<> struct range_const_iterator <boost::filesystem::directory_iterator> { typedef boost::filesystem::directory_iterator type; };