4
为了找出哪个元素最常出现在给定的数组中,我一直使用std.algorithm中的组函数。首先,我将对数组进行排序(似乎不再需要),然后将它传递给group,然后对tuple数组进行排序,以便我可以获取第一个元素。它曾经工作,但现在我得到错误:重叠阵列副本。我为win32使用2.053版本。我知道D2和Phobos正在建设中,所以我并不感到惊讶。只是对导致问题的原因感到困惑。d2:重叠阵列副本
import std.stdio, std.algorithm, std.array;
void main() {
int[] arr = [ 1, 2, 2, 2, 2, 3, 4, 4, 4, 5 ];
auto a = sort!("a[1] > b[1]")(array(group(arr)))[0];
}
我得到的错误:
[email protected]\rt\arraycat.d(40): overlapping array copy
----------------
42EB58
42E9CF
4061F8
4060A0
406166
405EE8
402072
408898
4088D7
4084D3
4532C9
----------------
数组的内容让很多区别的。以下代码编译并打印出正确的结果:
import std.stdio, std.algorithm, std.array;
void main() {
int[] arr = [ 1, 2, 3, 4, 4, 4, 5 ];
auto a = sort!("a[1] > b[1]")(array(group(arr)))[0];
writeln(a);
}
// prints: Tuple!(int,uint)(4, 3)
使用-release开关进行编译,如错误报告所述,确实可以解决问题。谢谢。 – fwend 2011-05-15 11:11:16