使用Array!T和opSlice()时,std.algorithm.sorting失败,并出现模糊错误

std.algorithm.sorting fails with obscure errors when using Array!T and opSlice()

我确定这里缺少明显的东西-D的其余部分(甚至是编译器错误)都非常明智且易于理解。我有一个类似结构的std.containers.Array,我想对它进行排序。 std.containers文档指出,为了使用std.algorithm中的内容,您需要使用array[]array.opSlice()对其进行切片。好的,没问题。

但是,如果我将两个非常普通的类型制成Array,它将不会排序-相反,它告诉我Phobos内部的例程不是空位(?)

1
2
3
4
B:\\lib\\D\\dmd2\\windows\\bin\\..\\..\\src\\phobos\\std\
ange\\package.d(7189): Error: 'std.range.SortedRange!(RangeT!(Array!(MyInt)),"a < b").SortedRange.dbgVerifySorted' is not nothrow
B:\\lib\\D\\dmd2\\windows\\bin\\..\\..\\src\\phobos\\std\\algorithm\\sorting.d(982): Error: template instance std.range.assumeSorted!("a < b", RangeT!(Array!(MyInt))) error instantiating
main.d(21):        instantiated from here: sort!("a < b", cast(SwapStrategy)0, RangeT!(Array!(MyInt)))

下面的最小示例。第一个sort(两个值的自动生成的标准数组)排序良好。其他sort调用因上述编译器错误而失败。使用VS Community 2015的DMD2构建,我找不到编译器版本标识符,但这仅是在昨天下载的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import std.array;
import std.container.array;
import std.algorithm.sorting;

struct MyInt
{
    int data;

    int opCmp(MyInt o)
    {
        return data - o.data;
    }
}

int main(string[] argv)
{
    MyInt ami, bmi;
    Array!MyInt arr = [ ami, bmi ];

    sort([ami, bmi]);
    sort(arr[0..2]);
    sort(arr[]);
    sort(arr.opSlice());

    return 0;
}

这是Phobos中的错误:问题#14981

该问题已在一个月前修复,但尚未对其发布进行任何更改。可能将在2.069中提供。

目前,您可以在发布模式下构建项目。