D function templates and type inference

Consider the following code:

module ftwr;

import std.regex;
import std.stdio;
import std.conv;
import std.traits;

S consume (S) (ref S data, Regex ! ( Unqual!(typeof(S.init[0])) ) rg)
{
    writeln (typeid(Unqual!(typeof(S.init[0]))));

    auto m = match(data, rg);
    return m.hit;
}

void main()
{
    auto data = "binary large object";
    auto rx = regex(".*");
    consume (data, rx); // this line is mentioned in the error message
}

Now I expect the compiler to conclude that it consumeshould be created as

string consume!(string)(string, Regex!(char))

but this does not seem to be happening. Errors are as follows:

func_template_with_regex.d(24): Error: template ftwr.consume(S) does not match any function template declaration
func_template_with_regex.d(24): Error: template ftwr.consume(S) cannot deduce template function from argument types !()(string,Regex!(char))

and I see that the parameter types are correct ... I tried some options for the function signature, for example:

S consume (S) (Regex ! ( Unqual!(typeof(S.init[0])) ) rg, ref S data)

which also does not compile (the idea was to change the order of the arguments) and

immutable(S)[] consume (S) (Regex ! ( S ) rg, ref immutable(S)[] data)

which compiles and writes types in order. If I specify the type explicitly in the call, i.e.

consume!string(data, rx);

it also compiles, and debugging writelnprints charas expected. Am I missing something in the output rules, or did I just hit the error in the compiler?

Oh yeah:

$ dmd -v
DMD64 D Compiler v2.053
...
+5
source share
1

, , , . consume :

S consume (S, U) (ref S data, Regex!U rg) if (is(U == Unqual!(typeof(S.init[0]))))
+5

All Articles