Boost logo

Boost Users :

Subject: Re: [Boost-users] [optional] boost improvement over std::map, the default initialization requirement
From: Dave Abrahams (dave.abrahams_at_[hidden])
Date: 2010-07-18 07:48:06


On Sunday, July 18, 2010, alfC <alfredo.correa_at_[hidden]> wrote:
> Hi,
>  The STL has an implementation of std::map<T1, T2>. It has some
> designs drawbacks in my opinion. For example, the fact that T2 has to
> have a default copy constructor. Even if for T2, by design, doesn't
> make sense to have a copy constructor.
>
> The problem boils down to the fact that, in the STL design, if an key
> element of the map is referenced with the operator[] and it doesn't
> exist then an 'empty' (default) object T2 is created. In my opinion
> this feature is independent of the other features of a map. For
> example if the element doesn't exists and the context is not
> assignment then it could give an exception.

Easy solution: use find and insert instead of operator[]. HTH

-- 
--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net