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,
>which is equal to
>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

+ #if defined(BOOST_MSVC)
+ #pragma warning(disable: 4244)
+ #endif
        void advance(typename super_t::difference_type n)
            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

Sebastian Redl

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at