I'm consolidating some routines from std.string into std.array. They are specialized for operating on arrays, and include the likes of insert, remove, replace.

One question is whether operations should be performed in place or on a copy. For example:

string s = "Mary has a lil lamb.";
// Implicit copy
auto s1 = replace(s, "lil", "li'l");
assert(s == "Mary has a lil lamb.");
// Explicit in-place
replaceInPlace(s, "lil", "li'l");
assert(s == "Mary has a li'l lamb.");

So that would make copying the default behavior. Alternatively, we could make in-place the default behavior and ask for the Copy suffix:

string s = "Mary has a lil lamb.";
// Explicit copy
auto s1 = replaceCopy(s, "lil", "li'l");
assert(s == "Mary has a lil lamb.");
// Implicit in-place
replace(s, "lil", "li'l");
assert(s == "Mary has a li'l lamb.");


Thoughts?

Andrei

Reply via email to