std.traits and std.string incompatible ?

Nick Sabalausky a at a.a
Tue Mar 8 13:24:44 PST 2011


"Ali Çehreli" <acehreli at yahoo.com> wrote in message 
news:il5pge$nrr$1 at digitalmars.com...
> On 03/08/2011 08:24 AM, Wilfried Kirschenmann wrote:
> > Hi,
> >
> > When running the following file:
> >
> > #!../dmd2/linux/bin/rdmd -unittest
> > import std.string, std.traits;
> > void main(string[] args){
> > bool test = isNumeric(args[0]);
> > }
> >
> > I get the error :
> > dmd2/linux/bin/../../src/phobos/std/traits.d(2576): Error: template
> > std.traits.isNumeric(T) is not a function template
> >
> > Is this a bug or is there something deprecated ?
> >
> > Wilfried
>
>
> isNumeric is a template. You are supposed to give it a type:
>
>   if (isNumeric!SomeType)
>
> or at compile time:
>
>   static if (isNumeric!SomeType)
>
> It doesn't work with string values. Although unnecessary, you could do 
> this:
>
>     bool test = isNumeric!(typeof(args[0]));
>

No, there's an isNumeric in *both* std.traits and std.string. The one in 
std.traits is a template that takes a type. But the one in std.string is a 
function that takes a string and checks if the value of the string is 
numeric.

I'm on the latest D2 (2.052) and I just tried the example and got the same 
result. But if I *only* import std.string then it works. So it sounds like a 
bug: I forget the exact details of the rules involving overloading across 
modules, but one of two things should happen with the original example:

A. It should know that you meant std.string.isNumeric because of how you're 
calling it.

or:

B. It should complain that there's an ambiguity between std.string.isNumeric 
and std.traits.isNumeric and require you to disambiguate with either 
"std.traits." or "std.string."

I'm not sure which of those it's supposed to do, but it's clearly not doing 
either, so I'd file it as a bug: http://d.puremagic.com/issues/





More information about the Digitalmars-d-learn mailing list