importing std.algorithm breaks std.string.count

Steven Schveighoffer schveiguy at yahoo.com
Thu Sep 23 07:10:41 PDT 2010


On Thu, 23 Sep 2010 02:19:55 -0400, Daniel Murphy  
<yebblies at nospamgmail.com> wrote:

> "Steven Schveighoffer" <schveiguy at yahoo.com> wrote in message
> news:op.vi64pdhveav7ka at localhost.localdomain...
>> Second, std.algorithm.count looks like this:
>>
>> size_t count(alias pred = "a == b", Range, E)(Range r, E value) if
>> (isInputRange!(Range))
>>
>> So, E can be any type, completely unrelated to strings, I could do:
>>
>> count!(string, int[]) which makes no sense.
>>
>> I think the sig should be
>>
>> size_t count(alias pred = "a == b", Range, E)(Range r, E value) if
>> (isInputRange!(Range) && isImplicitlyConvertable!(E,  
>> ElementType!(Range)))
>>
>> -Steve
>
> Except you can call it like this:
>
> string s = "1234";
> int[] a = [1, 2, 3];
> count!"cast(int)(a - '0') == b.length"(s, a);
>
> Which is perfectly valid.

and insane :)

count(s, cast(char)(a.length + '0'));

-Steve


More information about the Digitalmars-d-learn mailing list