Related articles |
---|
C++ Template implementation bfahle@migratec.com (Bill Fahle) (1998-04-21) |
Re: C++ Template implementation leichter@smarts.com (Jerry Leichter) (1998-04-27) |
Re: C++ Template implementation jrw@pobox.com (John Williams) (1998-04-27) |
From: | "John Williams" <jrw@pobox.com> |
Newsgroups: | comp.compilers |
Date: | 27 Apr 1998 23:30:58 -0400 |
Organization: | The University of Texas at Austin, Austin, Texas |
References: | 98-04-086 |
Keywords: | C++, parse |
Bill Fahle wrote in message 98-04-086...
>template_class_name::= template_name "<" List(template_arg) ">".
>
>template_arg::= expression | type_name.
>
>b) Why are expressions necessary to the template_arg? I've never seen
>this in practice, and I'm not sure of the semantics. These seem to
>cause a lot of the conflicts I experience, because of the >
>ambiguity. A general expression would indeed be ambiguous:
>
>SpecificList<Specific *, a>b > m_specificList;
An expression argument can be any compile-time constant. The problem with
ambiguity is solved by adding parentheses:
SpecificList<Specific *, (a>b) > m_specificList;
A case where you might see this in practice would be a fixed-size template
data structure:
template<class T, int M, int N>
class Matrix { private: T data[M*N]; ... };
Matrix<int, 3, 2> x; // x is a 3x2 matrix of integers
This is just the tip of the iceberg, though. To see some uses of templates
that will make your head spin, look at Blitz++:
http://seurat.uwaterloo.ca/blitz/
jw
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.