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


Groups > comp.lang.c++ > #11602

Re: Array of initializer lists?

From Victor Bazarov <v.bazarov@comcast.invalid>
Newsgroups comp.lang.c++
Subject Re: Array of initializer lists?
Date 2011-11-18 11:39 -0500
Organization A noiseless patient Spider
Message-ID <ja61ns$for$1@dont-email.me> (permalink)
References <4ec6856f$0$4382$7b1e8fa0@news.nbl.fi>

Show all headers | View raw


On 11/18/2011 11:18 AM, Juha Nieminen wrote:
>    I'm trying to do this:
>
>      auto values[] = { { 1, 2, 3 }, { 4, 5, 6 } };
>
> but gcc 4.6 is giving me the error:
>
> error: unable to deduce 'std::initializer_list<auto>' from '{{1, 2, 3}, {4, 5, 6}}'
>
>      If I make a small change, it doesn't help:
>
>      auto values = { { 1, 2, 3 }, { 4, 5, 6 } };
>
> (the same error is issued.)
>
>    Is this because the above code is invalid, or because gcc 4.6 doesn't
> yet work properly with such constructs?
>
>    Note that this compiles and works as expected:
>
>      auto values = { { 1, 2, 3 } };

The doubled-up braces are converted into single ones here, so no 
surprise that it's OK.

When you supply a brace-enclosed initializer list, the compiler is 
supposed to initialize the object with 'initializer_list<blah>', and 
nested brace initializers probably call for 
'initializer_list<initializer_list<blah>>', which is likely too much for 
the compiler to deduce.

V
-- 
I do not respond to top-posted replies, please don't ask

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


Thread

Array of initializer lists? Juha Nieminen <nospam@thanks.invalid> - 2011-11-18 16:18 +0000
  Re: Array of initializer lists? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-11-18 11:39 -0500
    Re: Array of initializer lists? Juha Nieminen <nospam@thanks.invalid> - 2011-11-18 18:59 +0000
  Re: Array of initializer lists? Johannes Schaub <schaub.johannes@googlemail.com> - 2011-11-19 04:08 +0100

csiph-web