On Wednesday, June 26, 2013 00:07:38 Namespace wrote: > 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?
I could certainly be missing something here, but I don't understand what about the code you're even concerned about. Where in here would you be breaking the type system? I don't see any place in here where you're mutating a const variable or anything like that. The worst thing I see about the code is that it won't compile on 64-bit machines thanks to id = points.length - 1; - Jonathan M Davis