Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:26

0001 #ifndef FWCore_Utilities_transform_h
0002 #define FWCore_Utilities_transform_h
0003 
0004 #include <vector>
0005 #include <type_traits>
0006 
0007 namespace edm {
0008 
0009   // helper template function to build a vector applying a transformation to the elements of an input vector
0010   template <typename InputType, typename Function>
0011   auto vector_transform(std::vector<InputType> const& input, Function predicate)
0012       -> std::vector<
0013           typename std::remove_cv<typename std::remove_reference<decltype(predicate(input.front()))>::type>::type> {
0014     using ReturnType =
0015         typename std::remove_cv<typename std::remove_reference<decltype(predicate(input.front()))>::type>::type;
0016     std::vector<ReturnType> output;
0017     output.reserve(input.size());
0018     for (auto const& element : input)
0019       output.push_back(predicate(element));
0020     return output;
0021   }
0022 
0023 }  // namespace edm
0024 
0025 #endif  // FWCore_Utilities_transform_h