Using std::xxx routines from <algorithm>?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using std::xxx routines from <algorithm>?

Rik-4
jwe,

I noticed in your last cset:

      for (octave_idx_type i = 0; i < nz; i++)
        r[i] = 0;

Would it be clearer to start using routines from std::algorithm for fills
and copies?

In this case one could write something like this:

std::fill_n (r, nz, 0);

There are loads of other simple loops that might be replaced.  Here is one
from dim-vector.h

  octave_idx_type *clonerep (void)
  {
    int l = ndims ();

    octave_idx_type* r = newrep (l);

    for (int i = 0; i < l; i++)
      r[i] = rep[i];

    return r;
  }

where the replacement might be

std::copy_n (rep, l, r);

Just an idea,
Rik


Reply | Threaded
Open this post in threaded view
|

Re: Using std::xxx routines from <algorithm>?

John W. Eaton
Administrator
On 04/15/2017 05:51 PM, Rik wrote:

> I noticed in your last cset:
>
>       for (octave_idx_type i = 0; i < nz; i++)
>         r[i] = 0;
>
> Would it be clearer to start using routines from std::algorithm for fills
> and copies?

Yes, I agree it would be better to replace the explicit loops with calls
to std functions.

jwe