Utils: Add clone functions to small string

Change-Id: I4e1ff40437253ce9fa047b476edb5d69654963b2
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2016-08-01 17:22:28 +02:00
parent 95ace75cc4
commit 4d29ca2d3a
2 changed files with 33 additions and 12 deletions

View File

@@ -887,5 +887,38 @@ QDataStream &operator>>(QDataStream &in, unordered_map<Key, Value, Hash, KeyEqua
} // namespace std
namespace Utils {
template<typename Key,
typename Value,
typename Hash = std::hash<Key>,
typename KeyEqual = std::equal_to<Key>,
typename Allocator = std::allocator<std::pair<const Key, Value>>>
std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>
clone(const std::unordered_map<Key, Value, Hash, KeyEqual, Allocator> &map)
{
std::unordered_map<Key, Value, Hash, KeyEqual, Allocator> clonedMap;
clonedMap.reserve(clonedMap.size());
for (auto &&entry : map)
clonedMap.emplace(entry.first, entry.second.clone());
return clonedMap;
}
template <typename Type>
std::vector<Type> clone(const std::vector<Type> &vector)
{
std::vector<Type> clonedVector;
clonedVector.reserve(vector.size());
for (auto &&entry : vector)
clonedVector.push_back(entry.clone());
return clonedVector;
}
} // namespace Utils
#pragma pop_macro("noexcept")
#pragma pop_macro("constexpr")

View File

@@ -148,18 +148,6 @@ private:
}
};
template <typename Type>
std::vector<Type> clone(const std::vector<Type> &vector)
{
std::vector<Type> clonedVector;
clonedVector.reserve(vector.size());
for (auto &&entry : vector)
clonedVector.push_back(entry.clone());
return clonedVector;
}
inline QDataStream &operator<<(QDataStream &out, const SmallStringVector &stringVector)
{
out << quint64(stringVector.size());