void arraycopy( T )( T[] src, T[] trg, int length ){
}
void main(){
char[] a, b;
arraycopy( a, b, 1 ); //(1)
arraycopy( a, b, a.length ); //(2)
}
I don't want to change the main() content:
(2) causes an error because length is uint.
if I change the signature of arraycopy to "( T[], T[], uint)", (1) causes an error.
If I supply both variations, they conflict. They should not.
Comment #1 by davidl — 2006-10-09T20:17:26Z
void arraycopy( T,U )( T[] src, T[] trg, U length ){
static if (is(U: int)) //now uint ,int and other type can implicitly cast to
//int can be processed
{
// do ur job here
}
}
void main(){
char[] a, b;
arraycopy( a, b, 1 ); //(1)
arraycopy( a, b, a.length ); //(2)
}
Comment #2 by davidl — 2006-10-09T20:19:31Z
ah, u mean the problem is they should not conflict... umm yep , they shouldn't conflict if they can't be implicitly cast to one type.
Comment #3 by davidl — 2006-10-09T20:30:58Z
umm, i think i should state that more clear, i guess the problem is dmd not doing enough distinguish check when the template in this collapsed form. actually if i write
template arraycopy(T)
{
arraycopy(T[] a, T[] b, int length)
arraycopy(T[] a, T[] b, uint length)
}
is ok
but the main func in ur example need to modified, so that's not a good idea.
Comment #4 by bruno.do.medeiros+deebugz — 2006-10-16T09:21:54Z
If I may, a more illustrative case:
--------
void func(int a) {
}
void tfunc()(int a) {
}
void test() {
func(cast(uint) 2); // OK
tfunc!()(cast(uint) 2); // OK
tfunc(cast(uint) 2); // IFTI breakage
}
Comment #5 by bugzilla — 2006-11-21T17:40:15Z
The language is working as defined. All the examples have easy solutions. Let's take the last one:
void tfunc()(int a) {
}
void test() {
tfunc!()(cast(uint) 2); // OK
tfunc(cast(uint) 2); // IFTI breakage
}
Fix:
void tfunc(T)(T a) {
}
Or:
void tfunc()(int a) { }
void tfunc(dummy=void)(uint a) { }