Boost logo

Boost :

From: Alberto Barbati (abarbati_at_[hidden])
Date: 2004-03-08 05:42:29

Jeremy Siek wrote:

> On Friday, March 5, 2004, at 01:42 AM, Jan Gaspar wrote:
>>> ________________________________________________
>>> 4. docs: "Type Requirements": doesn't the T need
>>> to be DefaultConstructible as well, e.g.
>>> to support push_back(void)?
>> Yes, but DefaultConstructible is needed only if you
>> use such a method. In general it is not needed. For
>> example you can just create empty circular_buffer and
>> use push_back(T&). In this case T doesn't have to be
>> DefaultConstructible.
> That means you have to mention this type requirement
> in the documentation for the push_back() method.

Standard containers do not have push_back()/push_front() methods that
take no arguments, so I don't agree with the decision of having them. I
would remove them entirely.

Moreover, I once had a discussion against having both a foobar() and a
foobar(T) or foobar(T&) signature. The argument was that explicit
instantiation of the entire class requires both methods to be
instantiated so it requires T to be DefaultConstructible even if
foobar() is never called. That's why the standard defines, for example,
std::vector::resize with a default argument, like this:

   void resize(size_type sz, T c = T());

this definition effectively works around this kind of problem as the
default argument expression is not evaluated unless the method is
invoked with less than a full set of arguments.


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