Oscar Fuentes wrote:
> "Manu \(mingw-users\)" <mingw-users@...> writes:
> > > > I was silently thinking the same. Well, if Brian switches to C++, I have
> > > > a generic linked list that may help:
> > > > http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/visual-mingw/visual-mingw/src
> > > > /
> > > >
> > > > I'm very happy with it, since it's fast, light and generic.
> > > > It wouldn't be difficult to write a stack inspired on it.
> > > > See CList.cpp, CList.h. The code is public domain.
> > >
> > > What advantage has it over std::list and other standard C++ containers?
> > Well, the origin of this CList was an article in "Programmez!" magazine
> > about doubly generic linked lists. The article by Claude Catonio started with
> > the following:
> > "If you don't like C++ templates, then you'll appreciate this article... etc..."
> > :) I've much appreciated.
> > For me, an advantage is the size of the binary.
> > OTOH, I agree that reinventing the wheel takes more time.
> > IOW, it depends what the programmer prefers, small binaries or
> > spending more time to reinvent the wheel.
> Well, having small binaries is nice, but most of the time I prefer
> techniques that maximizes my chances of releasing a correct piece of
> software within the estimated schedule.
> OTOH, I don't think that a template-based data structure similar to
> what you showed would add a significant executable file size
> overhead. The advantages related to type-safety are overwhelming,
Yes, I agree concerning type-safety.
OTOH, I also agree with the following, from the wxWindows Programmer Style Guide:
Don't use C++ templates
Besides the reasons mentioned above, template usage also makes the program compile much slower
(200%-300% is not uncommon) and their support even in the compilers which have had it for a
long time is far from perfect (the best example is probably gcc).
Workaround: The things you would like to use templates for are, most commonly, polymorphic
containers (in the sense that they can contain objects of any type without compromising C++
type system, i.e. using void * is out of question). wxWindows provides dynamic arrays and lists
which are sufficient in 99% of cases - please don't hesitate to use them. Lack of template is
not a reason to use static arrays or type-less (passing by void *) containers.
Finally, in some particular cases, with templates or not, we must use type-less data. For
example to attach a class pointer to
items in Windows common controls, like Tree Views, List Views, etc... using the lParam member.
Same if you wish to attach data to a window with SetWindowLong / GetWindowLong.
Using a base class, with different kind of derived classes is not so bad.
At least, that's a possibility.