Debian Codegraph @

yo/concrete/examples/foreachdemo.cc

raw
1 #include <iostream>
2 #include <string>
3 #include <vector>
4 #include "foreach.h"
5
6 //VECTOR2
7 template <typename Type>
8 class Vector2: public std::vector<std::vector<Type> >
9 {
10 using iterator = typename Vector2<Type>::iterator;
11
12 template <typename Iterator, typename Class, typename Data>
13 friend Class &ForEach(Iterator begin, Iterator end, Class &object,
14 void (Class::*member)(Data &));
15 public:
16 void process();
17
18 private:
19 void rows(std::vector<Type> &row);
20 void columns(Type &str);
21 };
22
23 template <typename Type>
24 void Vector2<Type>::process()
25 {
26 ForEach<iterator, Vector2<Type>, std::vector<Type> >
27 (this->begin(), this->end(), *this, &Vector2<Type>::rows);
28 }
29
30 template <typename Type>
31 void Vector2<Type>::rows(std::vector<Type> &row)
32 {
33 ForEach(row.begin(), row.end(), *this,
34 &Vector2<Type>::columns);
35 std::cout << '\n';
36 }
37
38 template <typename Type>
39 void Vector2<Type>::columns(Type &str)
40 {
41 std::cout << str << " ";
42 }
43
44 using namespace std;
45
46 int main()
47 {
48 Vector2<string> c;
49 c.push_back(vector<string>(3, "Hello"));
50 c.push_back(vector<string>(2, "World"));
51
52 c.process();
53 }
54 /*
55 Generated output:
56
57 Hello Hello Hello
58 World World
59 */
60 //=