33 #ifndef INCLUDE_OLA_STL_STLUTILS_H_
34 #define INCLUDE_OLA_STL_STLUTILS_H_
79 typename T::iterator iter = sequence->begin();
80 for (; iter != sequence->end(); ++iter)
111 typename T::iterator iter = container->begin();
112 for (; iter != container->end(); ++iter)
125 template<
typename T1,
typename T2>
127 return container.find(value) != container.end();
136 template<
typename T1>
137 void STLKeys(
const T1 &container, vector<typename T1::key_type> *keys) {
138 keys->reserve(keys->size() + container.size());
139 typename T1::const_iterator iter = container.begin();
140 for (; iter != container.end(); ++iter)
141 keys->push_back(iter->first);
151 template<
typename T1,
typename T2>
152 void STLValues(
const T1 &container, vector<T2> *values) {
153 values->reserve(values->size() + container.size());
154 typename T1::const_iterator iter = container.begin();
155 for (; iter != container.end(); ++iter)
156 values->push_back(iter->second);
166 template<
typename T1>
167 typename T1::mapped_type*
STLFind(T1 *container,
168 const typename T1::key_type &key) {
169 typename T1::iterator iter = container->find(key);
170 if (iter == container->end()) {
173 return &iter->second;
187 template<
typename T1>
189 const typename T1::key_type &key) {
190 typename T1::const_iterator iter = container.find(key);
191 if (iter == container.end()) {
214 template<
typename T1>
215 bool STLReplace(T1 *container,
const typename T1::key_type &key,
216 const typename T1::mapped_type &value) {
217 std::pair<typename T1::iterator, bool> p = container->insert(
218 typename T1::value_type(key, value));
220 p.first->second = value;
240 template<
typename T1>
242 const typename T1::key_type &key,
243 const typename T1::mapped_type &value) {
244 std::pair<typename T1::iterator, bool> p = container->insert(
245 typename T1::value_type(key, value));
247 typename T1::mapped_type old_value = p.first->second;
248 p.first->second = value;
264 template<
typename T1>
266 const typename T1::mapped_type &value) {
267 std::pair<typename T1::iterator, bool> p = container->insert(
268 typename T1::value_type(key, value));
270 delete p.first->second;
271 p.first->second = value;
286 template<
typename T1>
288 const typename T1::value_type &key_value) {
289 return container->insert(key_value).second;
303 template<
typename T1>
305 const typename T1::mapped_type &value) {
306 return container->insert(
typename T1::value_type(key, value)).second;
320 template<
typename T1>
322 const typename T1::mapped_type &value) {
323 assert(container->insert(
typename T1::value_type(key, value)).second);
334 template<
typename T1>
335 bool STLRemove(T1 *container,
const typename T1::key_type &key) {
336 return container->erase(key);
351 template<
typename T1>
353 const typename T1::key_type &key,
354 typename T1::mapped_type *value) {
355 typename T1::iterator iter = container->find(key);
356 if (iter == container->end()) {
359 *value = iter->second;
360 container->erase(iter);
373 template<
typename T1>
375 typename T1::iterator iter = container->find(key);
376 if (iter == container->end()) {
380 container->erase(iter);
395 template<
typename T1>
398 const typename T1::key_type &key) {
399 typename T1::iterator iter = container->find(key);
400 if (iter == container->end()) {
403 typename T1::mapped_type value = iter->second;
404 container->erase(iter);
409 #endif // INCLUDE_OLA_STL_STLUTILS_H_