mutable constant?
Simen Kjaeraas
simen.kjaras at gmail.com
Tue Jun 25 15:45:47 PDT 2013
On Wed, 26 Jun 2013 00:07:38 +0200, Namespace <rswhite4 at 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
More information about the Digitalmars-d-learn
mailing list