Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > std::array clear

Reply
Thread Tools

std::array clear

 
 
Chris Forone
Guest
Posts: n/a
 
      03-26-2013
is it guaranteed, that std::array<std::array<float, 4>, 4> var = {};
sets all 16 values to 0.0f?

thanks, chris
 
Reply With Quote
 
 
 
 
Tiib
Guest
Posts: n/a
 
      03-26-2013
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?
 
Reply With Quote
 
 
 
 
Chris Forone
Guest
Posts: n/a
 
      03-27-2013
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.
 
Reply With Quote
 
Tiib
Guest
Posts: n/a
 
      03-27-2013
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.
 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      03-27-2013
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
 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      03-27-2013
Öö 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
 
Reply With Quote
 
Tiib
Guest
Posts: n/a
 
      03-28-2013
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".
 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      03-28-2013
Öö 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
 
Reply With Quote
 
Chris Forone
Guest
Posts: n/a
 
      03-28-2013
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox - Clear History? Paull Firefox 7 08-24-2012 04:49 PM
Response.Clear() doesn't clear David ASP .Net 2 01-31-2008 08:32 PM
Unrecognized element 'add' after <clear></clear> InvalidLastName ASP .Net Web Services 3 03-06-2007 03:07 AM
How Do I Clear search items? Wabby Wabusha Firefox 1 10-26-2004 08:36 PM



Advertisments