More C++ 11 questions regarding array

Discussion in 'C++' started by bobl0456@gmail.com, Oct 21, 2013.

  1. Guest

    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
     
    , Oct 21, 2013
    #1
    1. Advertising

  2. Öö Tiib Guest

    On Monday, 21 October 2013 22:35:43 UTC+3, 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.
     
    Öö Tiib, Oct 21, 2013
    #2
    1. Advertising

  3. red floyd Guest

    On 10/21/2013 12:35 PM, 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>);
     
    red floyd, Oct 21, 2013
    #3
  4. On 21.10.2013 21:35, 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:>, 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
     
    Alf P. Steinbach, Oct 21, 2013
    #4
    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. TaeHo Yoo

    Questions regarding CR.NET

    TaeHo Yoo, Aug 12, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    603
    Natty Gur
    Aug 15, 2003
  2. Michael
    Replies:
    4
    Views:
    468
    Matt Hammond
    Jun 26, 2006
  3. Ali Syed
    Replies:
    3
    Views:
    582
    Mark McIntyre
    Oct 13, 2004
  4. Robert Klemme

    With a Ruby Yell: more, more more!

    Robert Klemme, Sep 28, 2005, in forum: Ruby
    Replies:
    5
    Views:
    237
    Jeff Wood
    Sep 29, 2005
  5. bbiker
    Replies:
    3
    Views:
    124
    bbiker
    Jun 11, 2009
Loading...

Share This Page