Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-02-23 07:13:21

David Abrahams wrote:
> Daniel Frey <daniel.frey_at_[hidden]> writes:
>> Consider:
>> // A strange way to retrieve my_container.begin():
>> boost::prior( my_container.end(), my_container.size() );
>> Is that legal? The second template parameter of boost::prior is
>> deduced to an unsigned(!) type, which IMHO means that -n is
>> undefined, right? Do we need to fix this? Maybe:
>> template <class T>
>> T prior(T x, typename T::difference_type n)
>> {
>> std::advance(x, -n);
>> return x;
>> }
> Well, that wouldn't work!
> How would you call prior(p, 4) when p is int*?
>> or shall we document that it's illegal/undefined to call
>> boost::prior() with an unsigned second parameter?
> Hmm, no I think if it's unsigned we should either deduce an
> appropriate signed type or implement the "backward advance"
> ourselves. We could use reverse_iterator to do that, FWIW.

template <class T> T prior(T x, ptrdiff_t n)

would be fine (waves hand) if you ask me. (Blasphemy!! Burn him!)

Boost list run by bdawes at, gregod at, cpdaniel at, john at