From -5576062408546203503 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,924f354765fe932a X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2002-05-17 13:13:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!194.42.224.136!diablo.netcom.net.uk!netcom.net.uk!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail From: James Dennett Newsgroups: comp.std.c++ Subject: Re: constructor calls in vectors Date: Fri, 17 May 2002 20:12:27 GMT Approved: Fergus Henderson , moderator of comp.std.c++ Message-ID: <3CE562E8.8050403@acm.org> References: X-Trace: mail2news.demon.co.uk 1021666351 mail2news:9963 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: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc2) Gecko/20020510 X-Accept-Language: en-us, en MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Lines: 42 Xref: archiver1.google.com comp.std.c++:11351 Francis Glassborow wrote: > In article , Eric J. Korpela > 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 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), and it is specified as filling the vector with copies of the second argument by Table 67 (from sequence container requirements). --- [ 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 ]