Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 27, 2004 Template scope 'promotion' | ||||
---|---|---|---|---|
| ||||
Currently, if a template block has exactly one declaration whose name is the same as that of the enclosing template, that declaration is promoted to 'become' the template. Could this be extended to occur if a template contains only one *public* declaration? It would be useful, among other things, for making temporary aliases to disturbingly long template instantiations. -- andy |
June 27, 2004 Re: Template scope 'promotion' | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | Andy Friesen wrote:
> Currently, if a template block has exactly one declaration whose name is the same as that of the enclosing template, that declaration is promoted to 'become' the template.
>
> Could this be extended to occur if a template contains only one *public* declaration? It would be useful, among other things, for making temporary aliases to disturbingly long template instantiations.
Templates do not have a concept of private or public internals. Private elements in a template declaration only make sense if that template is used as mixin for a class, where the "private" template element then becomes a private class element.
|
June 27, 2004 Re: Template scope 'promotion' | ||||
---|---|---|---|---|
| ||||
Posted in reply to Norbert Nemec | Norbert Nemec wrote: > Andy Friesen wrote: > > >>Currently, if a template block has exactly one declaration whose name is >>the same as that of the enclosing template, that declaration is promoted >>to 'become' the template. >> >>Could this be extended to occur if a template contains only one *public* >>declaration? It would be useful, among other things, for making >>temporary aliases to disturbingly long template instantiations. > > > Templates do not have a concept of private or public internals. Private > elements in a template declaration only make sense if that template is used > as mixin for a class, where the "private" template element then becomes a > private class element. Right, I know. I was asking if that could be changed some. :) Looking back, it's not such a big deal. I can live without it. (FYI, here's what I wanted it for: <http://andy.tadan.us/d/tupletest.d.html>) -- andy |
June 27, 2004 Re: Template scope 'promotion' | ||||
---|---|---|---|---|
| ||||
Posted in reply to Norbert Nemec | On Sun, 27 Jun 2004 10:06:44 +0200, Norbert Nemec <Norbert.Nemec@gmx.de> wrote: > Andy Friesen wrote: > >> Currently, if a template block has exactly one declaration whose name is >> the same as that of the enclosing template, that declaration is promoted >> to 'become' the template. >> >> Could this be extended to occur if a template contains only one *public* >> declaration? It would be useful, among other things, for making >> temporary aliases to disturbingly long template instantiations. > > Templates do not have a concept of private or public internals. Private > elements in a template declaration only make sense if that template is used > as mixin for a class, where the "private" template element then becomes a > private class element. That is not 100% correct. If the element is private in the template then it cannot be accessed by the class that mixes it, example: --[a.d]-- template A(T) { public: T a; private: T b; } class B { mixin A!(int); void foo() { a = 1; b = 2; } } void main() { B b = new B(); b.foo(); } C:\Temp\delete>dmd a.d a.d(10): class B A!(int).b is private So private in a template means private to the template. In fact AFAICS there is no way to mix something to give the new object (class or struct) private members. Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ |
Copyright © 1999-2021 by the D Language Foundation