More C++ 11 questions regarding array

B

bobl0456

Correct me if I am wrong, but there seems to be a least 2 short comings (at least to my view point) to using std::array :

1) no equivalent to

int myArray[] = { a very long list of values too long to conveniently count };

2) no equivalent to

void func (int[], int[][3] );

in other words, when converted to an std::array we need to specify the size of all of the dimensions of arrays passed to a function.

Am I correct on these 2 points? Or are there acceptable workarounds or syntax I am not aware of?

Thanks,
Bob
 
Ö

Öö Tiib

Correct me if I am wrong, but there seems to be a least 2 short comings (at least to my view point) to using std::array :

1) no equivalent to
int myArray[] = { a very long list of values too long to conveniently count };

Correct. That is the sole shortcoming and such long arrays are rare and
usually immutable.
2) no equivalent to

void func (int[], int[][3] );

Wrong. That declaration is /exactly/ equivalent to:

void func (int*, int(*)[3]);

No arrays are passed there, just pointers. 'std::array' can be converted
to pointer to underlying array with 'data()' but why? Just pass pointer
to 'std::array'.
in other words, when converted to an std::array we need to specify the
size of all of the dimensions of arrays passed to a function.

If the function does not know the dimensions then how can it dare to
touch the elements of array? Unsafe "hopefully it is OK"? That is common
source of errors. If it does know it then what is the problem to
indicate it in interface? If it should accept different arrays then
it can be made a template and if the arrays are made dynamically
then it is 'std::vector' (not 'std::array') that you need instead
anyway.
 
R

red floyd

Correct me if I am wrong, but there seems to be a least 2 short comings (at least to my view point) to using std::array :

1) no equivalent to

int myArray[] = { a very long list of values too long to conveniently count };
Not sure about this. I think you may need to know the size for the
template parameter.
2) no equivalent to

void func (int[], int[][3] );

template<int N>
void func(std::array<int, N>, std::array<std::array<int, N>,3>);
 
A

Alf P. Steinbach

Correct me if I am wrong, but there seems to be a least 2 short comings (at least to my view point) to using std::array :

1) no equivalent to

int myArray[] = { a very long list of values too long to conveniently count };

It's not difficult to work around, but it's definitely missing
functionality.

E.g. see my clc++ posting <url:
e.g. as
archived at
<url:
https://groups.google.com/d/msg/comp.lang.c++/0gGpBl6Bm54/3_tjMwXf2J0J>.

Which Visual C++ ICE reminds me to submit yet another bug report to
Microsoft. I just plain forgot about it. Also, reminds me of how Google
actively sabotages Usenet: in addition to dropped references, sabotage
of signature marker (you can't -- or couldn't -- post one via GG), no
threaded display, etc., Google Groups posts with QUOTED PRINTABLE. :(

2) no equivalent to

void func (int[], int[][3] );

in other words, when converted to an std::array we need to specify the size of all
of the dimensions of arrays passed to a function.
Hm.


Am I correct on these 2 points? Or are there acceptable workarounds or syntax I
am not aware of?

For initialization, see above.


Cheers & hth.,

- Alf
 

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,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top