Topic: A problem with templates...


Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Sun, 20 Feb 1994 23:00:07 GMT
Raw View
In article <1994Feb7.053754.22378@cs.cornell.edu> moudgill@cs.cornell.edu ( Mayan Moudgill) writes:
>
>[Note: I posted something similar earlier, but got a profound silence...]
>
>Template classes can have non-type parameters, as in
>
>   template class Vector< class T, int length>;
>
>Unfortunately, it is impossible to write _ANY_ non-member functions that can use
>these objects. This follows from the fact that template functions can only have
>types as parameters. The following, for instance is illegal:
>
>   template <class T, int length> ostream& operator<<(ostream&, Vector<T, length>&);
>
>So:
>1. Is there a work-around?
>2. If not, would this be considered to be a problem?
>3. If so, have there been any proposals to fix it?

 Fixed at San Jose, where a MAJOR revision of the
template system occured. You can now write, if you have
a super up to date compiler <grin>:

 template <class T, class Q, int x=5> void f() {}
 f<int,long>(); // fine: explicit qualification


--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,      CSERVE:10236.1703
        6 MacKay St ASHFIELD,     Mem: SA IT/9/22,SC22/WG21
        NSW 2131, AUSTRALIA




Author: jhs@edg.com (John H. Spicer)
Date: Wed, 9 Feb 1994 14:01:38 GMT
Raw View
In article <1994Feb7.053754.22378@cs.cornell.edu> moudgill@cs.cornell.edu ( Mayan Moudgill) writes:
>
>[Note: I posted something similar earlier, but got a profound silence...]
>
>Template classes can have non-type parameters, as in
>
>   template class Vector< class T, int length>;
>
>Unfortunately, it is impossible to write _ANY_ non-member functions that can use
>these objects. This follows from the fact that template functions can only have
>types as parameters. The following, for instance is illegal:
>
>   template <class T, int length> ostream& operator<<(ostream&, Vector<T, length>&);
>
>So:
>1. Is there a work-around?
>2. If not, would this be considered to be a problem?
>3. If so, have there been any proposals to fix it?
>
>Thanks!
>:)
>Mayan


Support for nontype parameters in function templates has recently (11/93)
been adopted by the ANSI/ISO C++ committee.  The feature was added to
solve exactly this kind of problem.

John Spicer
Edison Design Group
jhs@edg.com