Re: Can't make inout work.

2019-03-18 Thread spir via Digitalmars-d-learn
On 17/03/2019 18:34, Kagamin via Digitalmars-d-learn wrote: On Saturday, 16 March 2019 at 14:57:35 UTC, Paul Backus wrote: This code fails to compile if you change `auto s2` to `const s2`--in other words, it has the same problem as the original example. Maybe there's not much need for

Re: Can't make inout work.

2019-03-18 Thread aliak via Digitalmars-d-learn
On Sunday, 17 March 2019 at 20:23:44 UTC, Paul Backus wrote: On Sunday, 17 March 2019 at 10:49:03 UTC, aliak wrote: [...] For some reason, when you call `make("hello")`, the template argument T is being inferred as char[] instead of string. (You can see this by putting `pragma(msg, T)` in

Re: Can't make inout work.

2019-03-17 Thread aliak via Digitalmars-d-learn
On Sunday, 17 March 2019 at 17:22:13 UTC, Kagamin wrote: struct S(T) { T value; bool opEquals(U:S!V,V)(in U r) const { return value==r.value; } } Hmm, that actually works for opEquals. But now you just hit the same problem with some other construct, unfortunately: auto x =

Re: Can't make inout work.

2019-03-17 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 17 March 2019 at 10:49:03 UTC, aliak wrote: 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:

Re: Can't make inout work.

2019-03-17 Thread Kagamin via Digitalmars-d-learn
On Saturday, 16 March 2019 at 14:57:35 UTC, Paul Backus wrote: This code fails to compile if you change `auto s2` to `const s2`--in other words, it has the same problem as the original example. Maybe there's not much need for qualifiers anyway. struct S(T) { T value; } auto make(T)(ref

Re: Can't make inout work.

2019-03-17 Thread Kagamin via Digitalmars-d-learn
struct S(T) { T value; bool opEquals(U:S!V,V)(in U r) const { return value==r.value; } }

Re: Can't make inout work.

2019-03-17 Thread aliak via Digitalmars-d-learn
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); }

Re: Can't make inout work.

2019-03-16 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 16 March 2019 at 11:55:56 UTC, spir wrote: I think (but may be wrong) that you don't need inout here, since a plain 'ref' will (and does) work. This is accepted by me (I added vars to make the code clearer to myself): struct S(T) { T value = T.init; } auto ref make(T)(ref T

Re: Can't make inout work.

2019-03-16 Thread spir via Digitalmars-d-learn
PS: the chapter of Ali Çehreli's book on func args is great: http://ddili.org/ders/d.en/function_parameters.html diniz

Re: Can't make inout work.

2019-03-16 Thread spir via Digitalmars-d-learn
On 16/03/2019 04:49, Paul Backus via Digitalmars-d-learn 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); }

Re: Can't make inout work.

2019-03-15 Thread Paul Backus via Digitalmars-d-learn
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); }