Article View: comp.std.c++
Article #3187Re: An STL helper -- and template and type shenanigans
From: James Kanze US/ESC 60/3/141 #407...
Date: Thu, 01 Feb 1996 17:23
Date: Thu, 01 Feb 1996 17:23
47 lines
3080 bytes
3080 bytes
In article <01BAEFD6.AD7E8620@dino.int.com> Eugene Lazutkin
<eugene@int.com> writes:
|> Why do I use wrappers? Just small example: vector< auto_ptr< T > >
|> (or list< auto_ptr< T > >). I f you tried it, you'd discover that STL
|> (I use ObjectSpace's implementation) uses copy-ctor with a const parameter
|> and auto_ptr doesn't define it.
|> BTW, how come that auto_ptr from Standard C++ Library is incompatible with
|> vector<>, list<> and other STL containers from the same source? Or maybe I
|> have incorrect implementation?
And just when I thought I'd found a solution to the auto_ptr
problem:-).
In fact, this is a weakness in the STL definition (IMHO). STL
containers require *real* copy constructors, that actually copy. For
something like auto_ptr, this is not reasonable. Even supposing that
STL and the language could handle it, what would be the meaning of:
vector< auto_ptr< T > >
v( 10 , auto_ptr< T >( new T ) ) ;
Certainly not what it would seem to be.
A possible solution would be to have two functions everywhere where
the STL requires a fill object. (The current version has one
function, with a default parameter T() as fill.) The version without
the fill object parameter would use the default constructor, rather
than copy. Obviously, this is only interesting if the implementation
only instantiates functions that are actually used. (I believe that
this is supposed to be the case, although I know that many
implementations do not do this.)
This still leaves a problem with the internal functions, such as
reserve, which may copy the data. While not a problem for auto_ptr
(since they are copying non-const lvalues), it may be a problem for
other classes.
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
-- A la recherche d'une activiti dans une region francophone
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<KANZE.96Feb1141158@slsvewt.lts.sel.alcatel.de>Path:
arc1-ca.pugleaf.net!fido.asd.sgi.com!austernReferences:
<01BAEFD6.AD7E8620@dino.int.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763) Newsgroups: comp.std.c++ Subject: Re: An STL helper -- and template and type shenanigans Date: 01 Feb 1996 09:23:34 PST Organization: SEL Approved: austern@isolde.mti.sgi.com Message-ID: <KANZE.96Feb1141158@slsvewt.lts.sel.alcatel.de> References: <01BAEFD6.AD7E8620@dino.int.com> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 01 Feb 1996 13:11:58 GMT In-Reply-To: Eugene Lazutkin's message of 31 Jan 1996 12:04:06 PST Apparently-To: std-c++@ncar.UCAR.EDU X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMRD3I0y4NqrwXLNJAQF8hwH+IhiXe8YOoMT8G6JLLKB9uhfvcQZu2rT9 xc/qy5NJRgehObxK+/8yyzLhU538xAu7UQLrRAJE/Aqa+HQVu9d9TA== =KLK5 Originator: austern@isolde.mti.sgi.com