So, apparently detecting refness has been solved for months, maybe years.
downs
default_357-line at yahoo.de
Fri Dec 14 16:05:16 PST 2007
downs wrote:
> * a way to detect ref in a delegate parameter list
Huh. After writing this, in a sudden flash of insight, I reinvented a method that has been in use in std.bind for ages now (props to h3).
Consider the following code:
>
> template _isRef(C, size_t which) {
> alias ParameterTypeTuple!(C) pt;
> pt[0..which] pre;
> const pt[which] test;
> pt[which+1..$] post;
> const bool r=!is(typeof(C(pre, test, post)));
> }
> template isRef(C, size_t which) { const bool isRef=_isRef!(C, which).r; }
>
What does this mean?
Succinctly put, if (and only if) a parameter is ref, then trying to call
the delegate/function type in question with a constant value for that parameter
will fail. The const bool r expression literally means "true if calling C with
a constant test fails to produce a return value".
Should there be a place to collect metaprogramming thingies like this so people
don't have to reinvent the wheel?
I vote std.meta! :)
--downs
More information about the Digitalmars-d
mailing list