Boost logo

Boost :

Subject: Re: [boost] [Config] Macro for C++0x range-based for
From: Michel MORIN (mimomorin_at_[hidden])
Date: 2010-12-17 11:02:48


John Maddock wrote:
> OK, but what I'm missing here is a boost-library author saying "I want to
> use this for X", or to put it another way, we don't add new macros just
> because we can - as there are too many of the things already!

I'm not a boost-library author, but would like to submit a patch
(for boost/range/begin.hpp and boost/range/end.hpp)
which needs BOOST_NO_RANGE_BASED_FOR.

C++0x range-based for conflicts with many Boost libraries:
(Remarkably, boost::iterator_range cannot be used in C++0x range-based for.)

// case 1
#include <boost/range/iterator_range.hpp>
for (auto x : boost::iterator_range<int*>(nullptr, nullptr)) {} // error

// case 2
#include <boost/ptr_container/ptr_vector.hpp>
for (auto x : boost::ptr_vector<int>()) {} // error

// case 3
#include <vector>
#include <boost/range/adaptor/reversed.hpp>
for (auto x : std::vector<int>() | boost::adaptors::reversed) {} // error

// case 4
#include <boost/algorithm/string.hpp>
#include <boost/array.hpp>
for (auto x : boost::array<int, 2>()) {} // error

// case 5
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/range/algorithm.hpp>
for (auto x : std::vector<boost::shared_ptr<int> >()) {} // error

All these errors are caused by ambiguity between std::begin/end and
boost::begin/end.
I've already made a patch to resolve this issue and I will submit a patch
after BOOST_NO_RANGE_BASED_FOR is ready on trunk.

Regards,
Michel


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