Skip to content

Commit

Permalink
make Unique.opDot() inout
Browse files Browse the repository at this point in the history
typecons.Unique.opDot() should be inout to allow use through const access paths.
  • Loading branch information
Cauterite authored Jul 26, 2016
1 parent 3cf5e9a commit c0fb999
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion std/typecons.d
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public:
return u;
}
/** Forwards member access to contents. */
RefT opDot() { return _p; }
auto opDot() inout { return _p; }

/**
Postblit operator is undefined to prevent the cloning of $(D Unique) objects.
Expand Down Expand Up @@ -288,6 +288,24 @@ private:
assert(!uf2.isEmpty);
}

unittest
{
struct Bar {int val;}
struct Foo {
Unique!Bar bar = new Bar;
}

Foo foo;
foo.bar.val = 6;
const Foo* ptr = &foo;
static assert(is(typeof(ptr) == const(Foo*)));
static assert(is(typeof(ptr.bar) == const(Unique!Bar)));
static assert(is(typeof(ptr.bar.val) == const(int)));
assert(ptr.bar.val == 6);
foo.bar.val = 7;
assert(ptr.bar.val == 7);
}

// Used in Tuple.toString
private template sharedToString(alias field)
if (is(typeof(field) == shared))
Expand Down

0 comments on commit c0fb999

Please sign in to comment.