|
From: | Rik |
Subject: | Re: Archetype for C++ function |
Date: | Tue, 8 Dec 2015 08:12:52 -0800 |
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); --Rik |
[Prev in Thread] | Current Thread | [Next in Thread] |