Why this doesn't compile?

Alexandre L. via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 11 11:10:14 PDT 2014


On Saturday, 11 October 2014 at 18:01:41 UTC, Uranuz wrote:
> 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)

Try doSmth!String("bla");

Also, the type is string, not String ?


More information about the Digitalmars-d mailing list