Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

More C++ 11 questions regarding array

46 views
Skip to first unread message

bobl...@gmail.com

unread,
Oct 21, 2013, 3:35:43 PM10/21/13
to
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

unread,
Oct 21, 2013, 4:29:41 PM10/21/13
to
On Monday, 21 October 2013 22:35:43 UTC+3, bobl...@gmail.com wrote:
> 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.

red floyd

unread,
Oct 21, 2013, 4:33:00 PM10/21/13
to
On 10/21/2013 12:35 PM, bobl...@gmail.com wrote:
> 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>);



Alf P. Steinbach

unread,
Oct 21, 2013, 4:36:03 PM10/21/13
to
On 21.10.2013 21:35, bobl...@gmail.com wrote:
> 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:
news:a12f9f2e-e414-45e8...@googlegroups.com>, 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

0 new messages