28 #include <unordered_map>
54 template<class ContainerT, class IndexIteratorT, class OutputIteratorT, class IndexT = typename std::iterator_traits<IndexIteratorT>::value_type>
55 void copyValuesAt(
const ContainerT& src, IndexIteratorT fst, IndexIteratorT lst, OutputIteratorT dest)
81 template<
class ContainerT,
class IndexContainerT,
class OutputIteratorT,
class IndexT =
typename IndexContainerT::value_type>
82 void copyValuesAt(
const ContainerT& src,
const IndexContainerT& idx, OutputIteratorT dest)
103 template<class ContainerT, class IndexIteratorT, class IndexT = typename std::iterator_traits<IndexIteratorT>::value_type>
104 std::vector<typename ContainerT::value_type>
copyValuesAt(
const ContainerT& src, IndexIteratorT fst, IndexIteratorT lst)
106 std::vector<typename ContainerT::value_type> result;
108 copyValuesAt(src, std::move(fst), std::move(lst), std::back_inserter(result));
128 template<
class ContainerT,
class IndexContainerT,
class IndexT =
typename IndexContainerT::value_type>
129 std::vector<typename ContainerT::value_type>
copyValuesAt(
const ContainerT& src,
const IndexContainerT& idx)
140 template<
class T,
class MapType = std::unordered_map<
typename T::value_type,
typename T::
size_type>>
144 result.reserve(vec.size());
145 for (
typename T::size_type i = 0; i < vec.size(); ++i)
147 auto emplacement = result.emplace(vec.at(i), i).second;
150 throw std::invalid_argument {
"The given container did not contain unique elements!"};
156 template<
class MapType,
class OutputIteratorType>
159 for (
const auto& e : map)
166 template<
class MapType>
167 std::vector<typename MapType::key_type>
getMapKeys(
const MapType& map)
169 std::vector<typename MapType::key_type> result;
170 result.reserve(map.size());
175 template<
class MapType,
class OutputIteratorType>
178 for (
const auto& e : map)
185 template<
class MapType,
template<
class...>
class ContainerT = std::vector>
186 ContainerT<typename MapType::mapped_type>
getMapValues(
const MapType& map)
188 ContainerT<typename MapType::mapped_type> result;
196 return t < 0 ? -1 : 1;
203 template<
typename It0,
typename ...It>
222 template <
typename T>
226 #pragma GCC diagnostic push
228 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
233 for (
auto& elem : newMap)
235 if (oldMap.count(elem.first))
237 throw std::invalid_argument {
"mergeMaps: newMap would override values from oldMap"};
242 for (
auto& elem : newMap)
244 oldMap[elem.first] = elem.second;
248 for (
auto& elem : newMap)
250 oldMap.emplace(elem);
254 #pragma GCC diagnostic pop
257 template <
class MapInT,
class TransformT,
class MapOutT = MapInT>
260 for (
const auto& elem : inMap)
262 outMap[
transform(elem.first)] = elem.second;
266 template <
class MapInT,
class TransformT,
class MapOutT = MapInT>
274 template <
class KeyT,
class ValT>
280 template <
class KeyT,
class ValT>
281 std::vector<KeyT>
getIndices(
const std::unordered_map<KeyT, ValT>&
c)
286 template <
class ValT>
289 std::vector<std::size_t> r(
c.size());
290 std::iota(r.begin(), r.end(), 0);
294 template <
class ContainerType,
class ElementType>
297 return std::find(container.begin(), container.end(), searchElement) != container.end();
314 template <
class OutputT,
class InputT,
typename Alloc,
template <
class,
class>
class Container>
315 auto transform(
const Container<InputT, Alloc>& in, OutputT(*func)(InputT
const&))
316 -> Container<OutputT, typename std::allocator_traits<Alloc>::template rebind_alloc<OutputT> >
318 Container<OutputT, typename std::allocator_traits<Alloc>::template rebind_alloc<OutputT>> result;
319 result.reserve(in.size());
320 std::transform(in.begin(), in.end(), std::back_inserter(result), func);
326 template<
class T,
class...Ts>
329 return std::all_of(
v.begin(),
v.end(), [](
const T & t)