[iterator]counting_iterator question

I encountered some problems while using counting_iterator. Suppose we have a range called RangeType, and we define: typedef boost::counting_iterator< boost::range_value< RangeType >::type
MyCountingIterator;
if I do:
std::vector< int > vec( 100 );
std::vector< int >:: iterator iter = vec.begin() + ( countingIter2 -
counitingIter1 );
VC8 would then complain about a conversion from __int64 to int because the
difference type of MyCountingIterator (using default) is __int64. Since we
treat warnings as errors. I then changed MyCountingIterator to
typedef boost::counting_iterator< boost::range_value< RangeType >::type,
boost::use_default, boost::range_difference< RangeType >::type >
MyCountingIterator;
This time I got a different error:
iterator_facade.hpp(554) : error C2784: '__w64 int
boost::counting_iterator

"Sean Huang"
My question is why limiting the last three template parameters to default in counting_iterator::distance_to.
Sorry, I don't understand the question. The only thing that's limited here is that you can only compare counting iterators that have the same CategoryOrTraversal and Difference parameters. That might be a bit shortsighted; maybe we should have additional template arguments to distance_to. -- Dave Abrahams Boost Consulting www.boost-consulting.com

From: "David Abrahams" dave@boost-consulting.com
"Sean Huang"
writes: My question is why limiting the last three template parameters to default in counting_iterator::distance_to.
Sorry, I don't understand the question.
The only thing that's limited here is that you can only compare counting iterators that have the same CategoryOrTraversal and Difference parameters. That might be a bit shortsighted; maybe we should have additional template arguments to distance_to. Sorry, I meant the last TWO template parameters.
The distance_to is declared as:
template < class OtherIncrementable >
difference_type
distance_to(counting_iterator<OtherIncrementable > const& y) const;
My understanding is this is equivent to (correct me if I am wrong):
template < class OtherIncrementable >
difference_type
distance_to(counting_iterator

"Sean Huang"
To do what you want, shouldn't it be:
template < class OtherIncrementable > difference_type distance_to(counting_iterator
const& y) const; Maybe the compiler is wrong?
You're right; this is certainly a bug. Would you care to submit a bug report at sourceforge? Thank you! -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Sean Huang