🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++.leda
Article #61

Re: Advice needed

#61
From: Stefan
Date: Fri, 01 Sep 1995 07:04
45 lines
1999 bytes
Phillipp T. Schneider writes:

 >  Well, does a LEDA container really call the constructor twice for
 > every element  added?

This is in fact true for the current version. The reason is that most
insert functions use value parameter passing, as in

    list_item  append(T x) {  return list_implementation::append(Copy(x)); }

here x is a copy of the actual parameter passed to the append operation,
it is copied again to be stored in the list, and finally x is destroyed.

Of course, this can be fixed easily by using a const-reference parameter

    list_item append(const T& x) ...

The main reason why this has not been done in previous versions is a bug of g++.

I cannot convert NULL to const-ref pointer types in templates, e.g,

list<char*> L;

L.append(0);  // error if append uses const T& argument

(g++-2.6.3 has additional problems with converting number types in this context)


Nevertheless, we will soon release a new (beta-) version that replaces the
value parameters of container types by ref-parameters.

Note, that in the case of arrays (this was the original example) the problem
does not occur since the operator[] returns a reference to the array element,
which is overwritten by the assignment operator.


---


-------------------------------------------------------------------------------
Stefan N"aher                                      e-mail: stefan@mpi-sb.mpg.de
Max-Planck-Institut f"ur Informatik                phone:  +49 681 302 5420
Im Stadtwald                                       fax:    +49 681 302 5401
6600 Saarbr"ucken
Germany
Technical Details
Message-ID: <426b9l$c17@coli-gate.coli.uni-sb.de>
Path: arc1-ca.pugleaf.net!news.coli.uni-sb.de!usenet
References: <423v1r$30d@sky.itr.ch>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.coli.uni-sb.de!usenet
From: stefan@mpi-sb.mpg.de (Stefan)
Newsgroups: comp.lang.c++.leda
Subject: Re: Advice needed
Date: 1 Sep 1995 07:04:21 GMT
Organization: Max Planck Institut fuer Informatik
Message-ID: <426b9l$c17@coli-gate.coli.uni-sb.de>
References: <423v1r$30d@sky.itr.ch>
Reply-To: stefan@mpi-sb.mpg.de
NNTP-Posting-Host: robin.ag1.mpi-sb.mpg.de