octave-maintainers
[Top][All Lists]
Advanced

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

Re: Archetype for C++ function


From: John W. Eaton
Subject: Re: Archetype for C++ function
Date: Tue, 08 Dec 2015 11:21:45 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0

On 12/08/2015 11:12 AM, Rik wrote:
On 12/07/2015 04:36 PM, John W. Eaton wrote:
On 12/06/2015 11:07 PM, Rik wrote:  >> 12/6/15 >> >> jwe, >> >> The switch to 
exceptions in the core is
making the code a lot clearer, in >> my mind anyways.  I want to propose
a new archetype for C++ functions, and >> if you like it, we can
possibly have it as one of the code sprint topics. > > While we are at
it, what do you think about writing things like > >   retval = ovl
(DiagMatrix (nr, nr, 1.0), >                 Matrix (nr, nc),
 >                 DiagMatrix (nc, nc, 1.0)); > > instead    of > >
retval(2) = DiagMatrix (nc, nc, 1.0); >   retval(1) = Matrix (nr, nc);
 >   retval(0) = DiagMatrix (nr, nr, 1.0); >

I'm not too much bothered either way.  The proposed method does have the
advantage of not having to either pre-declare the size of the
octave_value_list at construction, use resize, or use indexing with the
largest value first.

I do think it is clearer that when a function is declared as "function
[x, y, z] = funcname (...)" we return the output variables in the same
order as the declaration.  In order to do that I think either we should
use the ovl() overload or use

octave_value_list retval (3);
... code ...
retval(0) = DiagMatrix (nr, nr, 1.0);
retval(1) = Matrix (nr, nc);
retval(2) = DiagMatrix (nc, nc, 1.0);

OK.

I kind of like the ovl overload.

Writing things in reverse order has always been confusing for people and it's not always simple to set the size in advance without multiple declarations of the return value.

jwe




reply via email to

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