29 #include <unordered_map>
54 template <
class ContainerT,
56 class OutputIteratorT,
57 class IndexT =
typename std::iterator_traits<IndexIteratorT>::value_type>
64 std::transform(fst, lst, dest, [&src](
const IndexT& i) {
return src.at(i); });
85 template <
class ContainerT,
86 class IndexContainerT,
87 class OutputIteratorT,
88 class IndexT =
typename IndexContainerT::value_type>
90 copyValuesAt(
const ContainerT& src,
const IndexContainerT& idx, OutputIteratorT dest)
111 template <
class ContainerT,
112 class IndexIteratorT,
113 class IndexT =
typename std::iterator_traits<IndexIteratorT>::value_type>
114 std::vector<typename ContainerT::value_type>
115 copyValuesAt(
const ContainerT& src, IndexIteratorT fst, IndexIteratorT lst)
117 std::vector<typename ContainerT::value_type> result;
119 copyValuesAt(src, std::move(fst), std::move(lst), std::back_inserter(result));
139 template <
class ContainerT,
140 class IndexContainerT,
141 class IndexT =
typename IndexContainerT::value_type>
142 std::vector<typename ContainerT::value_type>
154 class MapType = std::unordered_map<typename T::value_type, typename T::size_type>>
159 result.reserve(vec.size());
160 for (
typename T::size_type i = 0; i < vec.size(); ++i)
162 auto emplacement = result.emplace(vec.at(i), i).second;
165 throw std::invalid_argument{
"The given container did not contain unique elements!"};
171 template <
class MapType,
class OutputIteratorType>
175 for (
const auto& e : map)
182 template <
class MapType>
183 std::vector<typename MapType::key_type>
186 std::vector<typename MapType::key_type> result;
187 result.reserve(map.size());
192 template <
class MapType,
class OutputIteratorType>
196 for (
const auto& e : map)
203 template <
class MapType,
template <
class...>
class ContainerT = std::vector>
204 ContainerT<typename MapType::mapped_type>
207 ContainerT<typename MapType::mapped_type> result;
216 return t < 0 ? -1 : 1;
227 template <
typename It0,
typename... It>
247 template <
typename T>
254 #pragma GCC diagnostic push
256 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
261 for (
auto& elem : newMap)
263 if (oldMap.count(elem.first))
265 throw std::invalid_argument{
266 "mergeMaps: newMap would override values from oldMap"};
271 for (
auto& elem : newMap)
273 oldMap[elem.first] = elem.second;
277 for (
auto& elem : newMap)
279 oldMap.emplace(elem);
283 #pragma GCC diagnostic pop
286 template <
class MapInT,
class TransformT,
class MapOutT = MapInT>
290 for (
const auto& elem : inMap)
292 outMap[
transform(elem.first)] = elem.second;
296 template <
class MapInT,
class TransformT,
class MapOutT = MapInT>
305 template <
class KeyT,
class ValT>
312 template <
class KeyT,
class ValT>
319 template <
class ValT>
320 std::vector<std::size_t>
323 std::vector<std::size_t> r(
c.size());
324 std::iota(r.begin(), r.end(), 0);
328 template <
class ContainerType,
class ElementType>
332 return std::find(container.begin(), container.end(), searchElement) != container.end();
349 template <
class OutputT,
class InputT,
typename Alloc,
template <
class,
class>
class Container>
351 transform(
const Container<InputT, Alloc>& in, OutputT (*func)(InputT
const&))
352 -> Container<OutputT, typename std::allocator_traits<Alloc>::template rebind_alloc<OutputT>>
354 Container<OutputT, typename std::allocator_traits<Alloc>::template rebind_alloc<OutputT>>
356 result.reserve(in.size());
357 std::transform(in.begin(), in.end(), std::back_inserter(result), func);
364 template <
class T,
class... Ts>
368 return std::all_of(
v.begin(),
v.end(), [](
const T& t) { return isfinite(t); });