Workspace 6.21.5
Public Member Functions | List of all members
IsDerivedFrom< Derived, Base > Class Template Reference

Define a constraints base class with a testable value. More...

#include <Workspace/Application/LanguageUtils/classconstraints.h>

Inheritance diagram for IsDerivedFrom< Derived, Base >:
[legend]

Public Member Functions

 IsDerivedFrom ()
 

Detailed Description

template<typename Derived, typename Base>
class CSIRO::Application::IsDerivedFrom< Derived, Base >

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:

template<typename T>
class X : IsDerivedFrom<T,Base> {
// ...
}
Define a constraints base class with a testable value.
Definition: classconstraints.h:63
@ X
Map the vector's X component. The Y and Z components are ignored.
Definition: vectormapping.h:47

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

Constructor & Destructor Documentation

◆ IsDerivedFrom()

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