On Monday 23 June 2014 12:29:27 you wrote:
On Monday 23 June 2014 08:40:29 Adam Romanek wrote:
Hi!
This is a re-post from boost-users mailing list, as I didn't get any response there.
I've just finished investigating an issue in my code which led it to an assert/abort in certain cases. It turned out it was caused by the use of boost::prior(it, n) where n was unsigned int with some non-zero value.
I found a question [1] on the mailing list back in 2004 which describes this issue. Additionally a solution to this problem was also posted in one of the replies [2].
My question is - why hasn't it made into the repository yet?
Probably because it got forgotten.
The current behavior of boost::prior(it, n) when n is unsigned type is far from the one expected by its potential users so I think it should either be properly documented (warned) or fixed immediately.
I agree this should be fixed. Although it would probably be better to follow the standard interface:
template <class BidirectionalIterator> BidirectionalIterator prev(BidirectionalIterator x, typename std::iterator_traits<BidirectionalIterator>::difference_type n = 1);
I.e. the second argument should be accepted as a signed value and not as a template parameter.
I'll apply the change later if noone objects.
I've created a pull request: https://github.com/boostorg/utility/pull/15 After I read that old discussion I decided to go with a slightly more complicated solution than I originally intended.