2

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

但是,如果我Array选择两种非常琐碎的类型,它不会排序 - 相反,它告诉我 Phobos 深处的例程不是 nothrow (?)

B:\lib\D\dmd2\windows\bin\..\..\src\phobos\std\range\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 构建,我找不到编译器版本标识符,但这是昨天才下载的。

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;
}
4

1 回答 1

5

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

一个月前就已经修复了,但还没有发布。可能会在 2.069 中提供。

作为现在的解决方法,您可以在发布模式下构建您的项目。

于 2015-10-18T13:44:26.393 回答