Topic: Why no constraint templates ?


Author: croizier@rennes.enst-bretagne.fr (Valery Croizier)
Date: 1995/10/05
Raw View
Sometimes, I wish I could oblige the user of a template class to
inherit from a given class:

class Shape {
public:
  void draw() = 0;
};

template <class T inherits from Shape>
class ListOfShape {
public:
// ...
  void drawAll();
};

Of course, the above is just an example, and we can find many other
use of such a kind of template.  The main advantage is compile-time
type-checking: when you write the implementation of the template class,
you cannot call a bad method.

  o Is there a way I have not noticed to do this ?
  o Does anybody know the reason why the team working on the
standard rejected this feature ?

--
Valery

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]