monotone

monotone Mtn Source Tree

Root/botan/stl_util.h

1/*************************************************
2* STL Utility Functions Header File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#ifndef BOTAN_STL_UTIL_H__
7#define BOTAN_STL_UTIL_H__
8
9#include <map>
10
11namespace Botan {
12
13/*************************************************
14* Copy-on-Predicate Algorithm *
15*************************************************/
16template<typename InputIterator, typename OutputIterator, typename Predicate>
17OutputIterator copy_if(InputIterator current, InputIterator end,
18 OutputIterator dest, Predicate copy_p)
19 {
20 while(current != end)
21 {
22 if(copy_p(*current))
23 *dest++ = *current;
24 ++current;
25 }
26 return dest;
27 }
28
29/*************************************************
30* Searching through a std::map *
31*************************************************/
32template<typename K, typename V>
33inline V search_map(const std::map<K, V>& mapping,
34 const K& key,
35 const V& null_result = V())
36 {
37 typename std::map<K, V>::const_iterator i = mapping.find(key);
38 if(i == mapping.end())
39 return null_result;
40 return i->second;
41 }
42
43template<typename K, typename V, typename R>
44inline R search_map(const std::map<K, V>& mapping, const K& key,
45 const R& null_result, const R& found_result)
46 {
47 typename std::map<K, V>::const_iterator i = mapping.find(key);
48 if(i == mapping.end())
49 return null_result;
50 return found_result;
51 }
52
53/*************************************************
54* Function adaptor for delete operation *
55*************************************************/
56template<class T>
57class del_fun : public std::unary_function<T, void>
58 {
59 public:
60 void operator()(T* ptr) { delete ptr; }
61 };
62
63/*************************************************
64* Delete the second half of a pair of objects *
65*************************************************/
66template<typename Pair>
67void delete2nd(Pair& pair)
68 {
69 delete pair.second;
70 }
71
72/*************************************************
73* Insert a key/value pair into a multimap *
74*************************************************/
75template<typename K, typename V>
76void multimap_insert(std::multimap<K, V>& multimap,
77 const K& key, const V& value)
78 {
79 multimap.insert(std::make_pair(key, value));
80 }
81
82}
83
84#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status