View source code
Display the source code in std/array.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

std.array.replaceInto - multiple declarations

Function replaceInto

Replace occurrences of from with to in subject and output the result into sink.

void replaceInto(E, Sink, R1, R2) (
  Sink sink,
  E[] subject,
  R1 from,
  R2 to
)
if (isOutputRange!(Sink, E) && (isForwardRange!R1 && isForwardRange!R2 && (hasLength!R2 || isSomeString!R2) || is(Unqual!E : Unqual!R1)));

Parameters

NameDescription
sink an output range
subject the array to scan
from the item to replace
to the item to replace all instances of from with

See Also

substitute for a lazy replace.

Example

auto arr = [1, 2, 3, 4, 5];
auto from = [2, 3];
auto to = [4, 6];
auto sink = appender!(int[])();

replaceInto(sink, arr, from, to);

writeln(sink.data); // [1, 4, 6, 4, 5]

Function replaceInto

Replace occurrences of from with to in subject and output the result into sink. changed counts how many replacements took place.

void replaceInto(E, Sink, R1, R2) (
  Sink sink,
  E[] subject,
  R1 from,
  R2 to,
  ref size_t changed
)
if (isOutputRange!(Sink, E) && (isForwardRange!R1 && isForwardRange!R2 && (hasLength!R2 || isSomeString!R2) || is(Unqual!E : Unqual!R1)));

Parameters

NameDescription
sink an output range
subject the array to scan
from the item to replace
to the item to replace all instances of from with
changed the number of replacements

Example

auto arr = [1, 2, 3, 4, 5];
auto from = [2, 3];
auto to = [4, 6];
auto sink = appender!(int[])();

size_t changed = 0;
replaceInto(sink, arr, from, to, changed);

writeln(sink.data); // [1, 4, 6, 4, 5]
writeln(changed); // 1

Authors

Andrei Alexandrescu and Jonathan M Davis

License

Boost License 1.0.