View mode: basic / threaded / horizontal-split · Log in · Help
August 01, 2005
Template alias parameters
Why can't a local variable be passed to a template's alias parameter?  
Because of something like this?:

   template Foo(alias X)
   {
      static int* p = &X;
   }

If so, shouldn't this restriction be up to the programmer? How about  
adding feature "static alias" to enforce no local variables, and regular  
alias would allow them..? It seems like never allowing locals is a big  
limitation.
August 01, 2005
Re: Template alias parameters
On Mon, 01 Aug 2005 01:39:24 -0400, Vathix <chris@dprogramming.com> wrote:

> Why can't a local variable be passed to a template's alias parameter?

I guess I understand why now, but I don't know why this won't work:

   template Templ(alias val)
   {
      int Templ = val;
   }

   int cow = 3324;
   int main()
   {
      writefln(Templ!(cow));
      return 0;
   }

DMD 0.128 says "non-constant expression cow".
August 01, 2005
Re: Template alias parameters
nevermind, I got it.
Top | Discussion index | About this forum | D home