Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

could an braced-init-list be a first-class expression?

43 views
Skip to first unread message

pietro....@gmail.com

unread,
Feb 19, 2014, 1:47:33 PM2/19/14
to
I'm wondering what would prevent an initialization list from being a first-class expression of type std::initializer_list.

I understand that the current standar allows braced-init-lists to appear only when assigning to a scalar of type T or to an object of a class taking an std::initializer_list in the assignment operator.

Having

void f (std::vector<double> v);

It is currently possible to do this:

auto a {1, 2, 3}:
g (a);

but not to do this:

g ({1, 2, 3});

As I see it, all information the compiler needs is there. Is there any specific reason why this isn't possible?

Thanks,

pietro....@gmail.com

unread,
Feb 19, 2014, 1:48:50 PM2/19/14
to

> g (a);

> g ({1, 2, 3});

of course I meant f(..);

Paavo Helde

unread,
Feb 19, 2014, 2:48:01 PM2/19/14
to
pietro....@gmail.com wrote in
news:a45ccd07-3838-4fda...@googlegroups.com:
>
> void f (std::vector<double> v);
>
> It is currently possible to do this:
>
> auto a {1, 2, 3}:
> g (a);
>
> but not to do this:
>
> g ({1, 2, 3});

FWIW, gcc 4.8 (with -std=c++0x) compiles and runs this fine:

#include <vector>

void g(std::vector<double> v) {}

int main(int argc, char *argv[]) {
g({1.5, 2.0, 3.0});
}

Pietro Cerutti

unread,
Feb 20, 2014, 2:55:47 AM2/20/14
to
Correct. This is what I get from posting trying to recall what the problem was. The actual issue is this. Why can't I construct a temporary initializer_list object with curly braces, so I can call this?


void h (const double d[3]);

h ({1., 2., 3.}.begin());

Paavo Helde

unread,
Feb 20, 2014, 3:54:18 AM2/20/14
to
Pietro Cerutti <pietro....@gmail.com> wrote in
news:d8738a16-7951-43b1...@googlegroups.com:
... whereas this compiles and runs:

auto x {1.};
typedef decltype(x) T;
h (T({1., 2., 3.}).begin());

Right... Something to do with grammar and that '}' can't be followed by
'.'?


Pietro Cerutti

unread,
Feb 20, 2014, 4:10:12 AM2/20/14
to
Yep my point exactly. The type info is there.
0 new messages