On Fri, Oct 20, 2000 at 02:47:42PM -0400, Lior Silberman wrote:
> > Indeed, if the object is local to the function this is not a solution and
> > the only option is to return a const copy of the object.
> I know this _feels_ bad, but I think the most efficient implementation
> will be to handle the temporary ourselves:
>
> Menu* Menu::expand (Buffer* buf)
> {
> Menu *resulting_menu = new Menu();
> ...
> // add stuff to the new menu
> ...
> return resulting_menu;
> }
>
> Which can be used as:
>
> Menu *tmp = menu.expand();
> ...
> ...
> delete tmp;
This is a quite ugly code. I think that having "Menu const expand(Buffer *)"
would be fine: when a function returns a vector, the time for copying the
vector is no more than the time of building the vector, and usually the former
is much less then the later. So the copying time is just a small overhead.
Furthermore, compiler optimizations may prevent the copying.