tl;dr
Call reserve()
and copy.
What's wrong with moving?
Several things. First, the expectation that you seem to have about std::move
is wrong. std::move
does not magically move anything (or moves anything at all, including non-magically). What it does is a cast to a rvalue reference, which may enable moving under some conditions.
Second, beginning with C++03, std::vector
is guaranteed to have its element contiguously laid out in memory (before C++03 it was factually the case anyway, but no explicit guarantee was given). If you use std::move
then you necessarily use a version later than C++03, so std::vector
necessarily lays out its elements contiguously.
Which means that except for the totally coincidal case that the two arrays happen to be adjacent to each other, there is no way of getting the elements from two arrays into a vector without copying. It's simply not possible to move them because at least one array must be relocated (= copied).
Further, I couldn't imagine how moving elements from an array the way you intend to do it would be possible in the first place. Moving assumes that you take over ownership, which usually means you modify the moved-from object in some way so that it is still valid, but without whatever resources it owned previously.
How do you do that with an array that has automatic storage duration in a surrounding scope? What is dereferencing the array after the move (which is possible and legitimate) going to do then?
Also, you want to decay an array to a pointer (that's perfectly legal) and then somehow magically move. That, however, does not move the contents of the array! The best you can do is move the pointer, but that doesn't make sense since moving a pointer is just the same as copying it.
There is no way you're getting around having to copy the array elements, but you can save one memory allocation and one needless copy by properly calling reserve()
ahead of time.