On 1/24/19 7:35 AM, FeepingCreature wrote:
On Tuesday, 27 March 2018 at 12:31:05 UTC, Simen Kjærås wrote:
On Tuesday, 27 March 2018 at 12:17:58 UTC, Ellie Harper wrote:
Sorry if this is a stupid question, but is there something special required to call Appender.clear?  When I attempt even just a simple use I am getting compile errors relating to `template object.clear`.

From the documentation for Appender:

Note
clear is disabled for immutable or const element types, due to the possibility that Appender might overwrite immutable data.

Since string is immutable(char)[], clear() is simply not available for appender!string.


Isn't this wrong, though? Appender controls the memory it references. It could just choose to allocate non-immutable memory internally. As long as any const data put into the appender is *returned* as const, there is no chance of immutable memory being overwritten.

Appender is sometimes given a starting array. clear isn't callable in that case, and we don't distinguish the difference in the type or at runtime.

I did a lot of work on std.array.Appender when I redid the array runtime to fix array appending back in 2010 to make it safe. e.g.: https://github.com/schveiguy/phobos/commit/7e89201cdae96e71e550afe72b59ef3db145916f

Disabling clear from appender for non-mutable element types was one of the changes: https://github.com/schveiguy/phobos/commit/6636569318d26545bf7c36ddac029830a6d52531

This is before we were on github, so I don't know if there's any discussion of the issues, perhaps on the mailing list, but looking at my emails around that time, there are some emails that aren't in the mailing list.

A funny thing I wrote to Walter/Sean around that time, when I was just getting druntime commit access:

"I don't mind helping out in druntime, but I'm not really any kind of expert on the runtime, and I doubt I'll make many contributions besides this one without assignment."

;)

FYI, this thread is almost a year old.

-Steve

Reply via email to