digitalmars.D.learn - Check if a variadic argument is numeric?
- Hamborg (4/4) Jul 05 2017 I can test for exactly what what the args are with (_arguments[i]
- =?UTF-8?Q?Ali_=c3=87ehreli?= (5/9) Jul 06 2017 If it exists, it would be in std.traits or __traits. In this case it's
- Hamborg (7/19) Jul 06 2017 But how would I check _arguments[i]?
- Andrea Fontana (4/10) Jul 06 2017 Try with:
- Hamborg (3/15) Jul 06 2017 That compiles, but it returns false when I pass in a numeric
- Andrea Fontana (4/6) Jul 06 2017 I think you should provide a code snippet then. I think I missed
- Adam D. Ruppe (11/13) Jul 06 2017 You did - this question is about a runtime variadic which gives
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.
Jul 05 2017
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
Jul 06 2017
On Thursday, 6 July 2017 at 07:11:01 UTC, Ali Çehreli wrote:On 07/05/2017 11:26 PM, Hamborg wrote: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"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
Jul 06 2017
On Thursday, 6 July 2017 at 08:22:44 UTC, Hamborg wrote: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"Try with: isNumeric!(typeof(_arguments[i])); Andrea
Jul 06 2017
On Thursday, 6 July 2017 at 08:35:05 UTC, Andrea Fontana wrote:On Thursday, 6 July 2017 at 08:22:44 UTC, Hamborg wrote:That compiles, but it returns false when I pass in a numeric value... :(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"Try with: isNumeric!(typeof(_arguments[i])); Andrea
Jul 06 2017
On Thursday, 6 July 2017 at 12:15:56 UTC, Hamborg wrote:That compiles, but it returns false when I pass in a numeric value... :(I think you should provide a code snippet then. I think I missed something about your question. Andrea
Jul 06 2017
On Thursday, 6 July 2017 at 12:26:11 UTC, Andrea Fontana wrote:I think you should provide a code snippet then. I think I missed something about your question.You did - this question is about a runtime variadic which gives you an array of TypeInfo objects, but all the answers are giving compile time things. None of them will work since the static type is some subclass of TypeInfo. There is no method in the interface to do what the OP wants. You'll have to do a list of comparisons.... or hack druntime, it is fairly easy to add such a method... but that's not a realistic solution either. Best option would perhaps be switching to a compile time variadic template.
Jul 06 2017