Skip to content

Commit

Permalink
Actually make getKey and getMapped usable with maps and vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Sep 12, 2023
1 parent a280483 commit bf75acd
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/MappingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ namespace k4EDM4hep2LcioConv {
}
}

/// Helper type alias that can be used to detect whether a T can be used
/// with std::get directly or whether it has to be dereferenced first
template<typename T>
using std_get_usable = decltype(std::get<0>(std::declval<T>()));

/**
* Helper function to get the Key from an Iterator (e.g. returned by
* mapInsert). This is necessary because map::emplace returns an iterator,
Expand All @@ -161,13 +166,12 @@ namespace k4EDM4hep2LcioConv {
template<typename It>
auto getKey(const It& it)
{
return std::get<0>(it);
}

template<typename It>
auto getKey(const It* it)
{
return std::get<0>(*it);
if constexpr (det::is_detected_v<std_get_usable, It>) {
return std::get<0>(it);
}
else {
return std::get<0>(*it);
}
}

/**
Expand All @@ -179,13 +183,12 @@ namespace k4EDM4hep2LcioConv {
template<typename It>
auto getMapped(const It& it)
{
return std::get<1>(it);
}

template<typename It>
auto getMapped(const It* it)
{
return std::get<1>(*it);
if constexpr (det::is_detected_v<std_get_usable, It>) {
return std::get<1>(it);
}
else {
return std::get<1>(*it);
}
}
} // namespace detail

Expand Down

0 comments on commit bf75acd

Please sign in to comment.