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