How do I specify a variadic template constraint on all the whole tuple?
Atila Neves
atila.neves at gmail.com
Thu Jul 18 07:40:18 PDT 2013
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.
More information about the Digitalmars-d-learn
mailing list