@foo int z; // Error: cannot interpret foo(T)(T val) at compile time
Where do you get that error? Is it from phobos' thing? cuz I copy/pasted your code and it compiled.
You can also just use a struct as the uda if your detection function checks for both the type and a value of the type, so it really depends on which search method you using.