Check if a variadic argument is numeric?

Hamborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 6 01:22:44 PDT 2017


On Thursday, 6 July 2017 at 07:11:01 UTC, Ali Çehreli wrote:
> On 07/05/2017 11:26 PM, Hamborg wrote:
>> I can test for exactly what what the args are with 
>> (_arguments[i] ==
>> typeid(int)) but if I just want to know if it's numeric and 
>> can pull it
>> out as a double what should I do? I don't really want to test 
>> for int,
>> uint, byte, float, etc individually.
>
> If it exists, it would be in std.traits or __traits. In this 
> case it's std.traits.isNumeric. :)
>
>   https://dlang.org/phobos/std_traits.html#isNumeric
>
> Ali

But how would I check _arguments[i]?

When I do (isNumeric!_arguments[i]) I get an error saying:
"Error: template instance isNumeric!(_arguments) does not match 
template declaration isNumeric(T)"

or when I do (isNumeric!(_arguments[i])) I get this error:
"Error: variable _arguments cannot be read at compile time"



More information about the Digitalmars-d-learn mailing list