Files
comaps/base/collection_cast.hpp
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

30 lines
805 B
C++

#pragma once
#include <type_traits>
namespace base
{
namespace details
{
template <typename T>
struct ValueType
{
using TType = typename std::remove_reference_t<T>::value_type;
};
template <typename T>
using TValueType = typename ValueType<T>::TType;
} // namespace details
// Use this function to cast one collection to annother.
// I.E. list<int> const myList = collection_cast<list>(vector<int>{1, 2, 4, 5});
// More examples:
// auto const mySet = collection_cast<set>("aaabcccd");
// auto const myMap = collection_cast<map>(vector<pair<int, int>>{{1, 2}, {3, 4}});
template <template<typename ... TArgs> class TTo, typename TFrom>
auto collection_cast(TFrom && from) -> TTo<details::TValueType<TFrom>>
{
return TTo<details::TValueType<TFrom>>(begin(from), end(from));
}
} // namespace base