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

P

pietro.cerutti

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,
 
P

Pietro Cerutti

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());
 
P

Pietro Cerutti

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

void h (const double d[3]);
h ({1., 2., 3.}.begin());



... 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

'.'?

Yep my point exactly. The type info is there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top