Why this doesn't compile?

Uranuz via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 11 11:01:39 PDT 2014


When I want to pass generic String by const reference I get an 
error. As far as I understand const should accept both mutable 
and immutable data. And there I want to pass it by reference. Is 
it possible? Or is there any reason why it is not? Is it a bug?

void doSmth(String)(ref const(String) str) {}

void main()
{
	doSmth("Foo");
}

Compilation output:
/d198/f399.d(5): Error: template f399.doSmth does not match any 
function template declaration. Candidates are:
/d198/f399.d(1):        f399.doSmth(String)(ref const(String) str)
/d198/f399.d(5): Error: template f399.doSmth(String)(ref 
const(String) str) cannot deduce template function from argument 
types !()(string)


More information about the Digitalmars-d mailing list