Re: referring to enum values in a template
Re: referring to enum values in a template
- Subject: Re: referring to enum values in a template
- From: James Widman <email@hidden>
- Date: Mon, 30 Jan 2006 14:02:20 -0500
On Jan 30, 2006, at 12:29 PM, Nathan Roberts wrote:
James,
Minor nit: we say "class template" when referring to the template
(as opposed to instantiations of it). "Template class" is known
these days as a somewhat deprecated shorthand for "template
specialization". It sure does roll off the tongue more easily
though. (:
Okay, sure. So the verb form would be specialized? ("class
template errors happen during specialization")
Not...quite...
I can see I was being a little loose with my language above; I should
have said:
"we say "class template" when referring to
the template (as opposed to instantiations of it)"
^^^^^^^^^^^^^^
...should be: "(as opposed to specializations of it)"
*Instantiation* of a class template or function template is the
process by which a C++ parser generates the *definition* (the body)
of a class or function when given a complete and non-dependent
template argument list for the template, and when the use of that
template and argument list requires a definition according to the
Standard. So, we say that errors about the *class template* are
issued "at template definition time", and errors about definitions
instantiated from it are issued "at template instantiation time".**
"*specialization* of a class template" can have two meanings:
1) "specialization": a symbol (e.g., a class, a member of a class, or
a namespace-scope function) that does not depend on template
parameters and can be denoted by a template name and a template
argument list. E.g.:
template<class T> struct A { typedef typename T::__nonexistent_member
M;/* instantiation bomb */ };
A<int> *aip;
No Standard-conforming compiler will instantiate A<int> in the
example above, and yet we can speak of "the specialization A<int>".
We say that the type A<int> is "incomplete" because its definition
has not yet been instantiated or scanned from source code.
2) "specialization" (also "explicit specialization" or "partial
specialization"): a way to cause a C++ parser to use an alternative
definition (or, by only forward-declaring, to *prevent* definition)
of a symbol for some set of template argument lists. E.g.:
template<class T> struct A; // primary template
A<int> *aip;
template<> struct A <char> // explicit specialization
{ int g() { return 1; } };
A<char> ac;
int n = ac.g();
template<class T> struct A <T*> // partial specialization
{ int f() { return 0; } };
A<double*> ad;
int m = ad.f();
extern "C" int printf( const char*, ... );
int main(){ printf( "%d, %d\n", n, m ); return 0; }
Issue 1: Base classes of dependent type (or, during
instantiation, of formerly-dependent type) are not searched during
unqualified name lookup. (14.6.2p3)
Understood. Do those rule numbers (14.6.2p3, e.g.) refer to9 a
document that describes gcc's parsing mechanism? Where might I
find that?
Sorry; those are sections in ISO C++ 2003. Google:
ISO/IEC 14882-2003
I think you can get the PDF file for something like $30. Every C++
programmer should have access to a copy; often it gives you the only
way to know whether an implementation contains a bug in its
interpretation of the language.
Be sure to use <ctrl-option-command-8> when viewing in Preview for
extended periods.
Issue 2: Enums do not introduce a new scope; instead, enumeration
constants ([e0-e3] above) are injected into the scope where the
enumeration type name resides. So instead, you should use:
Got it. Thanks for a wonderfully detailed, clear explanation. Not
only do I understand, those errant lines now compile!
You're welcome. (:
**[ Note that, because template definitions may contain uses of
templates where instantiation is elicited at definition time, and
because class templates may themselves contain templates as members,
"template definition time" can occur during "template instantiation
time" and vice-versa. (: Also note: the phrases "template definition
time" and "template instantiation time" are in no way related to the
notion of "peanut butter jelly time" or to dancing bananas of any
sort. ]
James Widman
--
Gimpel Software
http://gimpel.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden