Typesafe variadic functions requiring at least one argument

kinke via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 6 13:10:50 PDT 2016


On Wednesday, 6 July 2016 at 19:50:11 UTC, pineapple wrote:
> I'd like to do something like this but it doesn't seem to be 
> legal -
>
>     void test(int[] ints...) if(ints.length){
>         // stuff
>     }
>
> Not being able to specify this interferes with how I'd like to 
> define my method overloads. What's the best way to achieve what 
> I'm looking for?

I don't really know what you're looking for. But you need to drop 
the if condition - you can only specify them for templates as 
instantiation constraints. You may want to use a runtime check 
instead (the slice's size isn't available at compile-time - 
although it's known at the call site):

void test(int[] ints...] { assert(ints); ... }



More information about the Digitalmars-d-learn mailing list