#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>

template <class InputIterator1, class InputIterator2,
          class OutputIterator>
  OutputIterator merge_alternately ( InputIterator1 first1, InputIterator1 last1,
                                     InputIterator2 first2, InputIterator2 last2,
                                     OutputIterator result)
 {
        size_t ct(0);
        while(first1 != last1
          and first2 != last2)
                *result++ = (++ct % 2 ? *first1++ : *first2++);

        std::copy(first1, last1, result);
        std::copy(first2, last2, result);

        return result;
 }

int main()
{

        std::vector<int> const a{1, 2, 3, 4, 5,},
                               b{6, 7, 8, 9, 10};
        std::vector<int>       c;

        merge_alternately(a.begin(), a.end(),
                          b.begin(), b.end(),
                          std::back_inserter(c));

        std::copy(c.begin(), c.end(), std::ostream_iterator<int>(std::cout, ", "));
}