Skip to content

Commit

Permalink
Use contains and std::ranges::find from C++20
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell authored and tmadlener committed Aug 21, 2024
1 parent 20afa8e commit ad7d497
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions test/hepmc/edm4hep_testhepmc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int main() {
std::cout << "Converting particle with PDG ID: " << particle_i->pdg_id() << std::endl;
std::cout << "\t and id: " << particle_i->id() << std::endl;

if (hepmcToEdmMap.find(particle_i->id()) == hepmcToEdmMap.end()) {
if (!hepmcToEdmMap.contains(particle_i->id())) {
auto edm_particle = convert(particle_i);
hepmcToEdmMap.insert({particle_i->id(), edm_particle});
}
Expand All @@ -124,7 +124,7 @@ int main() {
if (nullptr != prodvertex) {

for (auto particle_mother : prodvertex->particles_in()) {
if (hepmcToEdmMap.find(particle_mother->id()) == hepmcToEdmMap.end()) {
if (!hepmcToEdmMap.contains(particle_mother->id())) {
auto edm_particle = convert(particle_mother);
hepmcToEdmMap.insert({particle_mother->id(), edm_particle});
}
Expand All @@ -136,7 +136,7 @@ int main() {
if (nullptr != prodvertex) {

for (auto particle_daughter : prodvertex->particles_in()) {
if (hepmcToEdmMap.find(particle_daughter->id()) == hepmcToEdmMap.end()) {
if (!hepmcToEdmMap.contains(particle_daughter->id())) {
auto edm_particle = convert(particle_daughter);
hepmcToEdmMap.insert({particle_daughter->id(), edm_particle});
}
Expand Down
2 changes: 1 addition & 1 deletion utils/src/ParticleIDUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ParticleIDMeta::ParticleIDMeta(const std::string& algName, const std::vector<std
}

std::optional<int> getParamIndex(const ParticleIDMeta& pidMetaInfo, const std::string& param) {
const auto nameIt = std::find(pidMetaInfo.paramNames.begin(), pidMetaInfo.paramNames.end(), param);
const auto nameIt = std::ranges::find(pidMetaInfo.paramNames, param);
if (nameIt != pidMetaInfo.paramNames.end()) {
return std::distance(pidMetaInfo.paramNames.begin(), nameIt);
}
Expand Down

0 comments on commit ad7d497

Please sign in to comment.