33 #ifndef INCLUDE_OLA_STL_STLUTILS_H_
34 #define INCLUDE_OLA_STL_STLUTILS_H_
75 typename T::iterator iter = sequence->begin();
76 for (; iter != sequence->end(); ++iter)
107 typename T::iterator iter = container->begin();
108 for (; iter != container->end(); ++iter)
121 template<
typename T1,
typename T2>
123 return container.find(value) != container.end();
132 template<
typename T1>
133 void STLKeys(
const T1 &container, std::vector<typename T1::key_type> *keys) {
134 keys->reserve(keys->size() + container.size());
135 typename T1::const_iterator iter = container.begin();
136 for (; iter != container.end(); ++iter)
137 keys->push_back(iter->first);
147 template<
typename T1,
typename T2>
148 void STLValues(
const T1 &container, std::vector<T2> *values) {
149 values->reserve(values->size() + container.size());
150 typename T1::const_iterator iter = container.begin();
151 for (; iter != container.end(); ++iter)
152 values->push_back(iter->second);
162 template<
typename T1>
163 typename T1::mapped_type*
STLFind(T1 *container,
164 const typename T1::key_type &key) {
165 typename T1::iterator iter = container->find(key);
166 if (iter == container->end()) {
169 return &iter->second;
183 template<
typename T1>
185 const typename T1::key_type &key) {
186 typename T1::const_iterator iter = container.find(key);
187 if (iter == container.end()) {
210 template<
typename T1>
211 bool STLReplace(T1 *container,
const typename T1::key_type &key,
212 const typename T1::mapped_type &value) {
213 std::pair<typename T1::iterator, bool> p = container->insert(
214 typename T1::value_type(key, value));
216 p.first->second = value;
236 template<
typename T1>
238 const typename T1::key_type &key,
239 const typename T1::mapped_type &value) {
240 std::pair<typename T1::iterator, bool> p = container->insert(
241 typename T1::value_type(key, value));
243 typename T1::mapped_type old_value = p.first->second;
244 p.first->second = value;
260 template<
typename T1>
262 const typename T1::mapped_type &value) {
263 std::pair<typename T1::iterator, bool> p = container->insert(
264 typename T1::value_type(key, value));
266 delete p.first->second;
267 p.first->second = value;
282 template<
typename T1>
284 const typename T1::value_type &key_value) {
285 return container->insert(key_value).second;
299 template<
typename T1>
301 const typename T1::mapped_type &value) {
302 return container->insert(
typename T1::value_type(key, value)).second;
316 template<
typename T1>
318 const typename T1::mapped_type &value) {
319 assert(container->insert(
typename T1::value_type(key, value)).second);
330 template<
typename T1>
331 bool STLRemove(T1 *container,
const typename T1::key_type &key) {
332 return container->erase(key);
347 template<
typename T1>
349 const typename T1::key_type &key,
350 typename T1::mapped_type *value) {
351 typename T1::iterator iter = container->find(key);
352 if (iter == container->end()) {
355 *value = iter->second;
356 container->erase(iter);
369 template<
typename T1>
371 typename T1::iterator iter = container->find(key);
372 if (iter == container->end()) {
376 container->erase(iter);
391 template<
typename T1>
394 const typename T1::key_type &key) {
395 typename T1::iterator iter = container->find(key);
396 if (iter == container->end()) {
399 typename T1::mapped_type value = iter->second;
400 container->erase(iter);
405 #endif // INCLUDE_OLA_STL_STLUTILS_H_