My advice is to time it. In programming speculating about what code should do is wrong, until you try it hands on you have no way of knowing. Time the first example 3 times, get the average time. And do the same thing for the second example. That's how you will for sure know which one is faster.
I don't think something that small you should even be bothered with efficiency. Anyways, depending on how many 0's there are the second method could be slower.
If efficiency is really a factor, then you can decide to store only the indexes containing a value in a symbol table such as std::map. Then your key, value pair is made up of an index and the value at that index so std::pair<int, int>.
Note that the use of std::unordered_map will not work in this case since you want the indices to be in their natural order, which std::unordered_map does not guarantee
> move everything no matter what the value is or make a if statement will be faster?
std::copy() would do it in the fastest possible way.
In practice, implementations of std::copy avoid multiple assignments and use bulk copy functions such as std::memmove if the value type is TriviallyCopyable
When copying overlapping ranges, std::copy is appropriate when copying to the left (beginning of the destination range is outside the source range) while std::copy_backward is appropriate when copying to the right (end of the destination range is outside the source range). http://en.cppreference.com/w/cpp/algorithm/copy