Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-06-27 17:23:28


"Peter Dimov" <pdimov_at_[hidden]> writes:

> David Abrahams wrote:
>> "Peter Dimov" <pdimov_at_[hidden]> writes:
>>
>>>> Yes. Why wouldn't you want this function to require that condition?
>>>> Anything else is a coding error.
>>>
>>> I am reluctant to label it a coding error ("should never happen in a
>>> correct program"), because in general it can be very hard to ensure
>>> that the condition isn't violated. It's a bit like:
>>>
>>> Requires: a particular state of the library that you have no way of
>>> querying.
>>
>> Harrumph. Isn't it the archive under construction whose state is
>> constrained? If you know you've put 5 elements in a vector, you don't
>> have to query it before calling pop_back(), do you?
>
> So it's safe to remove size() and empty() from the vector interface as users
> always know how large their vectors are, right?

No, because people need that functionality, and not just to check
whether it's okay to pop_back.

> If you are given a vector you don't know whether you can pop_back.

Right. But then you don't want to pop elements off a vector you don't
know anything about.

> If you are given an archive you don't know whether you are allowed to save
> by value, or whether you can safely save by pointer.
>
> (In general.)

Yeah, but what's the use case for this? Someone you don't know hands
you an archive and tells you to save something in it without telling
you how it's safe to do so?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk