On 22 Oct 2000, Lars Gullik Bjønnes wrote:

> Baruch Even <[EMAIL PROTECTED]> writes:
> 
> | On Fri, 20 Oct 2000, Lior Silberman wrote:
> | 
> | > 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;
> | 
> | At least if we go this way we should use auto_ptr<Menu> as in:
> | {
> |    auto_ptr<Menu> tmp( menu.expand() );
> |    ...
> |    ...
> | }
> | 
> | This is also better since we reduce the risk of exceptions and/or returns
> | before the delete.
> 
> If we want to do this exception safe we have to do something like:
> 
> build_men(Menu & m) {
>         Menu me;
>         ...; // populate me
>         m.swap(me);
> }
> 
> to avoid half populated objects, and objects in unknown state.
> 
>         Lgb
> 
> 

I think we return here to the current situation:
(which does avoid all the copying)

void Menu::expand (Menu & tomenu, Buffer * buf)
{
        // populate tomenu
}

Lior.

Reply via email to