delegate object instead of a literal

Joel Christensen joelcnz at gmail.com
Sun Aug 14 01:50:03 PDT 2011


Hi,

This program loops through a string until it finds a number and gives 
the position of it.

The first assert works, but not the second one.

import std.algorithm;

void main() {
	static bool isNumber( char input, char dummy ) {
		if ( ( input >= '0' && input <= '9' ) || input == '.' )
			return true;
		else
			return false;
	}
	
	string str = "abc123";
	assert( countUntil!( ( input, b ) {
		if ( ( input >= '0' && input <= '9' ) || input == '.' ) return true; 
else return false;
		} )(str, 0) == 3 ); // works
	assert( countUntil!( isNumber, string, string )( str, 0 ) == 3 );
}

This is the error:
parse.d(15): Error: template instance 
countUntil!(isNumber,string,string) does not match template declaration 
countUntil(alias pred = "a == b",R1,R2) if 
(is(typeof(startsWith!(pred)(haystack,needle))))

- Joel


More information about the Digitalmars-d-learn mailing list