Topic: template classes
Author: simonh@swidev.demon.co.uk (Simon Huntington)
Date: Wed, 29 Sep 1993 16:07:51 +0000 Raw View
I've just read the 'Implementing class templates' article by Michael Ball in
the September '93 C++ report. It mentions that the ANSI/ISO committee is
trying to tidy up templates in respect to their use of non-extern names and
the binding of names to different symbols depending on the location of
template instatiation.
I was thinking about the example given by Michael Ball in his column. The
example he gave was as follows:
class strange
{
};
class stranger
{
enum
{
intown
};
};
class intown
{
};
template <class T> class odd : public T
{
intown a;
};
odd<strange> ts;
odd<stranger> tsr;
As he points out: The instantiations of the template-class odd implies that
member a has the following types:
odd<strange>::a has type class intown
odd<stranger>::a has type stranger::intown
Now to the point: The template-class odd is actually parameterized by two
types - namely T and intown - since intown can vary depending on T. Will such
'indirect parameterization' be disallowed in any revision of the template
standard?
Templates at the moment seem like a pre-processor extension (Borland C++
actually uses a similar technique - no syntax checking is performed until
template instantiation, not even syntax analysis). They create all-sorts of
problems for the compiler and especially any sort of high-level environment
that tries to intelligently help with the creation of template classes.
Ideally, the class-template must be parsed as much as possible when it is
first seen. This would bind any names used in the class-template to symbols.
Function definitions can be stored unparsed. When the template is
instantiated, a parameterized base class may add more members, but at least
the immediate template class members do not depend indirectly on the
parameter.
I hope this all makes sense. The current template-class specification is
causing me major headaches in the development environment for our compiler.
Comments or info appreciated.
--
Simon Huntington
Software Interrupt Developments. Leeds, UK.