www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Template scope 'promotion'

reply Andy Friesen <andy ikagames.com> writes:
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
Jun 26 2004
parent reply Norbert Nemec <Norbert.Nemec gmx.de> writes:
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.
Jun 27 2004
next sibling parent Andy Friesen <andy ikagames.com> writes:
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
Jun 27 2004
prev sibling parent Regan Heath <regan netwin.co.nz> writes:
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/
Jun 27 2004