On Saturday, 30 April 2016 at 18:32:32 UTC, ag0aep6g wrote:
On 30.04.2016 18:44, TheGag96 wrote:
I was just writing some code trying to remove a value from a character array, but the compiler complained "No overload matches for remove", and if I specifically say use std.algorithm.remove() the compiler doesn't think it fits any definition. For reference, this would be all I'm doing:

char[] thing = ['a', 'b', 'c'];
thing = thing.remove(1);

Is this a bug? std.algorithm claims remove() works on any forward range...

The documentation is wrong.

1) remove requires a bidirectional range. The constraints and parameter documentation correctly say so. char[] is a bidirectional range, though.

2) remove requires lvalue elements. char[] fails this, as the range primitives decode the chars on-the-fly to dchars.

Pull request to fix the documentation:
https://github.com/dlang/phobos/pull/4271

By the way, I think requiring lvalues is too restrictive. It should work with assignable elements. Also, it has apparently been missed that const/immutable can make non-assignable lvalues.

There's a ticket open related to the lvalue element requirement: https://issues.dlang.org/show_bug.cgi?id=8930

Personally, I think this example is more compelling than the one in the ticket. It seems very reasonable to expect that std.algorithm.remove will work regardless of whether the elements are characters, integers, ubytes, etc.

If an initial step is to fix the documentation, it would be helpful to include specifically that it doesn't work with characters. It's not obvious that characters don't meet the requirement.

--Jon

Reply via email to