13 #ifndef LARCOREALG_COREUTILS_MAKEVALUEINDEX_H 14 #define LARCOREALG_COREUTILS_MAKEVALUEINDEX_H 21 #include "range/v3/view/enumerate.hpp" 28 #include <type_traits> 57 template <
typename Coll,
typename Extractor>
60 template <typename Coll>
71 template <
typename Coll,
typename Extractor>
74 using Value_t =
typename Coll::value_type;
75 using Key_t = std::remove_reference_t<std::invoke_result_t<Extractor, Value_t>>;
77 using Map_t = std::map<Key_t, std::size_t>;
82 Key_t
const& key = getter(collValue);
83 auto const iKey = index.lower_bound(key);
84 if ((iKey != index.end()) && (iKey->first == key)) {
86 throw std::runtime_error(std::string(__func__) +
": element #" +
std::to_string(iValue) +
89 index.emplace_hint(iKey, key, iValue);
97 #endif // LARCOREALG_COREUTILS_MAKEVALUEINDEX_H Namespace for general, non-LArSoft-specific utilities.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
Transparent functor that returns its argument just as passed.
Functions to help debugging by instrumenting code.
decltype(auto) makeValueIndex(Coll const &coll, Extractor getter)
Returns a map of value to index.
Code that might appear as standard C++ in the future.