Thanks! I had to change allSatistfy!(isSomeString, Symbols) to allSatistfy!(isSomeString, typeof(Symbols)) but it works.

I don't use the same types as runtimne arguments actually. You might see why if/when I finish this particular project and announce it.

Shall I answer my own question on stackoverflow?

Atila

On Thursday, 18 July 2013 at 13:25:55 UTC, Andrej Mitrovic wrote:
On Thursday, 18 July 2013 at 13:18:29 UTC, Atila Neves wrote:
bool func(SYMBOLS...)() if(!is(typeof(SYMBOLS[0]) == string)) {
}
and

bool func(STRINGS...)() if(is(typeof(STRINGS[0]) == string)) {
}

Here you go:

-----
import std.string;
import std.traits;
import std.typetuple;
import std.functional;

bool func(Symbols...)(Symbols symbols)
    if (!anySatisfy!(isSomeString, Symbols))
{
    return true;
}

bool func(Strings...)(Strings strings)
    if (allSatisfy!(isSomeString, Strings))
{
    return true;
}

void main()
{
    func("1", "2");
    func(1, 2);
    static assert(!__traits(compiles, func(1, "2")));
}
-----

And remember you have to actually list the runtime arguments after the type arguments (e.g. 'Strings strings'), otherwise the template won't match.

Reply via email to