A request for an easier way to pass a storage class to a template

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Tue Oct 25 01:40:42 PDT 2011


I had similar problems many times.
Parameter storage classes are not considered as part of the type, but
they change the underlying type of the parameter:
 * ref and out make the parameter a pointer of it's type
 * lazy makes the parameter a delegate, returning it's type

I was thinking about making ref, out and lazy full-fledged storage classes.

Making lazy that way seems like a great idea to me It would allow to
easily manipulate and return delegates with no parameters.

Unfortunately, i didn't come up with a neat solution to ref and out.

On Tue, Oct 25, 2011 at 7:14 AM, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> And look, here they even get lost by ParameterTypeTuple:
>
> import std.traits;
>
> class Foo(Types...)
> {
>    alias void delegate(Types) DG;
>    DG dg;
> }
>
> void test(ref int, ref int) { }
>
> void main()
> {
>    auto foo = new Foo!(ParameterTypeTuple!test);
>    foo.dg = (ref int, ref int) { };
> }
>
> Error: cannot implicitly convert expression (__dgliteral1) of type
> void delegate(ref int _param_0, ref int _param_1) pure nothrow @safe
> to void delegate((int, int))
>
> This is completely bizarre since storage classes are actually kept in
> that tuple if you try to print them out, e.g.:
>
> pragma(msg, ParameterTypeTuple!test);
> prints: (ref int, ref int)
>


More information about the Digitalmars-d mailing list