The DerivedFrom concept

By Douglas Gregor

We recently decided that we needed a new concept, DerivedFrom, to express the requirement for an inheritance relationship between two types. This concept has the following definition:

  concept DerivedFrom<typename Derived, typename Base> { /*unspecified*/ }

DerivedFrom is a compiler-support concept, like SameType. We expect that most of its uses will be to intermingle the object-oriented and generic programming facilities of C++0x, e.g.,

  template<typename T>
  requires DerivedFrom<T, Shape>
  void draw(T& shape) {
    // Can use Shape's member functions via "shape" object.
  }

DerivedFrom is now supported (albeit “lightly tested”) in the development version of ConceptGCC.

Leave a Reply