From -8248414113886331165
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!news2.google.com!news.glorb.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
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++
Date: Mon, 21 Dec 2009 19:09:08 CST
Organization: T-Online
Lines: 43
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <hgoe4g$pua$01$2@news.t-online.com>
References: <hgf8r0$7ta$1@news.albasani.net>
  <2fba9f88-3e5e-472f-a2fa-b7b415f07f69@g26g2000yqe.googlegroups.com>
  <hgkrs6$p1f$01$1@news.t-online.com>
NNTP-Posting-Host: netlab.cs.rpi.edu
Content-Type: text/plain; charset="ISO-8859-1"
To: (Usenet)
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
X-Original-Date: Mon, 21 Dec 2009 19:17:53 +0100
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news1.google.com comp.std.c++:1959

Johannes Schaub (litb) wrote:

> 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];
> };
> 

Actually, to be a constexpr constructor, all the parameter types must be
taken by value so that they are literal types. But since the goal is static-
initialization, i think this won't matter. One could specialize "array" for
literal types to get back some performance for dynamic initialization cases,
i suspect.

I wonder though about differences in behavior to normal aggregate
initialization - are there any? Thanks!

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



