Can't make inout work.
aliak
something at something.com
Fri Mar 15 23:57:15 UTC 2019
This is the set up I have, and I'm not sure how to get the main
function at the bottom to compile. The error in the code below is
that it cannot implicitly convert an inout(C) to a C in the
constructor of S(T).
If you remove the constructor that takes an inout then you get a
"cannot deduce function from argument types !()(inout(C))"
because there's no constructor that can take in inout.
If you remove the inout form the function "f", then "a.f" cannot
be deduced because there's no f that takes an inout(C).
If you remove the inout from the "make" function, then you get:
"only parameters or stack based variables can be inout."
Anyone knows how to make this work?
struct S(T) {
T value = T.init;
}
auto ref make(T)(inout auto ref T value) {
return S!T(value);
}
auto ref f(T)(inout auto ref S!T s) {
return make(s.value);
}
void main() {
class C {}
const a = S!C();
a.f;
}
Cheers,
- Ali
More information about the Digitalmars-d-learn
mailing list