-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContainer.hpp
104 lines (77 loc) · 1.6 KB
/
Container.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/** Container Class
** Standardizes all inserts, pops, updates, etc for a container so that these functions are independent of type
**/
using namespace std;
template <typename V>
class Container{
private:
public:
/** Element type. */
typedef typename V::value_type value_type;
/** Type of pointers to elements. */
typedef typename V::pointer pointer;
/** Type of references to elements. */
typedef typename V::reference reference;
/** Iterator category. */
typedef std::input_iterator_tag iterator_category;
/** Difference between iterators */
typedef typename V::difference_type difference_type;
/** Size type */
typedef typename V::size_type size_type;
/** Iterator type */
typedef typename V::iterator iterator;
/** Key type */
typedef typename V::key_type key_type;
Container(){}
iterator begin(){
return v_.begin();
}
iterator end(){
return v_.end();
}
reference front(){
return *begin();
}
reference back(){
if (empty())
return *(back());
else
return *(begin()+(size()-1));
}
value_type pop(){
value_type a = front();
v_.erase(begin());
return a;
}
value_type push(const value_type& a){
return v_.insert(a);
}
void clear(){
v_.clear();
}
size_type size(){
return v_.size();
}
void erase(iterator it){
v_.erase(it);
}
void erase(key_type& k){
v_.erase(k);
}
reference operator[](key_type& k){
return *(v_.find(k));
}
reference operator[](size_type k){
return *(begin() + k);
}
bool empty(){
return v_.size()==0;
}
V& operator=(const V& v){
clear();
v_.insert(v.begin(),v.end());
return v_;
}
private:
V v_;
};