Follow-up from "Fix compile time warning from !1118"
The following discussion from !1130 (merged) should be addressed:
-
@graven started a discussion: (+1 comment) can we please, instead of having a loop with an 'if and break' construction just use
std::find_if
, and avoid first initializing and then overwriting a local variable?auto i = std::find_if( m_handles.begin(), m_handles.end(), [](const auto& data) { return data.mode() == Gaudi::DataHandle::Writer && data.objKey() == "Renounce" ; } ); const DataObjID* renounce_id = ( i != m_handles.end() ? &(i->fullKey()) : nullptr;
and even better, properly deal with the fact that as-is,
renounce_id
may be a nullptr, and thus L130 will SEGV, and thus is would be better to put that code insideauto i = std::find_if( m_handles.begin(), m_handles.end(), [](const auto& data) { return data.mode() == Gaudi::DataHandle::Writer && data.objKey() == "Renounce" ; } ); if ( i!= m_handles.end() ) { TestTool::Logger logger; RenounceToolInputsVisitor renouncer( std::vector<DataObjID>( {i->fullKey()} ), logger ); DEBUG_TRACE( std::cout << "DEBUG " << name() << " renounce tools " << "Renounce" << std::endl ); ToolVisitor::visit( tools(), renouncer ); }
I know this is 'just' test code, but I would still prefer a more idiomatic, clearer style even there...
Edited by Marco Clemencic