Ranges and Library and toir.c internal error

StupidIsAsStupidDoes kc_heaser at yahoo.com
Wed Oct 31 16:35:57 PDT 2012


There may be a better way to solve this but I'm trying to learn 
Phobos and parameter typing and anonymous function, etc.  So this 
is probably more of an academic question but I've got the 
following code:

int countBetween(T)(T[] x, T low, T high)
{
    auto k = count!( (x){return ((x >= low) && (x <= high));} ) 
(x);
    return k;
}

int[] a = [ 9, 77, 1, 13, 76, 17, 4, 27, 99, 5 ];

auto m = countBetween!(int)(a, 1, 25);      // works!


char[] b = ['h', 'e', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'];
	
auto n = countBetween!(char)(b, 'c', 'k');  // fails



The integer call compiles and runs correctly.

The char call doesn't compile and I get a toir.c internal error.


The library definition says count is
size_t count(alias pred = "true", Range)(Range r);


I'm still trying to get my head around Ranges. Is a int array a 
valid range but a character array not?

Any enlightenment is welcome.




More information about the Digitalmars-d-learn mailing list