www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13428] New: Add template to perform appropriate substitution

https://issues.dlang.org/show_bug.cgi?id=13428

          Issue ID: 13428
           Summary: Add template to perform appropriate substitution for
                    inout when it appears in a type
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: turkeyman gmail.com

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...

What I want is:

alias Y = SubstituteInout!(X, T); // copy the mutability of T where 'inout'
appears in X

static assert(is(SubstituteInout!(inout(T)[], const(S)) == const(T)[]);

Can anyone suggest how I might write that template? I can't work it out >_<

--
Sep 06 2014