This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
too much copy in map
- To: stl at sgi dot com, libstdc++ at sourceware dot cygnus dot com
- Subject: too much copy in map
- From: Levente Farkas <!spam-lfarkas at mindmaker dot hu>
- Date: Thu, 09 Mar 2000 13:06:29 +0100
- Organization: Mindmaker Ltd.
- Reply-To: lfarkas at mindmaker dot hu
hi,
why is there so much contructor call in map. if I'd like to insert a new
element into a map it's call too copy constructor at least. why ?
---------------
#include <map>
#include <iostream>
using namespace std;
struct A
{
A() { cout << "def "; }
A(const A&) { cout << "copy "; }
};
int main()
{
typedef map<int, A> Map;
Map m;
m.insert(Map::value_type(1, A()));
A& a = m[2];
m.insert(m.end(), Map::value_type(3, A()));
return 0;
}
---------------
the output is:
------
def copy copy def copy copy def copy copy
------
all of these 3 insertion call 2 times the copy constuctor.
it can't be implemeted just 1 cc call for an insertation ?
or is there any way to do so ?
thnaks.
-- lfarkas
"The only thing worse than not knowing the truth is
ruining the bliss of ignorance."