Debian Codegraph @

yo/classtemplates/examples/concretefriends.cc

raw
1 #include <iterator>
2 #include <istream>
3 #include <ctime>
4 #include <vector>
5 #include <algorithm>
6
7 #if 1
8
9 //FUNCTION
10 template <typename Type>
11 class Storage
12 {
13 friend void basic();
14 static size_t s_time;
15 std::vector<Type> d_data;
16 public:
17 Storage();
18 };
19 template <typename Type>
20 size_t Storage<Type>::s_time = 0;
21 template <typename Type>
22 Storage<Type>::Storage()
23 {}
24
25 void basic()
26 {
27 Storage<int>::s_time = time(0);
28 Storage<double> storage;
29 std::sort(storage.d_data.begin(), storage.d_data.end());
30 }
31 //=
32
33 // class Friend; // SF.
34
35 //CLASS
36 template <typename Type>
37 class Composer
38 {
39 friend class Friend;
40 std::vector<Type> d_data;
41 public:
42 Composer();
43 };
44
45 class Friend
46 {
47 Composer<int> d_ints;
48 public:
49 Friend(std::istream &input);
50 };
51
52 inline::Friend::Friend(std::istream &input)
53 {
54 std::copy(std::istream_iterator<int>(input),
55 std::istream_iterator<int>(),
56 back_inserter(d_ints.d_data));
57 }
58 //=
59
60 #else
61
62 //MEMBER
63 template <typename Type>
64 class Composer;
65
66 class Friend
67 {
68 Composer<int> *d_ints;
69 public:
70 Friend(std::istream &input);
71 void sorter();
72 };
73
74 template <typename Type>
75 class Composer
76 {
77 friend void Friend::sorter();
78 std::vector<Type> d_data;
79 public:
80 Composer(std::istream &input)
81 {
82 std::copy(std::istream_iterator<int>(input),
83 std::istream_iterator<int>(),
84 back_inserter(d_data));
85 }
86 };
87
88 inline Friend::Friend(std::istream &input)
89 :
90 d_ints(new Composer<int>{ input })
91 {}
92
93 inline void Friend::sorter()
94 {
95 std::sort(d_ints->d_data.begin(), d_ints->d_data.end());
96 }
97 //=
98
99 #endif