Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++.moderated > #1422 > unrolled thread
| Started by | hayate <hayatelee@gmail.com> |
|---|---|
| First post | 2011-06-09 07:02 -0600 |
| Last post | 2011-06-10 03:13 -0600 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.c++.moderated
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
| From | hayate <hayatelee@gmail.com> |
|---|---|
| Date | 2011-06-09 07:02 -0600 |
| Subject | See if this usage about initializer_list is conforming to the final draft |
| Message-ID | <3310b0a0-d3ac-497c-b177-ef05f83cdadd@l14g2000pro.googlegroups.com> |
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?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[toc] | [next] | [standalone]
| From | Daniel Krügler <daniel.kruegler@googlemail.com> |
|---|---|
| Date | 2011-06-09 15:22 -0600 |
| Message-ID | <isqvkp$3m2$1@dont-email.me> |
| In reply to | #1422 |
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! ]
[toc] | [prev] | [next] | [standalone]
| From | Helmut Jarausch <jarausch@igpm.rwth-aachen.de> |
|---|---|
| Date | 2011-06-09 15:54 -0600 |
| Subject | Re: See if this usage about initializer_list is conforming to the final draft |
| Message-ID | <95bvfhF7jsU1@mid.dfncis.de> |
| In reply to | #1422 |
On Thu, 09 Jun 2011 07:02:48 -0600, hayate wrote:
> 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?
I've been bitten by this myself. 'array' is an aggregate, there is a long
thread on comp.std.c++ why, thus you have to replace the declaration of
'a' by
A a({{1,2,3,4}}); // note the double braces
Helmut.
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[toc] | [prev] | [next] | [standalone]
| From | Daniel Krügler <daniel.kruegler@googlemail.com> |
|---|---|
| Date | 2011-06-10 03:13 -0600 |
| Subject | Re: See if this usage about initializer_list is conforming to the final draft |
| Message-ID | <isrcrj$tg9$1@dont-email.me> |
| In reply to | #1434 |
Am 09.06.2011 23:54, schrieb Helmut Jarausch:
[..]
> I've been bitten by this myself. 'array' is an aggregate, there is a long
> thread on comp.std.c++ why, thus you have to replace the declaration of
> 'a' by
> A a({{1,2,3,4}}); // note the double braces
This is a false herring: The problem is not because array is an
aggregate, but because array is an aggregate *containing* an aggregate.
This becomes obvious, if we look at a slightly different example:
struct aggr {
int i1, i2, i3, i4;
};
struct B {
B(aggr){}
};
int main() {
B({1,2,3,4}); // OK
}
In this case, we have no wrapped aggregate, therefore we need exactly
one level of braces.
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! ]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++.moderated
csiph-web