Range Construction Pattern

Tobias Pankrath tobias at pankrath.net
Sat Feb 22 06:21:50 PST 2014


>
> I believe we need a new std.trait, say arityMin, for this.
> Any ideas on how to implement that? Perhaps using 
> __traits(compiles...?
>
> See also my update at:
> https://stackoverflow.com/questions/21954381/range-construction-pattern/21954416?noredirect=1#21954416

In the meantime you can use an is-expression:
--
int foo()  { return 12; }
void bar() { }
void baz(int x) { }
void main()
{
	pragma(msg, is(typeof(foo()) == void));
	pragma(msg, is(typeof(bar()) == void));
         pragma(msg, is(typeof(baz()) == void));
}
--

You can check if arbitrary code compiles with the 
"if-typeof-delegate-trick":
--
static if(is(typeof({ <code>}))))
{
// code compiles
}
--


More information about the Digitalmars-d-learn mailing list