Welcome to mirror list, hosted at ThFree Co, Russian Federation.

collection_cast.hpp « base - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8ba6844bbbd9b5a593410c56b6910b3aa27c8038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once

#include <type_traits>

namespace my
{
namespace details
{
template <typename T>
struct ValueType
{
  using TType = typename std::remove_reference<T>::type::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 my