On Wed, 26 Jun 2013 00:07:38 +0200, Namespace <rswhi...@googlemail.com> 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?

This is perfectly fine.

--
Simen

Reply via email to