Boost logo

Boost :

From: Ed Brey (brey_at_[hidden])
Date: 2002-07-16 15:07:20

"Philippe A. Bouchard" <philippeb_at_[hidden]> wrote in message news:ah1i2c$p2g$
> Important classes like pair<>, list<>, vector<> from STL already use copy
> constructor to initialize their members.

An important reason why these classes get away with taking the element by value is that the user knows that if his element is big, he can use vector< shared_ptr<X> >. :-)

> It is also negligable in time because the operator new() is already expensive.

This argument falls apart fairly quickly as soon as the class starts doing some heap allocations in its constructor.

> And I'm curious to know if
> the compiler is not creating the object directly instead of creating a
> temporary, copying it and destroying it when optimizations are requested.

Certainly not in all circumstances. For example, if the constructor reads configuration data from a file, it will be read twice. And of course, part of the convenience of shared_ptr is that it often makes it practical for classes to be noncopyable, which can save development time, depending on the nature of the class.

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