digitalmars.D.learn - Why std.array : array needs pure postblit?
- Andrea Fontana (5/5) Jun 15 2018 Check this code:
- Basile B. (5/10) Jun 15 2018 Hello, i've tested locally and it can works by making
- Basile B. (30/43) Jun 15 2018 Patch is as simple as
- Andrea Fontana (3/7) Jun 15 2018 That was my idea too. But I wonder if pureness of reserve and
- Andrea Fontana (3/10) Jun 15 2018 My point is: if we remove pure from those functions it is
- Steven Schveighoffer (9/21) Jun 15 2018 Best way to check is to look in git history to see why it was added.
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
Jun 15 2018
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? AndreaHello, 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.
Jun 15 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: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; ---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? AndreaHello, 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.
Jun 15 2018
On Friday, 15 June 2018 at 11:25:49 UTC, Basile B. wrote:That was my idea too. But I wonder if pureness of reserve and ensureAddable have a particular reason.Hello, i've tested locally and it can works by making `Appender.reserve()` and `Appender.ensureAddable()` function templates.
Jun 15 2018
On Friday, 15 June 2018 at 11:48:59 UTC, Andrea Fontana wrote:On Friday, 15 June 2018 at 11:25:49 UTC, Basile B. wrote:My point is: if we remove pure from those functions it is inferred , isn't it? Why does we need to force it there?That was my idea too. But I wonder if pureness of reserve and ensureAddable have a particular reason.Hello, i've tested locally and it can works by making `Appender.reserve()` and `Appender.ensureAddable()` function templates.
Jun 15 2018
On 6/15/18 7:56 AM, Andrea Fontana wrote:On Friday, 15 June 2018 at 11:48:59 UTC, Andrea Fontana wrote:Best way to check is to look in git history to see why it was added. https://github.com/dlang/phobos/pull/1337 Looks like the idea is to make pure and safe appending work. It's quite old (2013), so it's possible that attribute inference wasn't up to snuff back then, but works OK now. Make sure you put in test cases that show pure safe formatting still works after your changes. -SteveOn Friday, 15 June 2018 at 11:25:49 UTC, Basile B. wrote:My point is: if we remove pure from those functions it is inferred , isn't it? Why does we need to force it there?That was my idea too. But I wonder if pureness of reserve and ensureAddable have a particular reason.Hello, i've tested locally and it can works by making `Appender.reserve()` and `Appender.ensureAddable()` function templates.
Jun 15 2018