This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: too much copy in map


Well, I'm not sure what I'm about to say will work for your
real program, but here's what you can do for this toy example:

Map::value_type v;
v.first = 1;
m.insert(v);

However, I'm not sure why you are worried about 1 extra copy.
For small objects, the extra copy gets optimized
away with a good compiler. For large objects... well you
probably shouldn't put a large object directly into the map... instead
store pointers in the map and define a custom compare operator. 


Levente Farkas wrote:
> 
> ok. then the proper question:
> why is not there a way to insert something into a map with just
> ONE copy contructor call ?
> yes you can said that this's the standard, but if there be an
> insert(const key_type&, const mapped_type&) or at least
> operator[const key_type&] could have implement in a way to call
> just one copy constructor.
> 
> > The first copy is even before you get to the insert().
> > The "Map::value_type(1,A())" creates a pair, *copying* A()
> > into the pair's data member. So there is only one copy
> > inside insert(), and that is necessary.

-- 
------------------------------------------------------------------------
 Jeremy Siek                        email: jsiek@engr.sgi.com
 Ph.D. Candidate               cell-phone: (415) 377-5814
 Univ. of Notre Dame                phone: (650) 933-8724  
 C++ Library & Compiler Group         fax: (650) 932-0127
 Silicon Graphics Inc.                www: http://www.lsc.nd.edu/~jsiek/
------------------------------------------------------------------------

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]