Topic: why ::template in qualified id?


Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 2000/05/13
Raw View
Larry Evans <cppljevans@earthlink.net> writes:

> The ISO/IEC 14882 standard in 5.1 para 7 shows qualified-id may have
> ::template substring; however, para 7 doesn't say when this is
> useful.  Could someone please explain this to me?

It is needed on a lexical level to determine the meaning of
"<". Normally, given

  X::foo<a,b>::c

you look up X, then X::foo. If it is a template, the '<' starts the
template parameters, so this is an access to member c of X::foo<a,b>.
Otherwise, this is equivalent to (X::foo < a), (b > ::c).

Now, if X is a template parameter, foo is a dependent name, and you
can't tell whether X::foo is a template or not until instantiation
time. Unfortunately, that means you could not parse that expression.
So the rule is: If X is a template parameter, the '<' parses as
an operator. If you mean it as a template argument list, you write

  X::template foo<a,b>::c

This is similar to the typename escape.

Regards,
Martin

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Larry Evans <cppljevans@earthlink.net>
Date: 2000/05/08
Raw View
The ISO/IEC 14882 standard in 5.1 para 7 shows qualified-id may have
::template
substring; however, para 7 doesn't say when this is useful.   Could
someone please
explain this to me?

TIA.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]