diff options
author | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
commit | a2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch) | |
tree | ad3d6c4fcc8dd0f403f8105598943616246fe172 /include/stl_util.h |
Initial checkin1.5.6
Diffstat (limited to 'include/stl_util.h')
-rw-r--r-- | include/stl_util.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/include/stl_util.h b/include/stl_util.h new file mode 100644 index 000000000..5ecbe0d9c --- /dev/null +++ b/include/stl_util.h @@ -0,0 +1,65 @@ +/************************************************* +* STL Utility Functions Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_STL_UTIL_H__ +#define BOTAN_STL_UTIL_H__ + +#include <map> + +namespace Botan { + +/************************************************* +* Copy-on-Predicate Algorithm * +*************************************************/ +template <typename InputIterator, typename OutputIterator, typename Predicate> +OutputIterator copy_if(InputIterator current, InputIterator end, + OutputIterator dest, Predicate copy_p) + { + while(current != end) + { + if(copy_p(*current)) + *dest++ = *current; + ++current; + } + return dest; + } + +/************************************************* +* Searching through a std::map * +*************************************************/ +template<typename K, typename V> +inline V search_map(const std::map<K, V>& mapping, + const K& key, + const V& null_result = V()) + { + typename std::map<K, V>::const_iterator i = mapping.find(key); + if(i == mapping.end()) + return null_result; + return i->second; + } + +template<typename K, typename V, typename R> +inline R search_map(const std::map<K, V>& mapping, const K& key, + const R& null_result, const R& found_result) + { + typename std::map<K, V>::const_iterator i = mapping.find(key); + if(i == mapping.end()) + return null_result; + return found_result; + } + +/************************************************* +* Insert a key/value pair into a multimap * +*************************************************/ +template<typename K, typename V> +void multimap_insert(std::multimap<K, V>& multimap, + const K& key, const V& value) + { + multimap.insert(std::make_pair(key, value)); + } + +} + +#endif |