Help with specific template function
aliak
something at something.com
Sun Mar 25 21:31:16 UTC 2018
On Sunday, 25 March 2018 at 19:06:14 UTC, Vladimirs Nordholm
wrote:
> On Sunday, 25 March 2018 at 18:24:37 UTC, Vladimirs Nordholm
> wrote:
>> The underlying problems are:
>> * How do I ensure the two first arguments (used as
>> coordinates) are types of numbers (all kinds: ints, floats,
>> reals, etc.)
>> * At least one argument is passed after the coordinates
>
> I found a solution which satisfies my needs :)
>
> void foo(X, Y, Args...)(X x, Y y, Args args)
> if (__traits(isArithmetic, x) && __traits(isArithmetic, y)
> && args.length >= 1)
> {
> // ...
> }
FYI there's also
https://dlang.org/library/std/traits/is_numeric.html incase you
haven't see it -takes in to account bools and chars, which
depending on your usecase you may not want to count as arithmetic.
Cheers
- Ali
More information about the Digitalmars-d-learn
mailing list