digitalmars.D - How to make stuff const in a template?
- Janice Caron (22/22) Nov 28 2007 The following program gives unexptected results.
The following program gives unexptected results. template MakeConst(T) { alias const(T) MakeConst; } void main() { alias float MF; alias const(float) CF; alias MakeConst!(MF) TF; writefln(MF.stringof, ", ", typeid(MF)); writefln(CF.stringof, ", ", typeid(CF)); writefln(TF.stringof, ", ", typeid(TF)); } It prints... float, float const float, const float float, float I would have expected the second and third lines to be identical. Why aren't they? More to the point, how can I create a template which turns a primitive type T into a const(T)?
Nov 28 2007