Christopher Smith on 8 Jul 2003 17:08:01 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [ALACPP] chapter 8


On Tue, 2003-07-08 at 09:23, Jon Stewart wrote:
> (Some of you have already heard my rant about std::map::operator[]. The 
> essential problem with it is it's a good example of how operator 
> overloading doesn't always do what you'd expect. operator[] is 
> semantically linked with C arrays, and one uses [] on arrays for r-values 
> just as much as for l-values -- however, std::map::operator[] does not 
> support r-value usage, not in the way which you'd suspect. 
> std::map::operator[] is the femme fatale of the STL, so seductive, so 
> deadly.)

I honestly am surprised when people make a mistake with operator[]. Most
of the time you look at the function prototype and realize there just
isn't a way to evaluate whether something is actually in the map or not.
However, I've been burned on this one enough to frequently dream about
putting something in my headers like, "using cbsmith::idiot_proof_map
map;"

--Chris
_______________________________________________
alacpp mailing list
alacpp@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/alacpp