Boost logo

Boost Users :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2006-01-26 11:56:48


Lee Houghton wrote:

>The problem appears to be when operator += is called on the iterator.
>Here, the difference_type of the iterator,
>boost::iterator_facade<Derived,Value,CategoryOrTraversal,Reference,Difference>::difference_type,
>which is equal to
>boost::detail::counting_iterator_base<int,boost::use_default,boost::use_default>::difference,
>is __int64.
>
OK, that actually makes sense. The typedef searches for the smallest
type able to represent all differences between any two numbers of the
given type. For signed integers, this is always the next larger signed
type. The reason for this is simple: INT_MAX - INT_MIN == UINT_MAX, but
INT_MIN - INT_MAX == -UINT_MAX, a number that can only be represented by
the next larger signed type.

I wonder if this problem is logically solvable, or if a hack (like a
static_cast in iterator_adaptor::advance, or perhaps a warning disable)
is necessary. Another question is whether this warning should be
considered perhaps a bug in VC++.

Whatever. Different workaround is to modify
boost/iterator/iterator_adaptor.hpp:

+ #if defined(BOOST_MSVC)
+ #pragma warning(disable: 4244)
+ #endif
        void advance(typename super_t::difference_type n)
        {
            
BOOST_ITERATOR_ADAPTOR_ASSERT_TRAVERSAL(random_access_traversal_tag)
            m_iterator += n;
        }
+ #if defined(BOOST_MSVC)
+ #pragma warning(default: 4244)
+ #endif

This is potentially unsafe, of course - nothing prevents you from just
passing a HUGE value to +=. The likelyhood, though ... well, it's just a
workaround.

Sebastian Redl


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net