Topic: A couple of template questions


Author: jamshid@emx.cc.utexas.edu (Jamshid Afshar)
Date: 10 Feb 1993 16:06:09 -0600
Raw View
I'm hoping someone can help me convince Borland that the following two
uses of templates are or will be legal.  ANSI "draft [what draft?]
chapter and verse" would be great, as would any information about
whether any current compilers handle it.  Thanks, your help is
appreciated.

1. The use of a template parameter in following template parameters:

 template<class T, T min, T max>
  // BC++ gives error that T previously defined
 class Range {
    T d;
 public:
    Range(T v) { if (v>=min && v<=max) d = v; else d = min; }
 };

 Range<int,1,10> score;

 // or

 template<class T, void (T:*mfp)()>
 class CB {
 public:
    CB(T* t) { (t->*mfp)(); }
 };

 class Foo {
 public:
    virtual void f();
 };

 Foo foo;
 FooCB<Foo, &Foo::f> c(&foo);

2.  A mutually-recursive use of templates.

 template<class Letter>
 class Envelope;

 template<class T>
 class Vector {
 public:
    void operator=(Envelope< Vector<T> >&);
 };

 template<class Letter>
 class Envelope : public Letter {};
    // BC++ gives error that "Vector<int> must be previously defined"

 typedef Vector<int> IntVector;

Jamshid Afshar
jamshid@emx.utexas.edu