Topic: Is binding only some template parameters allowed?


Author: jamesh@cs.umr.edu (James Hartley)
Date: 8 May 92 03:17:50 GMT
Raw View
In Lippman's _C++ Primer_ 2nd edition, he discusses friend declarations
between template classes (page 378) where either all parameters are
bound (mapping one template class to all instantiations of another) or
all template arguments are constrained (creating a 1:1 mapping between
instantiated classes).  Has the ANSI committee considered the case where
some arguments are bound and others not?  This would make implementation
of a matrix multiply simpler...
--
James J. Hartley               _   /| Internet: jamesh@cs.umr.edu
Department of Computer Science \'o.O'   Bitnet: jamesh@cs.umr.edu@umrvmb.bitnet
University of Missouri - Rolla =(___)=    UUCP: ...!uunet!cs.umr.edu!jamesh
"If at first you don't succeed,   U   compile, compile, again..."




Author: pete@borland.com (Pete Becker)
Date: Fri, 8 May 1992 16:34:41 GMT
Raw View
In article <5074@umriscc.isc.umr.edu> jamesh@cs.umr.edu (James Hartley) writes:
>In Lippman's _C++ Primer_ 2nd edition, he discusses friend declarations
>between template classes (page 378) where either all parameters are
>bound (mapping one template class to all instantiations of another) or
>all template arguments are constrained (creating a 1:1 mapping between
>instantiated classes).  Has the ANSI committee considered the case where
>some arguments are bound and others not?  This would make implementation
>of a matrix multiply simpler...

 It's been suggested, but it doesn't really seem necessary.  You can
do the same thing with inheritance:

 template <class T1, class T2, class T3> class C
 {
 ...
 };

 template <class T4> class BoundC : public C<int, double, T4>
 {
 ...
 };

 The only additional thing that has to be done to make this work is
to provide constructors for BoundC with the appropriate parameter lists, since
the constructors for C are not inherited.  These constructors would be
inline, and would simply forward their parameters to the appropriate
constructors in C.