1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <iostream>
20 #include <vector>
21
22 namespace vect{
23
24
25 ¦
26 ¦
27 ¦
28 ¦
29 ¦
30
31 template < class T >
32 class Lvalue
33 {
34 public:
35
36
37 Lvalue (){};
38 Lvalue (std::vector<T> in): _ofthings{in}{};
39 Lvalue ( const Lvalue &other );
40 ~Lvalue (){};
41
42
43 std::vector<T>& ofthings(){
44 return _ofthings;
45 };
46
47 void ofthings(std::vector<T> const vec){
48 _ofthings = vec;
49 };
50
51
52
53
54 const Lvalue& operator = ( const Lvalue &other );
55 T& operator [] (int index)
56 {
57 return (ofthings()[index]);
58 };
59 friend std::ostream &operator << (std::ostream &os, const Lvalue in)
60 {
61 for(int i = 0; i < in._ofthings.size(); i++ ){
62 std::cout << i << "\t";
63 }
64 return os;
65 };
66
67
68 protected:
69 std::vector<T> _ofthings;
70
71 private:
72
73 };
74
75 };
76
77
78 int main ( int argc, char *argv[] )
79 {
80
81 std::cout << "TEST INPUT TO VECTOR" << std::endl;
82 std::vector<int> test(100, 0);
83 for(int i = 0; i<10; i++ ){
84 test[i] = i;
85 std::cout << i << "::" <<test[i] << "\t";
86 }
87 std::cout << std::endl;
88 std::cout << "TEST INPUT TO OBJECT" << std::endl;
89 vect::Lvalue<int> test2 {test};
90 for(int j = 0, i=10; j < 10; i--, j++){
91 test[j] = i;
92 std::cout << "What is J" << j << std::endl;
93 std::cout << "i: " << i << " j: " << j << " test[j]: " << test[j] << std::endl;
94 std::cout << "i: " << i << " j: " << j << " test2[j]: " << test[j] << std::endl;
95 }
96 std::cout << std::endl;
97 std::cout << "TEST INPUT TO OBJECT bidirectional" << std::endl;
98 for(int i = 0, j=10; i < 10; i++, j++){
99 test2[i] = j;
100 std::cout << "What is i ==>" << i << std::endl;
101 std::cout << "i: " << i << " j: " << j << " test2[i]: " << test2[i] << std::endl;
102 std::cout << "i: " << i << " j: " << j << " test[i]: " << test[i] << std::endl;
103 }
104 std::cout << std::endl;
105 std::cout << std::endl;
106 for(int j = 0, i=10; j < 10; i--, j++){
107 test[j] = i;
108 std::cout << "What is J" << j << std::endl;
109 std::cout << "i: " << i << " j: " << j << " test[j]: " << test[j] << std::endl;
110 std::cout << "i: " << i << " j: " << j << " test2[j]: " << test[j] << std::endl;
111 }
112 std::cout << "__DONE__" << std::endl;
113
114
115
116 return EXIT_SUCCESS;
117 }