www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Template alias parameters

reply Vathix <chris dprogramming.com> writes:
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.
Jul 31 2005
parent reply Vathix <chris dprogramming.com> writes:
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".
Aug 01 2005
parent Vathix <chris dprogramming.com> writes:
nevermind, I got it.
Aug 01 2005