initialization syntax: a = { ...

Discussion in 'C++' started by Stefan Ram, Mar 12, 2013.

  1. Stefan Ram

    Stefan Ram Guest

    To initialize an array or ::std::vector object, I have seen both

    .... a = { 1, 2, 3 };

    and also

    .... a{ 1, 2, 3 };

    Does the use of the equals sign »=« make any difference?

    (This question is not restricted to arrays and
    ::std::vectors as the type of »a«, but only asks
    about the curly braces, not parentheses.)
     
    Stefan Ram, Mar 12, 2013
    #1
    1. Advertising

  2. Stefan Ram

    Öö Tiib Guest

    On Tuesday, 12 March 2013 18:25:09 UTC+2, Stefan Ram wrote:
    > To initialize an array or ::std::vector object, I have seen both
    >
    > ... a = { 1, 2, 3 };
    >
    > and also
    >
    > ... a{ 1, 2, 3 };
    >
    > Does the use of the equals sign »=« make any difference?


    I have impression that *no* *differences* *whatsoever*.

    I do not have C++11 under hand now (only N3485) but 8.5 tells that
    'brace-or-equal-initializer' can be among other things '= braced-init-list'
    or 'braced-init-list' and both result with the initialized thing becoming
    8.4.5 "list-initialized". Standard does not seemingly make any
    differences. Both invoke either same constructor (like with std::vector) or
    do aggregate-initialization (like with std::array).

    For my taste the initialization semantics of C++11 are too loose so I
    suspect that something of it has to be adjusted in next revision.
    Lot of surprising initialization code will compile without much noise
    until then.
     
    Öö Tiib, Mar 12, 2013
    #2
    1. Advertising

  3. Stefan Ram

    Stefan Ram Guest

    Re: initialization syntax: a = { ...

    Öö Tiib <> writes:
    >For my taste the initialization semantics of C++11 are too loose so I
    >suspect that something of it has to be adjusted in next revision.
    >Lot of surprising initialization code will compile without much noise
    >until then.


    Somewhat sad is that the new »uniform initialization syntax« cannot
    be used together with the new »auto« semantics. (Well, it /can/, but
    usually not with the effect that would help a beginner.)
     
    Stefan Ram, Mar 12, 2013
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JKop
    Replies:
    10
    Views:
    950
  2. Matthias Kaeppler
    Replies:
    2
    Views:
    446
    Victor Bazarov
    Jul 18, 2005
  3. Replies:
    6
    Views:
    465
    Ron Natalie
    Dec 11, 2005
  4. toton
    Replies:
    5
    Views:
    936
    Victor Bazarov
    Sep 28, 2006
  5. Jess
    Replies:
    23
    Views:
    934
Loading...

Share This Page