Error in "Template Alias Parameter" example in the documentation

simendsjo simen.endsjo at pandavre.com
Thu Mar 17 07:29:20 PDT 2011


This example comes from http://digitalmars.com/d/2.0/template.html

int x;

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

void test()
{
    alias Foo!(x) bar;
    *bar.p = 3;		// set x to 3
    static int y;
    alias Foo!(y) abc;
    *abc.p = 3;		// set y to 3
}

Compiling this gives the following compiler errors on the line inside Foo:
t.d(5): Error: non-constant expression & x
t.d(5): Error: non-constant expression & y

Changing static int* to enum int* fixes the compiler errors.

Are these pages written using DDoc? Is it possible to extract and compile the examples to
ensure they are correct? And perhaps use asserts instead of/in addition to comments where
possible (Asserts are used many places already)?
Executable and verifiable examples could be a useful feature as plain text documentation and
examples have a tendency to rot.


More information about the Digitalmars-d-learn mailing list