octave-maintainers
[Top][All Lists]
Advanced

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

Re: move constructors likely a requirement


From: Carlo De Falco
Subject: Re: move constructors likely a requirement
Date: Wed, 21 Aug 2019 05:21:19 +0000


> Il giorno 21 ago 2019, alle ore 07:03, Carlo De Falco <address@hidden> ha 
> scritto:
> 
> Hi,
> 
>> Il giorno 21 ago 2019, alle ore 00:59, Rik <address@hidden> ha scritto:
>> 
>> main ()
>> {
>>  comp_class cobj;
>> 
>>  cobj = init ();
>> 
>>  ...
>> }
>> 
>> comp_class init (void)
>> {
>>  comp_class retval;  // local variable
>> 
>>  retval.xxx = yyy;   // initialization
>>  ...
>> 
>>  return retval;      // return by value (a comp_class object)
>> }
> 
> This may be a naive comment as it is based only on your super-simplified 
> and I didn't look at the actual code, but wouldn't it be more simple and 
> efficient
> to change the code pattern above to the following?
> 
> 
> main ()
> {
>  comp_class cobj;
> 
>  init (cobj);
> 
>  ...
> }
> 
> void init (comp_class& retval)
> {
>  //comp_class retval;  // local variable, no longer needed
> 
>  retval.xxx = yyy;   // initialization
>  ...
> 
>  //return retval;      // return by value (a comp_class object), no longer 
> needed
> }
> 
> 
> this is mainly out of curiosity, sorry for the noise if it makes no sense ...
> 
> c.

OH, I see now that you had already suggested that in your message ...

>> One obvious solution would be to discard returning by value.  In that case,
>> perhaps passing a reference to the octave_value_list in to the child
>> function so that it operates directly on the only instance we care to
>> create.  But, this would mean changing a fair number of APIs and
>> potentially a lot of code refactoring.

so this answer my question already ...

c.




reply via email to

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