Generic programming [Musser-Stepanov] offers the ability to parameterize functions and classes with arbitrary data types. This new
technique allows us to focus on the nature of algorithms rather than on their implementations for special types. Unfortunately, in a
language like C++ it is not always possible to use parameterization : For example, virtual functions cannot be parameterized
([ANSI-CPP] 14.5.2). Furthermore, the primitive data types often don't integrate very well into a system of derived classes. This article
describes one solution to this problem: a simple and elegant wrapper class which can hold arbitrary data types and can be used to pass
these objects between different program units while maintaining type safety.
...
Postscript Version (138kb),
gziped Postscript Version (59kb),
Online Version
(Notice: These links reference a somewhat corrected and extended version of
the article published in the January 2000 issue of
"C++ Report")
The source code presented in the paper can be downloaded here. The main files
are Value.hpp and
Value.cpp.
Value_void.hpp and
Value_VTable.hpp are the
alternative Value class implementations with 'void pointers' and the
'method jump table' respectively described in section 4.5 of the paper.
The file Value.tgz contains all the
files in one archive.
26.07.2005: Today I uploaded some slightly revised
versions of Value.hpp,
Value.cpp,
Value_void.hpp and
Value_VTable.hpp which have been tested to compile and run with g++ 3.4, g++ 4.0 and cl 13.10.3077 (which is the command line C++ compiler from the Microsoft Visual C++ Toolkit 2003). Again you can also get all the files together in one archive: Value.zip