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()) {
258 template<
typename T1>
259 bool STLReplace(T1 *container,
const typename T1::key_type &key,
260 const typename T1::mapped_type &value) {
261 std::pair<typename T1::iterator, bool> p = container->insert(
262 typename T1::value_type(key, value));
264 p.first->second = value;
284 template<
typename T1>
286 const typename T1::key_type &key,
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 typename T1::mapped_type old_value = p.first->second;
292 p.first->second = value;
308 template<
typename T1>
310 const typename T1::mapped_type &value) {
311 std::pair<typename T1::iterator, bool> p = container->insert(
312 typename T1::value_type(key, value));
314 delete p.first->second;
315 p.first->second = value;
330 template<
typename T1>
332 const typename T1::value_type &key_value) {
333 return container->insert(key_value).second;
347 template<
typename T1>
349 const typename T1::mapped_type &value) {
350 return container->insert(
typename T1::value_type(key, value)).second;
364 template<
typename T1>
366 const typename T1::mapped_type &value) {
367 assert(container->insert(
typename T1::value_type(key, value)).second);
378 template<
typename T1>
379 bool STLRemove(T1 *container,
const typename T1::key_type &key) {
380 return container->erase(key);
395 template<
typename T1>
397 const typename T1::key_type &key,
398 typename T1::mapped_type *value) {
399 typename T1::iterator iter = container->find(key);
400 if (iter == container->end()) {
403 *value = iter->second;
404 container->erase(iter);
419 template<
typename T1>
421 const typename T1::key_type &key) {
422 std::pair<typename T1::iterator, bool> p = container->insert(
423 typename T1::value_type(key, NULL));
435 template<
typename T1>
437 typename T1::iterator iter = container->find(key);
438 if (iter == container->end()) {
442 container->erase(iter);
457 template<
typename T1>
460 const typename T1::key_type &key) {
461 typename T1::iterator iter = container->find(key);
462 if (iter == container->end()) {
465 typename T1::mapped_type value = iter->second;
466 container->erase(iter);
482 template<
typename T1,
typename T2>
484 typename T1::mapped_type value) {
485 typename T2::const_iterator iter = input.begin();
486 for (; iter != input.end(); ++iter) {
487 std::pair<typename T1::iterator, bool> p = output->insert(
488 typename T1::value_type(*iter, value));
490 p.first->second = value;
495 #endif // INCLUDE_OLA_STL_STLUTILS_H_