Made assets::data_stores thread safe.
This commit is contained in:
33
include/util/vector_replace_range.hpp
Normal file
33
include/util/vector_replace_range.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user