From -2090744948804753004
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!news4.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 20 Dec 2009 12:30:02 -0600
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
To: (Usenet)
From: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Newsgroups: comp.std.c++
Subject: Re: Why is std::array an aggregate?
Followup-To: comp.std.c++
Organization: T-Online
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <hgkrs6$p1f$01$1@news.t-online.com>
References: <hgf8r0$7ta$1@news.albasani.net>
  <2fba9f88-3e5e-472f-a2fa-b7b415f07f69@g26g2000yqe.googlegroups.com>
Content-Type: text/plain; charset="ISO-8859-1"
X-Original-Date: Sun, 20 Dec 2009 10:47:49 +0100
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Date: Sun, 20 Dec 2009 12:21:57 CST
Lines: 38
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-xVf66C7yseoyYEvaH4GGM0HxRpfh4QDiD8OMucHTx7IbsellwAg9uiqPr2M7e0r4lGO/ZAFAGSTAzkG!AqaRO5YXx5RmtqFHxkfRaRlRyDvhtQE4dL7pvrlZZuskFv0lhmwDsaVekeU9
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
Xref: g2news1.google.com comp.std.c++:1945

James Kanze wrote:

> On Dec 18, 9:00 pm, Scott Meyers <NeverR...@aristeia.com> wrote:
>> In TR1, std::tr1::array needed to be an aggregate so that it
>> could be brace-initialized.  To offer the same capability for
>> C++0x's std::array, the class could simply declare a
>> constructor taking a std::initializer_list.  So why is
>> std::array an aggregate?  Making it a non-aggregate would
>> permit e.g., giving it a constructor taking a pair of
>> iterators.
> 
> Presumably, so that it can be statically initialized, in order
> to avoid order of initialization problems.  
>

I believe this can all be done using variadic templates:

template<typename T, size_t S>
struct array {
   template<typename ...U>
   constexpr array(U&&... u):elems{ u... } { }

   T elems[S];
};

array<int, 3> a = { 1, 2 }; // works, is statically initialized
array<int, 2> a = { 1, 2, 3 }; // gives an error at compile time

It doesn't seem to be that we can use static_cast or std::forward here to
enable move semantics, as i think it will render the initializers to non-
potential-constant-expressions.

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



