CMS 3D CMS Logo

transform.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_transform_h
2 #define FWCore_Utilities_transform_h
3 
4 #include <vector>
5 #include <type_traits>
6 
7 namespace edm {
8 
9  // helper template function to build a vector applying a transformation to the elements of an input vector
10  template <typename InputType, typename Function>
11  auto vector_transform(std::vector<InputType> const& input, Function predicate) -> std::vector<
12  typename std::remove_cv<typename std::remove_reference<decltype(predicate(input.front()))>::type>::type> {
13  using ReturnType =
14  typename std::remove_cv<typename std::remove_reference<decltype(predicate(input.front()))>::type>::type;
15  std::vector<ReturnType> output;
16  output.reserve(input.size());
17  for (auto const& element : input)
18  output.push_back(predicate(element));
19  return output;
20  }
21 
22 } // namespace edm
23 
24 #endif // FWCore_Utilities_transform_h
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
static std::string const input
Definition: EdmProvDump.cc:50
std::map< DetId, double > ReturnType
HLT enums.