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