Topic: Permit "template" qualification to distinguish name-as-template from name-as-instantiated-class
Author: "Ivan Godard" <igodardA@TpacbellDO.Tnet>
Date: 1 Jul 2004 20:45:02 GMT Raw View
Extension proposal. Consider:
template<typename X, template<typename> class Y> struct A{};
template<typename T> struct B : A<T, B> {B(): A<T, ::B>(){} }:
In this context, let us also permit:
template<typename X, template<typename> class Y> class A{};
template<typename T> struct B : A<T, B> {B(): A<T, template B>(){} }:
There is no machinery extension here, because "template" qualification
already exists; the idiom just lets the compiler choose an interpretation
for "B" as a template rather than the usual interpretation as a type.
Nuisance in the compiler should be minor, and there seems no ambiguity.
The advantage of the proposal shows when struct B is itself declared locally
in another class or namespace; then "::B" must have a proper
name-qualification chain, something like "::Namespace::Struct<T,
U>::Class<V, W>::B" perhaps. This namechain, besides being typically
unreadable, has to be changed whenever the class nesting structure changes,
whereas "template B" does not.
The example arises from actual code using the common "curiously recursive"
use of a derived class as an argument to a templated base class to implement
"mixin"-style interfaces. When the derived is itself a template, then the
base takes a template argument and it is the derived -template- rather than
the particular derived class that must be passed, leading to the example.
Ivan
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]