From -3461568519221968421
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,924f354765fe932a
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-05-18 12:35:02 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!yellow.newsread.com!netaxs.com!newsread.com!newsfeed00.sul.t-online.de!t-online.de!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: Gabriel Dos Reis <gdr@codesourcery.com>
Newsgroups: comp.std.c++
Subject: Re: constructor calls in vectors
Date: Sat, 18 May 2002 19:34:53 GMT
Organization: CodeSourcery, LLC
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <m37km2s6bz.fsf@merlin.nerim.net>
References: <ac1iu6$222i$1@agate.berkeley.edu> <XeeEevAWeV58EwTU@robinton.demon.co.uk> <3CE562E8.8050403@acm.org>
X-Trace: mail2news.demon.co.uk 1021750497 mail2news:21195 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)
Mime-Version: 1.0 (generated by tm-edit 7.106)
Content-Type: text/plain; charset=US-ASCII
NNTP-Posting-Date: Fri, 17 May 2002 23:28:44 +0000 (UTC)
X-Newsreader: Gnus v5.7/Emacs 20.7
Lines: 66
Xref: archiver1.google.com comp.std.c++:11358

James Dennett <jdennett@acm.org> writes:

| Francis Glassborow wrote:
| > In article <ac1iu6$222i$1@agate.berkeley.edu>, Eric J. Korpela 
| > <korpela@ellie.ssl.berkeley.edu> writes
| > 
| >> Quick (or maybe not so quick) std::vector question.  Does the
| >> standard specify what constructors will be called during creation
| >> of a vector?  For example when I have classes like the following...
| >>
| >> class A {
| >>  public:
| >>    int i;
| >>    A();                  // Constructor:  Details left to the imagination
| >>    A(const A &a);        // Copy Constuctor:  Ditto
| >> };
| >>
| >> int main(void) {
| >>  std::vector<A> B(1024));
| >> }
| >>
| >> My problem is in porting some code between two platforms.  On one 
| >> platform
| >> the A() constructor is called for every element.
| > 
| > 
| > see 23.2.4.1. where the signature of the relevant ctor for vector 
| > strongly implies that the copy ctor is expected to be used to initialise 
| > the elements of a vector. I do not see anything that forbids the 
| > alternative.
| 
| The fact that the behaviour is specified; there's a single constructor
                                                      ^^^^^^
| which takes a size_type argument and a defaulted const reference to
| ElementType (followed by a defaulted allocator argument which I'm
| largely ignoring here),

Actually, the standard is a little more permissive than that:

17.4.4.4/2:
  An implementation can declare additional non-virtual member function
  signatures within a class:   
   --- by adding arguments with default values to a member function
       signature;172) The same latitude does not extend to the
       implementation of virtual or global functions, however.   
   --- by replacing a member function signature with default values by
       two or more member function signatures with *equivalent behavior*;
   --- by adding a member function signature for a member function name. 

(Emphasis is mine)

| and it is specified as filling the vector
| with copies of the second argument by Table 67 (from sequence
| container requirements).

Agreed, by a literal reading of the standard.

-- 
Gabriel Dos Reis, dosreis@cmla.ens-cachan.fr

---
[ 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                       ]



