www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Local templates and alias parameters

reply "John Colvin" <john.loughran.colvin gmail.com> writes:
void main()
{
	template A(alias a)
	{
		enum A = a.stringof;
	}
	int b;
	string s = A!b;   // Error: template instance A!(b) cannot use 
local 'b' as parameter to non-global template A(alias a)
}

Bug or feature?
Jun 28 2013
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 06/28/2013 01:04 PM, John Colvin wrote:
 void main()
 {
      template A(alias a)
      {
          enum A = a.stringof;
      }
      int b;
      string s = A!b;   // Error: template instance A!(b) cannot use
 local 'b' as parameter to non-global template A(alias a)
 }

 Bug or feature?
Popular limitation: :) http://d.puremagic.com/issues/show_bug.cgi?id=5710 Ali
Jun 28 2013
parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Friday, 28 June 2013 at 23:57:30 UTC, Ali Çehreli wrote:
 On 06/28/2013 01:04 PM, John Colvin wrote:
 void main()
 {
     template A(alias a)
     {
         enum A = a.stringof;
     }
     int b;
     string s = A!b;   // Error: template instance A!(b) cannot 
 use
 local 'b' as parameter to non-global template A(alias a)
 }

 Bug or feature?
Popular limitation: :) http://d.puremagic.com/issues/show_bug.cgi?id=5710 Ali
I get that it's a problem when they are in entirely non-overlapping scopes, but when they are in the same local scope it really shouldn't be an error as there's no need for the double context pointer. Indeed, in this case there's no need for any context pointer at all, it's a purely compile-time manipulation. I'm tempted to create a separate bug report for this as it's not quite the same problem.
Jun 28 2013