Workspace 6.21.5
|
Define a constraints base class with a testable value. More...
#include <Workspace/Application/LanguageUtils/classconstraints.h>
Public Member Functions | |
IsDerivedFrom () | |
Taken from "Extensible Templates: Via Inheritance or Traits?", Herb Sutter, C/C++ Users Journal, Feb 2002, pp28-38. This is the "IsDerivedFrom2" class of that article.
To use this class, make it a base class of the template object you want to enforce a condition on. For example:
This would ensure that T is derived from Base. It would perform the check at compile-time and create no code in the final binary (assuming compiler optimizations are turned on).
|
inline |
The default constructor forces a compile-time test on the validity of whatever is in Constraints(). Therefore, to enforce the constraints, make the compiler construct an IsDerivedFrom object. This is most easily done by making it a base class of an object. We try to suppress the unused variable warning if we know how to do it for this compiler.