sources/list.h

changeset 88
08ccaf26cffd
parent 87
53c2aecb9704
child 109
e4966d7e615d
equal deleted inserted replaced
87:53c2aecb9704 88:08ccaf26cffd
34 #include <deque> 34 #include <deque>
35 #include <functional> 35 #include <functional>
36 #include <cassert> 36 #include <cassert>
37 #include <vector> 37 #include <vector>
38 #include "range.h" 38 #include "range.h"
39 BEGIN_ZFC_NAMESPACE
39 40
40 // ------------------------------------------------------------------------------------------------- 41 // -------------------------------------------------------------------------------------------------
41 // 42 //
42 template<typename T, typename C> 43 template<typename T, typename C>
43 class Container 44 class Container
44 { 45 {
45 public: 46 public:
46 using Iterator = typename C::iterator; 47 typedef typename C::iterator Iterator;
47 using ConstIterator = typename C::const_iterator; 48 typedef typename C::const_iterator ConstIterator;
48 using ReverseIterator = typename C::reverse_iterator; 49 typedef typename C::reverse_iterator ReverseIterator;
49 using ConstReverseIterator = typename C::const_reverse_iterator; 50 typedef typename C::const_reverse_iterator ConstReverseIterator;
50 using Self = Container<T, C>; 51 typedef Container<T, C> Self;
51 52
52 Container(){} 53 Container(){}
53 54
54 Container (int numvalues) : 55 Container (int numvalues) :
55 m_container (numvalues) {} 56 m_container (numvalues) {}
68 return m_container.begin(); 69 return m_container.begin();
69 } 70 }
70 71
71 ConstIterator begin() const 72 ConstIterator begin() const
72 { 73 {
73 return m_container.cbegin(); 74 return m_container.begin();
74 } 75 }
75 76
76 void clear() 77 void clear()
77 { 78 {
78 m_container.clear(); 79 m_container.clear();
79 } 80 }
80 81
81 bool contains (const T& a) const 82 bool contains (const T& a) const
82 { 83 {
83 return std::find (m_container.cbegin(), m_container.cend(), a) != m_container.end(); 84 return std::find (m_container.begin(), m_container.end(), a) != m_container.end();
84 } 85 }
85 86
86 ConstReverseIterator crbegin() const 87 ConstReverseIterator crbegin() const
87 { 88 {
88 return m_container.crbegin(); 89 return m_container.rbegin();
89 } 90 }
90 91
91 ConstReverseIterator crend() const 92 ConstReverseIterator crend() const
92 { 93 {
93 return m_container.crbegin(); 94 return m_container.rend();
94 } 95 }
95 96
96 const C& container() const 97 const C& container() const
97 { 98 {
98 return m_container; 99 return m_container;
103 return m_container.end(); 104 return m_container.end();
104 } 105 }
105 106
106 ConstIterator end() const 107 ConstIterator end() const
107 { 108 {
108 return m_container.cend(); 109 return m_container.end();
109 } 110 }
110 111
111 Iterator find (const T& needle) 112 Iterator find (const T& needle)
112 { 113 {
113 auto it = std::find (m_container.begin(), m_container.end(), needle); 114 auto it = std::find (m_container.begin(), m_container.end(), needle);
118 return it; 119 return it;
119 } 120 }
120 121
121 ConstIterator find (const T& needle) const 122 ConstIterator find (const T& needle) const
122 { 123 {
123 auto it = std::find (m_container.cbegin(), m_container.cend(), needle); 124 auto it = std::find (m_container.begin(), m_container.end(), needle);
124 125
125 if (it == m_container.cend()) 126 if (it == m_container.end())
126 return end(); 127 return end();
127 128
128 return it; 129 return it;
129 } 130 }
130 131
131 Iterator find (Function<bool (T const&)> func) 132 Iterator find (bool (*func)(T const&))
132 { 133 {
133 for (Iterator it = begin(); it != end(); ++it) 134 for (Iterator it = begin(); it != end(); ++it)
134 { 135 {
135 if (func (*it)) 136 if (func (*it))
136 return it; 137 return it;
137 } 138 }
138 139
139 return end(); 140 return end();
140 } 141 }
141 142
142 ConstIterator find (Function<bool (T const&)> func) const 143 ConstIterator find (bool (*func)(T const&)) const
143 { 144 {
144 for (ConstIterator it = begin(); it != end(); ++it) 145 for (ConstIterator it = begin(); it != end(); ++it)
145 { 146 {
146 if (func (*it)) 147 if (func (*it))
147 return it; 148 return it;
367 operator const T*() const 368 operator const T*() const
368 { 369 {
369 return data(); 370 return data();
370 } 371 }
371 }; 372 };
373
374 END_ZFC_NAMESPACE

mercurial