Jon Stewart on 8 Jul 2003 16:24:01 -0000


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

Re: [ALACPP] chapter 8


> I would never use the factory template in my code. It is a degenerate
> abstraction over a map template. I would always just use a map
> directly. I am calling it degenerate because it does not add any
> additional functionality or abstract away any of the details of a map.
> All it does is rename the interface methods: map::insert becomes
> Factory::Register, map::erase become Factory::Unregister, and map::find
> becomes Factory::CreateObject. What's the point?


In addition to Arlo's insights, one useful side effect of wrapping a 
std::map is hiding operator[]!

(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.)



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