Why std.array : array needs pure postblit?

Basile B. b2.temp.temp.temp at gmx.gmx.gmx.com.com
Fri Jun 15 11:25:49 UTC 2018


On Friday, 15 June 2018 at 11:24:42 UTC, Basile B. wrote:
> On Friday, 15 June 2018 at 11:15:03 UTC, Andrea Fontana wrote:
>> Check this code:
>> https://run.dlang.io/is/PoluHI
>>
>> It won't work, because array appender requires a pure postblit.
>>
>> Why? Can we remove this limitation?
>>
>> Andrea
>
> Hello, i've tested locally and it can works by making 
> `Appender.reserve()` and `Appender.ensureAddable()` function 
> templates.
>
> If you want to open an issue i'd be okay to propose a PR.

Patch is as simple as

---
@@ -2953,11 +2953,11 @@ if (isDynamicArray!A)
       * done.
       *
       * Params:
       *     newCapacity = the capacity the `Appender` should have
       */
-    void reserve(size_t newCapacity) @safe pure nothrow
+    void reserve()(size_t newCapacity)
      {
          if (_data)
          {
              if (newCapacity > _data.capacity)
                  ensureAddable(newCapacity - _data.arr.length);
@@ -2988,11 +2988,11 @@ if (isDynamicArray!A)
           */
          return cast(typeof(return))(_data ? _data.arr : null);
      }

      // ensure we can add nelems elements, resizing as necessary
-    private void ensureAddable(size_t nelems) @trusted pure 
nothrow
+    private void ensureAddable()(size_t nelems) @trusted
      {
          if (!_data)
              _data = new Data;
          immutable len = _data.arr.length;
          immutable reqlen = len + nelems;

---


More information about the Digitalmars-d-learn mailing list