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

Discussion in 'C++' started by pietro.cerutti, Feb 19, 2014.

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


    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?

    pietro.cerutti, Feb 19, 2014
    1. Advertisements

  2. of course I meant f(..);
    pietro.cerutti, Feb 19, 2014
    1. Advertisements

  3. 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());
    Pietro Cerutti, Feb 20, 2014
  4. Yep my point exactly. The type info is there.
    Pietro Cerutti, Feb 20, 2014
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.