From -7238669899776357496
X-Google-Thread: 7894ca11fe,8390690191732735
X-Google-Attributes: gid7894ca11fe,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news1.google.com!news.glorb.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: Scott Meyers <NeverRead@aristeia.com>
Newsgroups: comp.std.c++
Subject: Re: Why is std::array an aggregate?
Date: Sat, 19 Dec 2009 21:37:48 CST
Organization: albasani.net
Lines: 31
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <hgiv5f$cca$1@news.albasani.net>
References: <hgf8r0$7ta$1@news.albasani.net>
  <2fba9f88-3e5e-472f-a2fa-b7b415f07f69@g26g2000yqe.googlegroups.com>
NNTP-Posting-Host: netlab.cs.rpi.edu
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
To: (Usenet)
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
X-Original-Date: Sat, 19 Dec 2009 08:31:41 -0800
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news1.google.com comp.std.c++:1943

James Kanze wrote:
> Presumably, so that it can be statically initialized, in order
> to avoid order of initialization problems.  (It still needs a
> mechanism for the number of elements to be determined,
> statically, from the initialization list, in order to be truly
> useful.)

Well, the size of the std::array is part of its type, so if dynamic
initialization were permitted, all we'd need would be a specification for what
happens if the number of clauses in the init list didn't match the declared size
of the std::array.  To keep things semi-consistent with aggregate
initialization, we could say that std::array elements without initializers would
be value initialized, and if too many initializers were specified, an exception
would be thrown.

Actually, now that I think of it, I'm pretty sure std::array objects can be
dynamically initialized:

    std::array<int, 3> a { f(), g(), h() };        // legal, no?

As for avoiding order of initialization problems, why should std::array be
special in this regard?

Scott

-- 
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



