D-Programming-Language/phobos — pull request #878 by monarchdodra (2012-10-17 11:07:09+00:00)
Title: streamlining Array

TL;DR:
* enforce => assert
* verbose asserts at call sight
* convenience functions
* Array.Range has an invariant.
* Array.Range now encapsulates an Array.Data, and not the Array itself.
* Fixed a few "empty array operation" bug.

In details:

Safety and Streamline

* Added the function _payload, as a convenient way to access the payload directly. Is relatively safer, because if the payload is not initialized, it will assert with an "internal implementation error", as opposed to the deeper error in RefCounted.
* Array has the private _length function: This is cheeper than length, because it doesn't check the RefCounted is initialized. Also, it is more conveninet, as it can be used inside a slice (writting [0 .. lengh] is illegal: There was some code that actually didn't compile because of this)
* Array.Range has an invariant, that verifies it is not out of range.
* Both Array and Array.Range now have a much sturdier assert methodology, and assert at the point of call.
*Fixed some bugs where legal operations on an empty array would actually fail.
*Fixed a few template functions that did not actually compile, are were not covered in the unittest.

RefCounting.
* Array.Range now holds an actual Array.Data object, as opposed to an actual Array. This changes virtually nothing, but is simpler on the implementation. Also, it ensures the range avoids calling the operators in Array, double verifying its inputs
* Array.Clear now actually clears the payload: This is what it is supposed to do, arguably, and now this "works as intended":

```D
import std.container;
void main()
{
alias Array!int ARR;
auto a = ARR([1, 2, 3]);
auto b = a;
a.clear();
assert(b.empty);
}
```

Pull changed a lot of code, but it is mostly repetitive s/foo/bar/ changes.