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) {
135 typename T::iterator iter = container->begin();
136 for (; iter != container->end(); ++iter) {
151 template<
typename T1,
typename T2>
153 return container.find(value) != container.end();
162 template<
typename T1>
163 void STLKeys(
const T1 &container, std::vector<typename T1::key_type> *keys) {
164 keys->reserve(keys->size() + container.size());
165 typename T1::const_iterator iter = container.begin();
166 for (; iter != container.end(); ++iter)
167 keys->push_back(iter->first);
177 template<
typename T1,
typename T2>
178 void STLValues(
const T1 &container, std::vector<T2> *values) {
179 values->reserve(values->size() + container.size());
180 typename T1::const_iterator iter = container.begin();
181 for (; iter != container.end(); ++iter)
182 values->push_back(iter->second);
192 template<
typename T1>
193 typename T1::mapped_type*
STLFind(T1 *container,
194 const typename T1::key_type &key) {
195 typename T1::iterator iter = container->find(key);
196 if (iter == container->end()) {
199 return &iter->second;
210 template<
typename T1>
211 typename T1::mapped_type
const*
STLFind(
const T1 *container,
212 const typename T1::key_type &key) {
213 typename T1::const_iterator iter = container->find(key);
214 if (iter == container->end()) {
217 return &iter->second;
231 template<
typename T1>
233 const typename T1::key_type &key) {
234 typename T1::const_iterator iter = container.find(key);
235 if (iter == container.end()) {
257 template<
typename T1>
258 bool STLReplace(T1 *container,
const typename T1::key_type &key,
259 const typename T1::mapped_type &value) {
260 std::pair<typename T1::iterator, bool> p = container->insert(
261 typename T1::value_type(key, value));
263 p.first->second = value;
282 template<
typename T1>
284 const typename T1::key_type &key,
285 const typename T1::mapped_type &value) {
286 std::pair<typename T1::iterator, bool> p = container->insert(
287 typename T1::value_type(key, value));
289 typename T1::mapped_type old_value = p.first->second;
290 p.first->second = value;
306 template<
typename T1>
308 const typename T1::mapped_type &value) {
309 std::pair<typename T1::iterator, bool> p = container->insert(
310 typename T1::value_type(key, value));
312 delete p.first->second;
313 p.first->second = value;
328 template<
typename T1>
330 const typename T1::value_type &key_value) {
331 return container->insert(key_value).second;
345 template<
typename T1>
347 const typename T1::mapped_type &value) {
348 return container->insert(
typename T1::value_type(key, value)).second;
361 template<
typename T1>
363 const typename T1::mapped_type &value) {
364 assert(container->insert(
typename T1::value_type(key, value)).second);
375 template<
typename T1>
376 bool STLRemove(T1 *container,
const typename T1::key_type &key) {
377 return container->erase(key);
392 template<
typename T1>
394 const typename T1::key_type &key,
395 typename T1::mapped_type *value) {
396 typename T1::iterator iter = container->find(key);
397 if (iter == container->end()) {
400 *value = iter->second;
401 container->erase(iter);
416 template<
typename T1>
418 const typename T1::key_type &key) {
419 std::pair<typename T1::iterator, bool> p = container->insert(
420 typename T1::value_type(key, NULL));
432 template<
typename T1>
434 typename T1::iterator iter = container->find(key);
435 if (iter == container->end()) {
439 container->erase(iter);
454 template<
typename T1>
457 const typename T1::key_type &key) {
458 typename T1::iterator iter = container->find(key);
459 if (iter == container->end()) {
462 typename T1::mapped_type value = iter->second;
463 container->erase(iter);
479 template<
typename T1,
typename T2>
481 typename T1::mapped_type value) {
482 typename T2::const_iterator iter = input.begin();
483 for (; iter != input.end(); ++iter) {
484 std::pair<typename T1::iterator, bool> p = output->insert(
485 typename T1::value_type(*iter, value));
487 p.first->second = value;
492 #endif // INCLUDE_OLA_STL_STLUTILS_H_