Why D is not popular enough?

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 19 01:42:40 PDT 2016


Am Mon, 15 Aug 2016 10:54:11 -0700
schrieb Ali Çehreli <acehreli at yahoo.com>:

> On 08/14/2016 07:07 AM, Andrei Alexandrescu wrote:
>  > On 08/14/2016 01:18 AM, Shachar Shemesh wrote:  
> 
>  >> Also, part of our
>  >> problems with this is that introspection also does not see refs, which
>  >> causes the following two functions to report the same signature:
>  >>
>  >> void func1(int arg);
>  >> void func2(ref int arg);  
>  >
>  > I actually think you can do introspection on any argument to figure
>  > whether it has "ref".  
> 
> Yes, it exists. However, I tried std.traits.Parameters but that wasn't 
> it. A colleague reminded us that it's std.traits.ParameterStorageClassTuple:
> 
>    http://dlang.org/phobos/std_traits.html#ParameterStorageClassTuple
> 
> Ali
> 

In fact, std.traits.Parameters _retains_ ref as long as you
don't unpack the tuple:

void foo(ref int);
void bar(Parameters!foo args); 

'bar' is now "void function(ref int)"

You can then access 'args.length' and 'args[n]' to get at each
argument or pass 'args' on as is to the next function.

You can also create a ref argument for 'T' out of thin air by
writing:

alias RefArg = Parameters!((ref T) {});

Just remember that 'RefArg' is again a tuple and you
always need to access args[0] to use it.

-- 
Marco



More information about the Digitalmars-d mailing list