Boost C++ Libraries: Ticket #6072: Bad iterator difference for m.begin1() - m.end1() in ublas https://svn.boost.org/trac10/ticket/6072 <p> In functional.hpp at a couple of places, for example: </p> <blockquote> <p> static BOOST_UBLAS_INLINE difference_type distance_i (difference_type k, size_type /* size_i */, size_type size_j) { </p> <blockquote> <p> return size_j != 0 ? k / size_j : 0; </p> </blockquote> <p> } </p> </blockquote> <p> k [ / | % ] size_[ i | j ] is used, where k is difference_type (signed), size_i|j is size_type (unsigned). This results in promoting k to unsigned, and can yield very strange results when k is negative. </p> <p> For example, m being a size 2x2 ublas::matrix, m.begin1() - m.end1() yields 2147483646 instead of -2. </p> <p> Putting a static_cast&lt;difference_type&gt;(size_i|j) in functional.hpp seems to solve the problem. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6072 Trac 1.4.3