Return types are not matched with method return type.

RollingCat rollingcat at hotmail.com
Mon Dec 31 08:11:02 PST 2012


Hi there. I'm new to D language and make a simple software 
monitoring new file with specified extension.

class FileList
{
	str_CurrentDir;
	bool ReturnMatchedFile(string str_arg_filename, string 
str_Extension)
	{
	return endsWith(str_arg_filename, '.'~str_Extension);
	}

	void GetCurrentList(string str_arg_Extension)
	{
		auto 
filter_CurrentList=filter!ReturnMatchedFile(str_arg_Extension, 
dirEntries(str_CurrentDir, SpanMode.shallow));
	}
}

with this FileList class, after making instance of FileList and 
assigning str_CurrentDir variable, when I call 
GetCurrentList("d"), it says that std.algorithm.filter! ~~ does 
not match any function template declaration.
OK. So I modified above code like below just for a test.

class FileList
{
	str_CurrentDir;
	bool ReturnMatchedFile(string str_arg_filename)
	{
	return endsWith(str_arg_filename, ".d");
	}

	void GetCurrentList()
	{
		auto 
filter_CurrentList=filter!ReturnMatchedFile(dirEntries(str_CurrentDir, 
SpanMode.shallow));
	}
}

And it says that
this for ReturnMatchedFile needs to be type FileList not type 
FileResult!(ReturnMatchedFile, DirIterator).
I can't understand it!

Anyway, to solve the problem, again, I modified above code like 
below.

static bool ReturnMatchedFile(string str_arg_filename)
	{
	return endsWith(str_arg_filename, ".d");
	}

class FileList
{
	str_CurrentDir;
	
	void GetCurrentList()
	{
		auto 
filter_CurrentList=filter!ReturnMatchedFile(dirEntries(str_CurrentDir, 
SpanMode.shallow));
	}
}

and it works.

What is the problem?

Best regards and happy new year! :)


More information about the Digitalmars-d-learn mailing list