Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:20

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) -> std::vector<
0012       typename std::remove_cv<typename std::remove_reference<decltype(predicate(input.front()))>::type>::type> {
0013     using ReturnType =
0014         typename std::remove_cv<typename std::remove_reference<decltype(predicate(input.front()))>::type>::type;
0015     std::vector<ReturnType> output;
0016     output.reserve(input.size());
0017     for (auto const& element : input)
0018       output.push_back(predicate(element));
0019     return output;
0020   }
0021 
0022 }  // namespace edm
0023 
0024 #endif  // FWCore_Utilities_transform_h