Can't make inout work.

aliak something at something.com
Sun Mar 17 10:49:03 UTC 2019


On Saturday, 16 March 2019 at 03:49:26 UTC, Paul Backus wrote:
> On Friday, 15 March 2019 at 23:57:15 UTC, aliak wrote:
>> Anyone knows how to make this work?
>
> You need an explicit `inout` on the return value of `make`:
>
> auto ref make(T)(inout auto ref T value) {
>     return inout(S!T)(value);
> }

Ah! Thanks! So next problem with that:

import std.stdio;

struct S(T) {
     T value;
}

auto make(T)(inout auto ref T val) {
     return inout(S!T)(val);
}

void main() {
     writeln(make("hello") == S!string("hello"));
}

Error: Error: incompatible types for (make("hello")) == 
(S("hello")): immutable(S!(char[])) and S!string

I think that's just this bug (which is marked as a diagnostic for 
some reason): https://issues.dlang.org/show_bug.cgi?id=19126

Thoughts on any workarounds?


More information about the Digitalmars-d-learn mailing list