Constraining template's function parameter signature

Timon Gehr timon.gehr at gmx.ch
Thu Jun 14 06:43:36 PDT 2012


On 06/14/2012 02:57 PM, Tommi wrote:
> I'm trying to constrain a struct template based on a parameter that's
> supposed be a function with a certain signature. Difficult to explain,
> easier just to show the problem:
>
> module pseudorange;
>
> struct PseudoInputRange(T, alias advance)
> //The next line doesn't compile
> //if (is(typeof(advance(T.init)) == void))
> ...
> alias PseudoInputRange!(int, (ref int x) {++x;}) MyRange;
> static assert(isInputRange!MyRange);
>

'T.init' is not an lvalue and can therefore not be passed by ref.
You can fix the problem with the fewest keystrokes like this:
if (is(typeof(advance([T.init][0])) == void))


More information about the Digitalmars-d-learn mailing list