Can't make inout work.

Paul Backus snarwin at gmail.com
Sat Mar 16 14:57:35 UTC 2019


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 value) {
>     return S!T(value);
> }
>
> auto ref f(T)(ref S!T s) {
>     return make(s.value);
> }
>
> void main() {
>     class C {}
>     C c ;
>     auto s1 = S!C(c) ;
>     auto s2 = make!C(c) ;
>     auto s3 = f!C(s2) ;
> }

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.


More information about the Digitalmars-d-learn mailing list