|
Boost : |
From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2006-05-23 14:20:15
On 5/23/06, Shunsuke Sogame <mb2act_at_[hidden]> wrote:
> Daniel Walker wrote:
> > On 5/23/06, Shunsuke Sogame <mb2act_at_[hidden]> wrote:
> >> BTW, I found a bug:
> >> <boost/range/concepts.hpp> seems to
> >> apply 'boost::size' to Forward Range.
> >
> > If I recall correctly applying boost::size() was intentional. size(r)
> > is a valid expression for the ForwardRange concept, and I believe
> > Thorsten didn't want ADL to kick in, so in the concept check
> > implementation boost:: is used to qualify all the functions.
> > boost::size() eventually dispatches either a size() member of the
> > range object or std::distance().
>
> Updated cvs shows 'boost::size' uses 'operator-' ?
> I somewhat wonder why 'boost::size' and
> 'boost::range_size' are not deprecated
> like 'boost::range_result_iterator'.
My bad. I just got the new range files (very busy the last few weeks)
and there is a bug here.
Actually, I think this is a case of the concept checks reveling a bug
in the library. The following generates the error you're seeing.
#include <boost/concept_check.hpp>
#include <boost/iterator/iterator_archetypes.hpp>
#include <boost/range/concepts.hpp>
#include <boost/range/iterator_range.hpp>
using namespace boost;
using namespace std;
int main()
{
typedef iterator_archetype<
int,
iterator_archetypes::readable_iterator_t,
forward_traversal_tag
> iterator_type;
typedef iterator_range<iterator_type> range_type;
function_requires<ForwardRangeConcept<range_type> >();
}
The problem is that the ForwardRange concept requires the expression
size(r) where r is an object of type X modeling ForwardRange and
boost::range_iterator<X>::type is a model of ForwardTraversalIterator.
However, the implementation of boost::size(r) expects X to provide
operator-, which is an expression of RandomAccessTraversalIterator.
So, I think either size(r) should be removed from the FowardRange
concept (bad idea), or boost::size(r) should either offer a
specialization for ForwardRanges or revert to dispatching the call to
std::distance() (better idea?).
Daniel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk