I don't understand a const
Simen kjaeraas
simen.kjaras at gmail.com
Thu Sep 2 05:59:13 PDT 2010
bearophile <bearophileHUGS at lycos.com> wrote:
> This program doesn't compile, dmd prints the errors:
> test.d(4): Error: template test.foo(T) does not match any function
> template declaration
> test.d(4): Error: template test.foo(T) cannot deduce template function
> from argument types !()(const(int),int)
> test.d(9): Error: template instance test.bar!(int) error instantiating
>
> Are you able to tell me what is the error in this code?
>
>
> void foo(T)(const T a, out T b) {}
>
> void bar(T)(const T x, out T y) {
> foo(x, y); // line 4
> }
>
> void main() {
> int s1, s2;
> bar(s1, s2); // line 9
> }
>
>
> Bye, and thank you,
> bearophile
Simpler test case:
void bar(T)(const T x, out T y) {}
void main() {
const int s1;
int s2;
bar(s1, s2);
}
It seems DMD is confused by const(int) being such a nice fit for the
first parameter. This might have to do with s2 = s1 being ok.
It is probably worth noting that this works:
import std.traits;
void bar(T)(const T x, out T y) {}
void main() {
const int s1;
int s2;
bar!(CommonType!(s1,s2))(s1, s2);
}
--
Simen
More information about the Digitalmars-d-learn
mailing list