33 #ifndef INCLUDE_OLA_STL_STLUTILS_H_
34 #define INCLUDE_OLA_STL_STLUTILS_H_
57 while (!stack->empty()) {
69 while (!stack->empty()) {
100 typename T::iterator iter = sequence->begin();
101 for (; iter != sequence->end(); ++iter)
132 typename T::iterator iter = container->begin();
133 for (; iter != container->end(); ++iter)
146 template<
typename T1,
typename T2>
148 return container.find(value) != container.end();
157 template<
typename T1>
158 void STLKeys(
const T1 &container, std::vector<typename T1::key_type> *keys) {
159 keys->reserve(keys->size() + container.size());
160 typename T1::const_iterator iter = container.begin();
161 for (; iter != container.end(); ++iter)
162 keys->push_back(iter->first);
172 template<
typename T1,
typename T2>
173 void STLValues(
const T1 &container, std::vector<T2> *values) {
174 values->reserve(values->size() + container.size());
175 typename T1::const_iterator iter = container.begin();
176 for (; iter != container.end(); ++iter)
177 values->push_back(iter->second);
187 template<
typename T1>
188 typename T1::mapped_type*
STLFind(T1 *container,
189 const typename T1::key_type &key) {
190 typename T1::iterator iter = container->find(key);
191 if (iter == container->end()) {
194 return &iter->second;
208 template<
typename T1>
210 const typename T1::key_type &key) {
211 typename T1::const_iterator iter = container.find(key);
212 if (iter == container.end()) {
235 template<
typename T1>
236 bool STLReplace(T1 *container,
const typename T1::key_type &key,
237 const typename T1::mapped_type &value) {
238 std::pair<typename T1::iterator, bool> p = container->insert(
239 typename T1::value_type(key, value));
241 p.first->second = value;
261 template<
typename T1>
263 const typename T1::key_type &key,
264 const typename T1::mapped_type &value) {
265 std::pair<typename T1::iterator, bool> p = container->insert(
266 typename T1::value_type(key, value));
268 typename T1::mapped_type old_value = p.first->second;
269 p.first->second = value;
285 template<
typename T1>
287 const typename T1::mapped_type &value) {
288 std::pair<typename T1::iterator, bool> p = container->insert(
289 typename T1::value_type(key, value));
291 delete p.first->second;
292 p.first->second = value;
307 template<
typename T1>
309 const typename T1::value_type &key_value) {
310 return container->insert(key_value).second;
324 template<
typename T1>
326 const typename T1::mapped_type &value) {
327 return container->insert(
typename T1::value_type(key, value)).second;
341 template<
typename T1>
343 const typename T1::mapped_type &value) {
344 assert(container->insert(
typename T1::value_type(key, value)).second);
355 template<
typename T1>
356 bool STLRemove(T1 *container,
const typename T1::key_type &key) {
357 return container->erase(key);
372 template<
typename T1>
374 const typename T1::key_type &key,
375 typename T1::mapped_type *value) {
376 typename T1::iterator iter = container->find(key);
377 if (iter == container->end()) {
380 *value = iter->second;
381 container->erase(iter);
394 template<
typename T1>
396 typename T1::iterator iter = container->find(key);
397 if (iter == container->end()) {
401 container->erase(iter);
416 template<
typename T1>
419 const typename T1::key_type &key) {
420 typename T1::iterator iter = container->find(key);
421 if (iter == container->end()) {
424 typename T1::mapped_type value = iter->second;
425 container->erase(iter);
430 #endif // INCLUDE_OLA_STL_STLUTILS_H_