View source code
Display the source code in std/algorithm/mutation.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.

Function std.algorithm.mutation.moveEmplaceSome

Same as moveSome but assumes all elements in tgt are uninitialized. Uses moveEmplace to move elements from src over elements from tgt.

Tuple!(InputRange1,InputRange2) moveEmplaceSome(InputRange1, InputRange2) (
  InputRange1 src,
  InputRange2 tgt
) @system
if (isInputRange!InputRange1 && isInputRange!InputRange2 && is(typeof(move(src.front, tgt.front))));

Example

static struct Foo
{
    ~this() pure nothrow @nogc { if (_ptr) ++*_ptr; }
    int* _ptr;
}
int[4] refs = [0, 1, 2, 3];
Foo[4] src = [Foo(&refs[0]), Foo(&refs[1]), Foo(&refs[2]), Foo(&refs[3])];
Foo[3] dst = void;

auto res = moveEmplaceSome(src[], dst[]);
writeln(res.length); // 2

import std.algorithm.searching : all;
assert(src[0 .. 3].all!(e => e._ptr is null));
assert(src[3]._ptr !is null);
assert(dst[].all!(e => e._ptr !is null));

Authors

Andrei Alexandrescu

License

Boost License 1.0.