Skip to content

Commit

Permalink
Merge pull request #4662 from Cauterite/patch-1
Browse files Browse the repository at this point in the history
make Unique.opDot() inout
  • Loading branch information
WalterBright authored Jul 27, 2016
2 parents 9f7dcd5 + e50b77f commit dc56fc1
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 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,26 @@ private:
assert(!uf2.isEmpty);
}

// ensure Unique behaves correctly through const access paths
@system 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 dc56fc1

Please sign in to comment.