mutable constant?

Namespace rswhite4 at googlemail.com
Tue Jun 25 15:07:38 PDT 2013


I want to ask if this code should compile or if it's a bug, 
because I circumvent the const system:

----
import std.stdio;

struct Point {
	int x, y;
}

Point*[] points;

struct TplPoint(T) {
public:
	Point _point;

	T x, y;

	const uint id;

	this(T x, T y) {
		this.x = x;
		this.y = y;

		points ~= &this._point;

		id = points.length - 1;
	}

	@property
	inout(Point)* ptr() inout {
		points[this.id].x = cast(int) this.x;
		points[this.id].y = cast(int) this.y;

		return cast(inout Point*) points[this.id];
	}
}

void main() {
	const TplPoint!float my = TplPoint!float(42, 23);
	writeln(my._point, "::", &my._point);
	writeln(*my.ptr, "::", my.ptr);
}
----

Or is the fact that it compiles ok and it's "only" unsafe?


More information about the Digitalmars-d-learn mailing list