help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Allocating N-dimensional Array in C++


From: John W. Eaton
Subject: Re: Allocating N-dimensional Array in C++
Date: Mon, 15 Mar 2010 17:30:28 -0400

On  7-Mar-2010, S ren Hauberg wrote:

| man, 08 03 2010 kl. 07:17 +0100, skrev Jaroslav Hajek:
| > On Mon, Mar 8, 2010 at 12:08 AM, S ren Hauberg <address@hidden> wrote:
| > > How about the attached changeset? With this, I can do
| > >
| > >    octave_idx_type tmp_size [] = {4, 5, 6, 7};
| > >    const dim_vector size (tmp_size, 4);
| > >    Array<double> A (size, 0);
| > >
| > > I was a bit confused about the use of the 'explicit' keyword in the
| > > other constructors. I thought this keyword only made a difference for
| > > constructors with one input argument, but I see it is used with all
| > > constructors.
| > >
| > > S ren
| > >
| > 
| > Seems OK to me.
| 
| I've pushed it.

I'm not a big fan of constructors like this because there is no way
for the constructor to ensure that the arguments are consistent.

Why not just introduce more constructors of the form

  explicit dim_vector (octave_idx_type d0, octave_idx_type d1,
                       octave_idx_type d2, octave_idx_type d3)
    : rep (newrep (4))
  {
    rep[0] = d0;
    rep[1] = d1;
    rep[2] = d2;
    rep[3] = d3;
  }

up to say 7 dimensions?  I Would think that would cover most cases,
and to me, it seems just as easy to write

  Array<double> A (dim_vector (4, 5, 6, 7), 0);

as what you have above.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]