From: Alberto Barbati (abarbati_at_[hidden])
Date: 2002-12-14 07:37:25
Fernando Cacciola wrote:
>>As an example, currently the C++ standard includes
>> T & stack<T>::top(), with precondition !(stack.empty()).
>>Instead, it could be
>> may_be<T> & stack<T>::top(); // no precondition required
>><set> could be improved also, instead of:
>> pair<iterator, bool> set::insert(const value_type & x)
>>we would use
>> may_be<iterator> set::insert(const value_type & x)
> Those are interesting examples! Thanks.
> They can all be paralleled with optional<> whatever the model and interface
> we choose.
> Which can of shows that the concept is useful.
If I can say it, I don't think that they are really good examples.
The stack::top signature is wrong, it should return a value and not a
reference and thus it may require a copy of the returned object. This
makes the proposed signature is potentially less efficient. Moreover,
the result of top() could not be used by the caller to modify the
top-most element. For this reason, a more correct signature would be
but, unfortunately, I don't think it's legal.
The proposed signature of set::insert is a downgrade and not an
improvement. Even if the element is not inserted, I still may want to
have the iterator. In order to perform its operation, insert() will have
to compute such iterator, so what's the point in discarding it?
Just my opinion,
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk