digitalmars.D.learn - Error in "Template Alias Parameter" example in the documentation
- simendsjo (23/23) Mar 17 2011 This example comes from http://digitalmars.com/d/2.0/template.html
- Jesse Phillips (3/8) Mar 17 2011 There has been talk about getting Examples compiled as part of unit test...
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.
Mar 17 2011
simendsjo Wrote: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.There has been talk about getting Examples compiled as part of unit tests. Agreement on how to do that was not reached (Sometimes examples require a lot of setup code). This example is probably old and in need of updating, file a bug report.
Mar 17 2011