Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++.moderated > #1429

Re: See if this usage about initializer_list is conforming to the final draft

Message-ID <isqvkp$3m2$1@dont-email.me> (permalink)
Newsgroups comp.lang.c++.moderated
From Daniel Krügler <daniel.kruegler@googlemail.com>
Subject Re: See if this usage about initializer_list is conforming to the final draft
Organization A noiseless patient Spider
References <3310b0a0-d3ac-497c-b177-ef05f83cdadd@l14g2000pro.googlegroups.com>
Date 2011-06-09 15:22 -0600

Show all headers | View raw


Am 09.06.2011 15:02, schrieb hayate:
>
> code:
>     http://ideone.com/T6GFO
>
> #include<array>
> #include<initializer_list>
>
> using namespace std;
>
> class A {
>      public:
>          A(array<int, 4>) {};
> };
>
> int main() {
>      A a({1,2,3,4});
> }
>
> Its compilation fails on GCC 4.6
> I checked n3291 at 8.5.4/1, it seems here for constructing a is a
> direct-initialization, thus array's aggregation can be invoked.
> Am I right?

You are right that std::array's aggregate initialization can be invoked,
but you are overlooking that (at least a non-zero-length) std::array
conceptually is an aggregate containing another aggregate (the actual C
array) as member. In this context the so-called brace-list elision
cannot be applied, you need to provide the correct number of {} levels,
which is in this case 2, thus

A a({{1,2,3,4}});

is necessary here. This is described in [over.ics.list] p4 of the FDIS:

"Otherwise, if the parameter has an aggregate type which can be
initialized from the initializer list according to the rules for
aggregate initialization (8.5.1),[..]"

HTH & Greetings from Bremen,

Daniel Krügler


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Back to comp.lang.c++.moderated | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

See if this usage about initializer_list is conforming to the final draft  hayate <hayatelee@gmail.com> - 2011-06-09 07:02 -0600
  Re: See if this usage about initializer_list is conforming to the final draft  Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-06-09 15:22 -0600
  Re: See if this usage about initializer_list is conforming to the  final draft Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2011-06-09 15:54 -0600
    Re: See if this usage about initializer_list is conforming to the  final draft  Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-06-10 03:13 -0600

csiph-web