Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Appears not -- d-programming-language.org/arrays.html says "A static array T[dim] can be implicitly converted to one of the following: ... U[] ... A dynamic array T[] can be implicitly converted to one of the following: U[] ... where U is a base class of T." Commented Jan 17, 2012 at 23:32
  • 2
    @BenVoigt Then the online docs need to be updated. They aren't always 100% up-to-date unfortunately. The conversion will work with const U[], since then you can't assign the wrong type to the array's elements, but T[] definitely does not convert to U[] as long as U[] is mutable. Allowing covariant arrays like it did before was a serious design flaw which has now been corrected. Commented Jan 17, 2012 at 23:57
  • @JonathanMDavis: Covariant arrays are icky, but work well for the particular scenario of code which will only write to an array elements which have been read from that same array. How would D allow one to write a method which could sort arrays of arbitrary type? Commented Dec 19, 2013 at 18:25
  • @supercat If you want to write a function which sorts arbitrary types, then templatize it. e.g. dlang.org/phobos/std_algorithm.html#sort Commented Dec 20, 2013 at 4:40