Why do "const inout" and "const inout shared" exist?
ag0aep6g via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jul 3 09:43:07 PDT 2017
On 07/03/2017 04:01 PM, Jonathan M Davis via Digitalmars-d wrote:
> Fortunately, it looks like your assertion that shared may stand for inout is
> wrong, because this code fails to compile:
>
> class C
> {
> }
>
> inout(C) foo(inout(C) c)
> {
> return c;
> }
>
> void main()
> {
> shared a = new C;
> auto b = foo(a);
> }
>
> and gives the error
>
> test.d(13): Error: function test.foo (inout(C) c) is not callable using
> argument types (shared(C))
Thanks, Jonathan. You're absolutely right. Checking the spec, it even
says: "Note: Shared types are not overlooked. Shared types cannot be
matched with inout." [1]
I think I've only tested with something like `foo(new shared C)`. That
is accepted, but not because of inout. The compiler sees that the
argument is unique and can't actually be shared with another thread yet,
so it strips shared off.
Sorry for the noise. Nothing to see here.
[1] https://dlang.org/spec/function.html#inout-functions
More information about the Digitalmars-d
mailing list