Ranges

Jonas Drewsen jdrewsen at nospam.com
Sat Mar 12 14:02:00 PST 2011


Hi,

    I'm working a bit with ranges atm. but there are definitely some 
things that are not clear to me yet. Can anyone tell me why the char 
arrays cannot be copied but the int arrays can?

import std.stdio;
import std.algorithm;

void main(string[] args) {

   // This works
   int[]	a1 = [1,2,3,4];
   int[] a2 = [5,6,7,8];
   copy(a1, a2);

   // This does not!
   char[] a3 = ['1','2','3','4'];
   char[] a4 = ['5','6','7','8'];
   copy(a3, a4);

}

Error message:

test2.d(13): Error: template std.algorithm.copy(Range1,Range2) if 
(isInputRange!(Range1) && isOutputRange!(Range2,ElementType!(Range1))) 
does not match any function template declaration

test2.d(13): Error: template std.algorithm.copy(Range1,Range2) if 
(isInputRange!(Range1) && isOutputRange!(Range2,ElementType!(Range1))) 
cannot deduce template function from argument types !()(char[],char[])

Thanks,
Jonas


More information about the Digitalmars-d-learn mailing list