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:03:45 +0000

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.


reply via email to

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