std::array clear

C

Chris Forone

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

thanks, chris
 
Ö

Öö Tiib

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?
 
C

Chris Forone

Am 26.03.2013 15:01, schrieb Öö Tiib:
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.
 
Ö

Öö Tiib

Am 26.03.2013 15:01, schrieb Öö Tiib:

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

Rui Maciel

Chris said:
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
 
R

Rui Maciel

Öö Tiib said:
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
 
Ö

Öö Tiib

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

Rui Maciel

Öö Tiib said:
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
 
C

Chris Forone

Am 27.03.2013 23:59, schrieb Rui Maciel:
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
 

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,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top