std::array clear

Discussion in 'C++' started by Chris Forone, Mar 26, 2013.

  1. Chris Forone

    Chris Forone Guest

    is it guaranteed, that std::array<std::array<float, 4>, 4> var = {};
    sets all 16 values to 0.0f?

    thanks, chris
    Chris Forone, Mar 26, 2013
    #1
    1. Advertising

  2. Chris Forone

    Öö Tiib Guest

    On Tuesday, 26 March 2013 15:21:49 UTC+2, Chris Forone wrote:
    > is it guaranteed, that std::array<std::array<float, 4>, 4> var = {};
    >
    > sets all 16 values to 0.0f?


    It is required by C++11 standard. That (like any documentation) does not
    always guarantee that software (compiler) is not defective. Do you have
    compiler that does not?
    Öö Tiib, Mar 26, 2013
    #2
    1. Advertising

  3. Chris Forone

    Chris Forone Guest

    Am 26.03.2013 15:01, schrieb Öö Tiib:
    > On Tuesday, 26 March 2013 15:21:49 UTC+2, Chris Forone wrote:
    >> is it guaranteed, that std::array<std::array<float, 4>, 4> var = {};
    >>
    >> sets all 16 values to 0.0f?

    >
    > It is required by C++11 standard. That (like any documentation) does not
    > always guarantee that software (compiler) is not defective. Do you have
    > compiler that does not?
    >

    i use visual studio express 2012 and it does right but i want maximum
    portability.
    Chris Forone, Mar 27, 2013
    #3
  4. Chris Forone

    Öö Tiib Guest

    On Wednesday, 27 March 2013 09:56:50 UTC+2, Chris Forone wrote:
    > Am 26.03.2013 15:01, schrieb Öö Tiib:
    > > On Tuesday, 26 March 2013 15:21:49 UTC+2, Chris Forone wrote:
    > >> is it guaranteed, that std::array<std::array<float, 4>, 4> var = {};
    > >>
    > >> sets all 16 values to 0.0f?

    > >
    > > It is required by C++11 standard. That (like any documentation) does not
    > > always guarantee that software (compiler) is not defective. Do you have
    > > compiler that does not?

    >
    > i use visual studio express 2012 and it does right but i want maximum
    > portability.


    Maximum portability you won't get since 'std::array' has been is in C++
    only for 2 years. Several compilers for more exotic platforms have
    life-cycle that is longer than 2 years.
    However, I have used 'boost::array' (it is same basically) for about 10
    years and have never experienced problems with such initialization.
    Öö Tiib, Mar 27, 2013
    #4
  5. Chris Forone

    Rui Maciel Guest

    Chris Forone wrote:

    > is it guaranteed, that std::array<std::array<float, 4>, 4> var = {};
    > sets all 16 values to 0.0f?


    As far as I can tell, it is guaranteed. The C++11 standard (well, N3242)
    defines a std::array as an aggregate that can be initialized with an
    initializer list. Then, in 8.5.4 3 of that standard it is said that an
    aggregate initialization with an empty initialization list ends up setting
    all members to zero. Then, as your example consists of an aggregate which
    contains sub-aggregates, 8.5.1 8 essentially states that the initializer
    clause for each sub-member can be omitted if you an empty initializer list
    is used.


    Rui Maciel
    Rui Maciel, Mar 27, 2013
    #5
  6. Chris Forone

    Rui Maciel Guest

    Öö Tiib wrote:

    > That (like any documentation) does not
    > always guarantee that software (compiler) is not defective.


    If the compiler is defective then that's a compiler issue, not a language
    issue. File a bug report with the compiler vendor.


    Rui Maciel
    Rui Maciel, Mar 27, 2013
    #6
  7. Chris Forone

    Öö Tiib Guest

    On Thursday, 28 March 2013 01:07:01 UTC+2, Rui Maciel wrote:
    > Öö Tiib wrote:
    > > That (like any documentation) does not
    > > always guarantee that software (compiler) is not defective.

    >
    > If the compiler is defective then that's a compiler issue, not a language
    > issue. File a bug report with the compiler vendor.


    If you can not read then perhaps stop trying to. OP asked for "maximum
    portability" not for "if it is kosher by language rules".
    Öö Tiib, Mar 28, 2013
    #7
  8. Chris Forone

    Rui Maciel Guest

    Öö Tiib wrote:

    > On Thursday, 28 March 2013 01:07:01 UTC+2, Rui Maciel wrote:
    >> Öö Tiib wrote:
    >> > That (like any documentation) does not
    >> > always guarantee that software (compiler) is not defective.

    >>
    >> If the compiler is defective then that's a compiler issue, not a language
    >> issue. File a bug report with the compiler vendor.

    >
    > If you can not read then perhaps stop trying to. OP asked for "maximum
    > portability" not for "if it is kosher by language rules".



    Are you aware of what a standard is and what it is used for? When someone
    seeks behaviour which has been standardized, that someone looks up to the
    behavior as defined in a specific standard. This discussion is about a
    container which had its interface and behaviour standardized in the form of
    an ISO standard. Are you aware of what that means?

    The language is defined by the standard, not the whims and lapses of whoever
    develops an implementation. When someone wants portability, the standard is
    targetted. That's what the standard is for. If an implementation fails to
    comply with the standard, it is broken and needs to be fixed. Do you find
    this hard to understand?

    And finally, are you aware of any compiler whose makers claim it to be
    C++11-compliant but happens to have a broken std::array? If you are unaware
    then what exactly are you whining about?


    Rui Maciel
    Rui Maciel, Mar 28, 2013
    #8
  9. Chris Forone

    Chris Forone Guest

    Am 27.03.2013 23:59, schrieb Rui Maciel:
    > Chris Forone wrote:
    >
    >> is it guaranteed, that std::array<std::array<float, 4>, 4> var = {};
    >> sets all 16 values to 0.0f?

    >
    > As far as I can tell, it is guaranteed. The C++11 standard (well, N3242)
    > defines a std::array as an aggregate that can be initialized with an
    > initializer list. Then, in 8.5.4 3 of that standard it is said that an
    > aggregate initialization with an empty initialization list ends up setting
    > all members to zero. Then, as your example consists of an aggregate which
    > contains sub-aggregates, 8.5.1 8 essentially states that the initializer
    > clause for each sub-member can be omitted if you an empty initializer list
    > is used.
    >
    >
    > Rui Maciel
    >

    thanks.

    cheers, chris
    Chris Forone, Mar 28, 2013
    #9
    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. Chris Mantoulidis

    std::cin.ignore() and std::cin.clear()

    Chris Mantoulidis, Jan 6, 2004, in forum: C++
    Replies:
    5
    Views:
    17,131
    Kevin Saff
    Jan 6, 2004
  2. Peter Jansson
    Replies:
    5
    Views:
    6,263
    Ivan Vecerina
    Mar 17, 2005
  3. Vinu
    Replies:
    4
    Views:
    342
    Jim Langston
    Jul 7, 2005
  4. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    994
    Mark Fitzpatrick
    Jan 31, 2008
  5. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    924
    Steven Cheng[MSFT]
    Mar 6, 2007
Loading...

Share This Page