must_have_base Struct Template Reference
[Constraints Utility Library]

#include <stlsoft/util/constraints.hpp>

List of all members.

Detailed Description

template<typename D, typename B>
struct stlsoft::must_have_base< D, B >

Constraint to ensure that the one type is convertible to another via inheritance.

D The derived type
B The base type
It may be used as follows:
  class Parent {};
  class Child : public Parent {};
  class Orphan {};

  stlsoft::must_have_base<Parent, Parent>();  // Ok
  stlsoft::must_have_base<Child, Parent>();   // Ok
  stlsoft::must_have_base<Child, Child>();    // Ok
  stlsoft::must_have_base<Child, Parent>();   // Compile error!

  stlsoft::must_have_base<Orphan, Parent>();  // Compile error!
  stlsoft::must_have_base<Orphan, Child>();   // Compile error!
  stlsoft::must_have_base<Parent, Orphan>();  // Compile error!
  stlsoft::must_have_base<Child, Orphan>();   // Compile error!

This is borrowed from Bjarne Stroustrup's idea as posted to comp.lang.c++.moderated 17th February 2001.
See also:

The documentation for this struct was generated from the following file:

Generated on Thu Jun 10 08:59:02 2010 for STLSoft by  doxygen 1.5.6