Still, that code cannot be compiled, right?
inout is a wildcard that should be able to take place of const and immutable but std.array.replace cannot work with const(char)[] nor with immutable(char)[].
Comment #2 by andrej.mitrovich — 2014-03-27T04:12:05Z
(In reply to comment #1)
> Still, that code cannot be compiled, right?
>
> inout is a wildcard that should be able to take place of const and immutable
> but std.array.replace cannot work with const(char)[] nor with
> immutable(char)[].
I thought it was supposed to allocate a new array to store the result to?
Comment #3 by monarchdodra — 2014-03-27T04:43:21Z
(In reply to comment #2)
> (In reply to comment #1)
> > Still, that code cannot be compiled, right?
> >
> > inout is a wildcard that should be able to take place of const and immutable
> > but std.array.replace cannot work with const(char)[] nor with
> > immutable(char)[].
>
> I thought it was supposed to allocate a new array to store the result to?
Seems that way:
http://dlang.org/phobos/std_array.html#replace
Replace occurrences of from with to in subject. Returns a new array without changing the contents of subject, or the original array if no match is found.
/----
import std.array, std.stdio;
void main()
{
int[] c = [1, 2, 3];
c.replace([2], [4, 4]).writeln(); //[1, 4, 4, 3];
c.writeln(); //[1, 2, 3];
c.idup.replace([2], [4, 4]).writeln(); //[1, 4, 4, 3];
}
//----
Ali must be thinking about "replaceInPlace" ?
Comment #4 by acehreli — 2014-03-27T10:40:12Z
Sorry for the noise. :( Yes, I thought it was in-place.
Comment #5 by andrej.mitrovich — 2014-04-23T19:58:13Z
It seems the bottom-line problem is this:
-----
import std.array;
import std.range;
inout(char)[] sanitize(inout(char)[] input)
{
auto app = appender!(inout(char)[])();
// fails because of inout(char) as the element type
static assert(isOutputRange!(typeof(app), inout(char)));
}
-----
And it fails because of this strange nested declaration inside of the put method:
@property ref E[] EArrayInit(); //@@@9186@@@: Can't use (E[]).init
std\range.d(656): Error: inout on return means inout must be on a parameter as well for @property ref inout(char)[]()
I guess this was some kind of funky workaround, but it causes issues for 12470. I'm not sure how to proceed yet.
Comment #6 by github-bugzilla — 2017-09-13T19:07:19Z