makrusak

templates

Feb 18th, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <string>
  7. #include <string.h>
  8. #include <queue>
  9. #include <stack>
  10. #include <deque>
  11. #include <map>
  12. #include <set>
  13. #include <cmath>
  14. #include <sstream>
  15. #include <ctime>
  16.  
  17. #define pb push_back
  18. #define mp make_pair
  19. #define PI 3.1415926535897932384626433832795
  20. #define ALL(x) x.begin(), x.end()
  21. #define F first
  22. #define S second
  23. #define m0(x) memset(x,0,sizeof(x))
  24. #define m1(x) memset(x,-1,sizeof(x))
  25. #define pw(x) (1ull<<(x))
  26.  
  27. using namespace std;
  28. typedef long long ll;
  29. typedef unsigned long long ull;
  30. typedef long double ld;
  31. typedef pair<int,int> pii;
  32. const int INF = 2147483647;
  33. const ll LLINF = 9223372036854775807LL;
  34.  
  35. template< typename Container>
  36. typename Container::value_type sum(Container x) {
  37.   typename Container::value_type ans = *x.begin();
  38.   for (typename Container::iterator it = ++x.begin();it!=x.end();it++) ans+=*it;
  39.   return ans;
  40. }
  41.  
  42. int main() {
  43.   //freopen("input.txt", "r", stdin);
  44.   //freopen("output.txt", "w", stdout);
  45.   vector<int> x;
  46.   for (int i=0;i<5;i++) x.pb(i);
  47.   cout << sum(x) << "\n";
  48.   return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment