digitalmars.D - Fun with inout
- Manu via Digitalmars-d (18/18) Sep 06 2014 I'm having a lot of problems with meta when inout gets involved.
- Kagamin (8/8) Sep 06 2014 template ReturnType1(alias F, TArg)
- Manu via Digitalmars-d (6/14) Sep 06 2014 Interesting. You're attacking it from the ReturnType! angle... I didn't
- Kagamin (3/3) Sep 06 2014 You can write it inline, it's about 2 lines
- Kagamin (4/7) Sep 06 2014 Function may not have `this` parameter, then you will need to
- Manu via Digitalmars-d (3/10) Sep 06 2014 It'd be preferable to receive a type, rather than a function alias.
- Kagamin (2/2) Sep 06 2014 Hmm... extract type from function with desired constancy and pass
- Manu via Digitalmars-d (4/6) Sep 06 2014 Existing code is using ReturnType though, so it'd be handy to be able to
- Kagamin (3/3) Sep 08 2014 Ah, you said X?
I'm having a lot of problems with meta when inout gets involved. There's no std.traits that deal with inout, and I think that's a bit of a hole... So my situation is, I have X captured by ReturnType!(T.f), and I also have T. T.f is "inout(RT)[] f() inout { return ...; }" I run into the situation where X == inout(RT)[]. I can't declare variables of that type, and it all goes wrong. What I need to do, is transform X into RT[], const(RT)[] or immutable(RT)[] accordingly to T. First problem, I can't work out how to detect if X is inout, I can't seem to craft an is() expression that works, and there's nothing in std.traits. After that, I need to perform the substitution, and that's proving to be really tricky... I think a std template could be created which will transform some type containing inout with the appropriate mutability level taken from some other type... Can anyone suggest how I might write that template? I can't work it out >_<
Sep 06 2014
template ReturnType1(alias F, TArg) { alias ReturnType1=typeof((){ ReturnType!F function(inout Unqual!TArg) test; TArg testv; return test(testv); }()); }
Sep 06 2014
Interesting. You're attacking it from the ReturnType! angle... I didn't think of that. I had to stare at this for like 10 minutes to work out how it works ;) I think I can use this, but I'm not sure it addresses the hole in phobos? On 6 September 2014 21:00, Kagamin via Digitalmars-d < digitalmars-d puremagic.com> wrote:template ReturnType1(alias F, TArg) { alias ReturnType1=typeof((){ ReturnType!F function(inout Unqual!TArg) test; TArg testv; return test(testv); }()); }
Sep 06 2014
You can write it inline, it's about 2 lines ReturnType!(T.f) function(inout Unqual!T) test; typeof(test(t))... // if you have t of type T
Sep 06 2014
On Saturday, 6 September 2014 at 11:46:17 UTC, Manu via Digitalmars-d wrote:Interesting. You're attacking it from the ReturnType! angle... I didn't think of that.Function may not have `this` parameter, then you will need to specify argument type anyway.
Sep 06 2014
It'd be preferable to receive a type, rather than a function alias. On 6 September 2014 22:21, Kagamin via Digitalmars-d < digitalmars-d puremagic.com> wrote:On Saturday, 6 September 2014 at 11:46:17 UTC, Manu via Digitalmars-d wrote:Interesting. You're attacking it from the ReturnType! angle... I didn't think of that.Function may not have `this` parameter, then you will need to specify argument type anyway.
Sep 06 2014
Hmm... extract type from function with desired constancy and pass it where you expect a ready to use type.
Sep 06 2014
Existing code is using ReturnType though, so it'd be handy to be able to perform this same resolution on a type that I already have... On 7 September 2014 02:25, Kagamin via Digitalmars-d < digitalmars-d puremagic.com> wrote:Hmm... extract type from function with desired constancy and pass it where you expect a ready to use type.
Sep 06 2014
Ah, you said X? X function(inout Unqual!T) test; typeof(test(T.init))...
Sep 08 2014