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]

too much copy in map


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."

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