fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. class C {
  5. public:
  6. void do_whatever() const {}
  7. };
  8.  
  9. template<class T>
  10. const T &apply_helper( const T *t ) { return *t; }
  11.  
  12. template<class T>
  13. typename std::enable_if<!std::is_pointer<T>::value, const T &>::type
  14. apply_helper( const T &t ) { return t; }
  15.  
  16.  
  17.  
  18. template<class T,typename Func>
  19. void apply( const std::vector<T> &v, Func f )
  20. {
  21. for( const auto &i : v ) f( apply_helper( i ) );
  22. }
  23.  
  24.  
  25.  
  26. int main() {
  27. std::vector<C> vc;
  28. std::vector<C*> vp;
  29. auto call = []( const C &c ) { c.do_whatever(); };
  30. apply( vc, call );
  31. apply( vp, call );
  32. return 0;
  33. }
Success #stdin #stdout 0s 4492KB
stdin
Standard input is empty
stdout
Standard output is empty