Re: Basic C++ question

2000-10-23 Thread Lars Gullik Bjønnes
Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes: | > "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes: | | Lars> There is nothing "unclean" about passing a ref to vector, but a | Lars> iterator is also nice. | | I mean we are building in memory a large structure just for the | purpo

Re: Basic C++ question

2000-10-23 Thread Lars Gullik Bjønnes
Lior Silberman <[EMAIL PROTECTED]> writes: | > 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 stat

Re: Basic C++ question

2000-10-23 Thread Jean-Marc Lasgouttes
> "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes: Lars> There is nothing "unclean" about passing a ref to vector, but a Lars> iterator is also nice. I mean we are building in memory a large structure just for the purpose of iterating over it later. JMarc

Re: Basic C++ question

2000-10-23 Thread Lars Gullik Bjønnes
Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes: | > "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes: | | Lars> It breaks the "I allocate, I deallocate" idom. | | Lars> I'd rather see a Menu & passed in that case. That is the clean | Lars> way of avoiding a copy. | | That's what I

Re: Basic C++ question

2000-10-23 Thread Jean-Marc Lasgouttes
> "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes: Lars> It breaks the "I allocate, I deallocate" idom. Lars> I'd rather see a Menu & passed in that case. That is the clean Lars> way of avoiding a copy. That's what I did, but I wondered whether it was a good idea. Another (cleaner?

Re: Basic C++ question

2000-10-23 Thread Juergen Vigna
On 20-Oct-2000 Lior Silberman wrote: > Menu *tmp = menu.expand(); > ... > delete tmp; IMO that this is not time critical code! So I would prefer the cleaner (and may be slower) solution! Jürgen -- -._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._ Dr. Jürgen Vigna

Re: Basic C++ question

2000-10-22 Thread Lior Silberman
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

Re: Basic C++ question

2000-10-22 Thread Lars Gullik Bjønnes
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

Re: Basic C++ question

2000-10-22 Thread Lars Gullik Bjønnes
Lior Silberman <[EMAIL PROTECTED]> writes: | 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 m

Re: Basic C++ question

2000-10-21 Thread Baruch Even
As I said in another e-mail I didn't notice this is regarding an object created inside the function and local to it. As usual C++ has some dark sides to it and references may be just as evil as pointers. This is just such a case. I haven't looked at the questioned code so I cant offer a real sugg

Re: Basic C++ question

2000-10-21 Thread Andre Poenitz
> If it's a large object that has long c-tor time the best method is to > return a const refernce as in: Menu const & expand(Buffer *) const; You are not suggesting to return a reference to a local variable, are you? If so, this is the most wicked suggestion ever made - including those made on a

Re: Basic C++ question

2000-10-21 Thread Andre Poenitz
> Well, this is a case of the blind leading the blind... the C++ gurus will > know, but I'm pretty sure that is referenced counted. My guess is > that all STL containers are. There is no requirement in the Standard. >From what I take from /usr/include/g++-3/, strings are reference counted for

Re: Basic C++ question

2000-10-21 Thread Andre Poenitz
> And is the vector class reference-counted? I guess the answer is no... I think I have seen no reqiurement that it be not reference counted, but I have never seen a reference counted implementation either. > Am I the only one finding that this is stupid? No. It is so common that it even got a

Re: Basic C++ question

2000-10-21 Thread Dekel Tsur
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 t

Re: Basic C++ question

2000-10-20 Thread Baruch Even
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 m

Re: Basic C++ question

2000-10-20 Thread Lior Silberman
On Fri, 20 Oct 2000, Baruch Even wrote: > On Fri, 20 Oct 2000, Angus Leeming wrote: > > > On Fri, 20 Oct 2000, Baruch Even wrote: > > > [on the topic of returning large objects from a function] > > > > > > If it's a large object that has long c-tor time the best method is to > > > return a cons

Re: Basic C++ question

2000-10-20 Thread Baruch Even
On Fri, 20 Oct 2000, Angus Leeming wrote: > On Fri, 20 Oct 2000, Baruch Even wrote: > > [on the topic of returning large objects from a function] > > > > If it's a large object that has long c-tor time the best method is to > > return a const refernce as in: Menu const & expand(Buffer *) const; >

Re: Basic C++ question

2000-10-20 Thread Angus Leeming
On Fri, 20 Oct 2000, Baruch Even wrote: > On 20 Oct 2000, Jean-Marc Lasgouttes wrote: > > The method Menu::expand in Menubackend.C has the following signature: > > > > /// Expands some special entries of the menu > > /** The entries with the following kind are exanded to a > >

Re: Basic C++ question

2000-10-20 Thread Baruch Even
On 20 Oct 2000, Jean-Marc Lasgouttes wrote: > > The method Menu::expand in Menubackend.C has the following signature: > > /// Expands some special entries of the menu > /** The entries with the following kind are exanded to a > sequence of Command MenuItems: Lastfile

Re: Basic C++ question

2000-10-20 Thread Baruch Even
On Fri, 20 Oct 2000, Angus Leeming wrote: > On Fri, 20 Oct 2000, Jean-Marc Lasgouttes wrote: > > > "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes: > > > > Angus> Things are always copied on return. That's why things like > > Angus> reference counters were invented; the main class holds j

Re: Basic C++ question

2000-10-20 Thread Angus Leeming
On Fri, 20 Oct 2000, Jean-Marc Lasgouttes wrote: > > "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes: > > Angus> Things are always copied on return. That's why things like > Angus> reference counters were invented; the main class holds just a > Angus> pointer that points to the data struct

Re: Basic C++ question

2000-10-20 Thread Jean-Marc Lasgouttes
> "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes: Angus> Things are always copied on return. That's why things like Angus> reference counters were invented; the main class holds just a Angus> pointer that points to the data structure. Only the pointer is Angus> then copied on return. An

Re: Basic C++ question

2000-10-20 Thread Angus Leeming
On Fri, 20 Oct 2000, Jean-Marc Lasgouttes wrote: > The method Menu::expand in Menubackend.C has the following signature: > > /// Expands some special entries of the menu > /** The entries with the following kind are exanded to a > sequence of Command MenuItems: Lastfile

Basic C++ question

2000-10-20 Thread Jean-Marc Lasgouttes
The method Menu::expand in Menubackend.C has the following signature: /// Expands some special entries of the menu /** The entries with the following kind are exanded to a sequence of Command MenuItems: Lastfiles, Documents, ViewFormats, ExportFormats, Upd