13 #ifndef LARCOREALG_COREUTILS_MAKEVALUEINDEX_H 14 #define LARCOREALG_COREUTILS_MAKEVALUEINDEX_H 26 #include <type_traits> 55 template <
typename Coll,
typename Extractor>
58 template <typename Coll>
69 template <
typename Coll,
typename Extractor>
73 using Value_t =
typename Coll::value_type;
75 #if 0 // this is C++17... 76 = std::remove_reference_t<std::invoke_result_t<Extractor, Value_t>>;
77 #else // ... and this is what Clang 5.0 understands: 78 = std::remove_reference_t<decltype(getter(std::declval<Value_t>()))>;
81 using Map_t = std::map<Key_t, std::size_t>;
86 Key_t
const& key = getter(collValue);
87 auto const iKey = index.lower_bound(key);
88 if ((iKey != index.end()) && (iKey->first == key)) {
90 throw std::runtime_error(std::string(__func__) +
": element #" +
std::to_string(iValue) +
93 index.emplace_hint(iKey, key, iValue);
102 #endif // LARCOREALG_COREUTILS_MAKEVALUEINDEX_H Namespace for general, non-LArSoft-specific utilities.
Definition of util::enumerate().
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.