From -4797183973042478464
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78e5,924f354765fe932a
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-05-23 01:51:01 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!skynet.be!skynet.be!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: James Kanze <kanze@alex.gabi-soft.de>
Newsgroups: comp.std.c++
Subject: Re: constructor calls in vectors
Date: Thu, 23 May 2002 08:50:13 GMT
Organization: James Kanze
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <864rgy9fgh.fsf@alex.gabi-soft.de>
References: <ac1iu6$222i$1@agate.berkeley.edu> <XeeEevAWeV58EwTU@robinton.demon.co.uk> <3CE562E8.8050403@acm.org> <m37km2s6bz.fsf@merlin.nerim.net> <86r8k4e1ec.fsf@alex.gabi-soft.de> <3CEAF4CA.20200@animats.com>
X-Trace: mail2news.demon.co.uk 1022143818 mail2news:15554 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
X-MIME-Autoconverted: from 8bit to quoted-printable by mr0.ash.ops.us.uu.net id QQmqbd26811
X-MIME-Autoconverted: from quoted-printable to 8bit by mulga.cs.mu.OZ.AU id RAA06098
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mulga.cs.mu.OZ.AU id SAA02628
Lines: 49
Xref: archiver1.google.com comp.std.c++:11447

John Nagle <nagle@animats.com> writes:

|>  James Kanze wrote:

|>  > I would argue that this is the correct interpretation.  I'm not
|>  > 100% sure, however, since I don't think that there is any
|>  > requirement concerning the default constructor, and there is a
|>  > guarantee that it is NOT called in constructing the vector.  (It
|>  > may be called to construct the argument to the constructor, of
|>  > course.)

|>      I once reported that as a bug in some STL implementation.  New
|>  objects were created by invoking the default constructor, then
|>  assigning, rather than by invoking the copy constructor.  It was a
|>  bug; only by accident did it work that way.

That is definitly non-conforming.

|>      This typically comes up when an class contains a data member
|>  which is a reference.  That reference has to be initialized during
|>  construction, and so the default constructor is usually not
|>  meaningful.  Thus, there's a reason to get this right.

I was thinking more of the case where instead of using a default
argument, the implementor provides two constructors:

    vector<T>::vector( size_t )
    vector<T>::vector( size_t, T const& )

The second *MUST* use only the copy constructor; no call to the
default constructor is allowed, as it must work with classes without
default constructors.

The formal semantics of the first are to default construct a T, then
copy it.  My question is rather whether using only the default
constructor is a legal optimization.

--=20
James Kanze                                mailto:kanze@gabi-soft.de
Conseils en informatique orient=E9e objet/
                    Beratung in objektorientierter Datenverarbeitung
Ziegelh=FCttenweg 17a, 60598 Frankfurt, Germany Tel. +49(0)179 2607481

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



