34 lines
684 B
C++
34 lines
684 B
C++
#pragma once
|
|
|
|
|
|
#include <algorithm>
|
|
#include <vector>
|
|
|
|
namespace ztu
|
|
{
|
|
|
|
template<class T, class Allocator, class InputIt>
|
|
void replace_range(
|
|
std::vector<T, Allocator>& dst,
|
|
typename std::vector<T, Allocator>::iterator dst_begin,
|
|
typename std::vector<T, Allocator>::iterator dst_end,
|
|
InputIt src_begin,
|
|
InputIt src_end
|
|
) {
|
|
const auto dst_size = std::distance(dst_begin, dst_end);
|
|
const auto src_size = std::distance(src_begin, src_end);
|
|
|
|
if (dst_size < src_size)
|
|
{
|
|
dst.insert(dst_end, src_begin + dst_size, src_end);
|
|
}
|
|
else if (dst_size > src_size)
|
|
{
|
|
dst.erase(dst_begin + src_size, dst_end);
|
|
}
|
|
|
|
std::copy_n(src_begin, std::min(src_size, dst_size), dst_begin);
|
|
}
|
|
|
|
}
|