From -2699724164613004416
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,c0e61b6a667823c0
X-Google-Attributes: gidf78e5,public
From: hinnant@_anti-spam_lightlink.com (Howard Hinnant)
Subject: Re: no const operator[] in STL map?
Date: 1999/01/24
Message-ID: <hinnant-2401991054050001@isdn3-17.lightlink.com>#1/1
X-Deja-AN: 436366901
X-NNTP-Posting-Host: 205.232.34.48
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <916993358.766341@aloomba.aaii.oz.au> <slrn7ai4q5.9dj.sbnaran@fermi.ceg.uiuc.edu> <36AA5AA6.2CC30DA4@ibm.net>
X-UID: 0000000001
X-Status: $$$T
X-Trace: 24 Jan 1999 10:53:59 -0500, 205.232.34.48
Organization: Lightlink Internet
Newsgroups: comp.std.c++
Originator: clamage@taumet


In article <36AA5AA6.2CC30DA4@ibm.net>, bijuthom@ibm.net wrote:

> Does it mean that the mapped_type stored in a map should always have a
> default constructor?

Yes, if you want to use operator[].

> If I don't have a default constructor for the
> mapped_type, is there any way for me to specify the value from which the
> mapped_type object can be copy-constructed. (For example, like in the
> constructor for vector.)

No.  Here is the standard-suggested implementation:

T& operator[](const key_type& x);

-1- Returns: (*((insert(make_pair(x, T()))).first)).second. 

-Howard


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




