Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
functor-state.cpp
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iostream>
3 #include <vector>
4 
5 class Sum
6 {
7 public:
8  Sum() : m_total(0) {}
9  void operator()(int value) { m_total += value; }
10 
11  friend std::ostream& operator<<(std::ostream& os, Sum& s)
12  {
13  os << s.m_total;
14  return os;
15  }
16 
17 private:
18  int m_total;
19 };
20 
21 int main()
22 {
23  std::vector<int> vect({1, 2, 3, 4, 5, 6});
24  Sum sum = for_each(vect.begin(), vect.end(), Sum());
25  std::cout << sum << std::endl;
26  return 0;
27 }
std::ostream & operator<<(std::ostream &out, std::pair< T, U > const &p)
Definition: Range.h:46
C::value_type sum(C const &c)
Definition: sum1.cpp:26
int main()