const-typed class does not have const members

Sean Eskapp eatingstaples at gmail.com
Fri Jan 21 16:09:31 PST 2011


The following code yields results as commented.

import std.stdio;

class A
{
	int b;
}

void main()
{
	const A a = new A;
	writeln(typeof(a).stringof); // const(A)
	writeln(typeof(a.b).stringof); // const(int)

	writeln((const A).stringof); // const(A)
	writeln(typeof((const A).b).stringof); // int
}

Given this information, how do I work around this in templates? I'd like a
template which can type its params based on members of T, for instance:

void foo(T)(T x, typeof(T.member) y)

but this will yield non-const second parameters even if T is const. Help anybody?


More information about the Digitalmars-d-learn mailing list