17 #ifndef __BUSBOY_ARRAY_UTIL_H__
18 #define __BUSBOY_ARRAY_UTIL_H__
31 template<
typename T>
void copyArray(
const T* src, T* dest,
size_t size) {
32 std::copy(src, src+size, dest);
40 template<
typename T> T*
copyArray(
const T* src,
size_t size) {
41 T* dest =
new T[size];
42 copyArray<T>(src,dest,size);
49 template<
typename T>
bool compareArray(
const T* arr1,
const T* arr2,
size_t size) {
50 return std::equal(arr1, arr1+size, arr2);
68 const std::vector<T*> vector1,
69 const std::vector<T*> vector2
71 if ( vector1.size()!=vector2.size() )
return false;
72 return std::equal(vector1.begin(), vector1.end(), vector2.begin(), &comparePointers<T>);
80 for (
typename std::vector<V*>::iterator iter = vector.begin(); iter!=vector.end(); iter++ ) {
88 template<
typename K,
typename V>
90 const std::pair<K,V*>& pair1,
91 const std::pair<K,V*>& pair2
95 if ( pair1.first!=pair2.first ) {
99 return *pair1.second==*pair2.second;
106 template<
typename K,
typename V>
108 const std::map<K,V*> map1,
109 const std::map<K,V*> map2
111 if ( map1.size()!=map2.size() )
return false;
112 return std::equal(map1.begin(), map1.end(), map2.begin(), &comparePointerPairs<K,V>);
118 template<
typename K,
typename V>
120 for (
typename std::map<K,V*>::iterator iter = map.begin(); iter!=map.end(); iter++ ) {
130 template<
typename K,
typename V>
131 std::set<K>
keySet(
const std::map<K,V>& map) {
133 typename std::map<K,V>::const_iterator iter=map.begin();
134 for ( ; iter!=map.end(); iter++ ) {
135 result.insert(iter->first);
143 template<
typename K,
typename V>
144 void mapAddAll(std::map<K,V>* map1,
const std::map<K,V>& map2) {
145 typename std::map<K,V>::const_iterator iter=map2.begin();
146 for ( ; iter!=map2.end(); iter++ ) {
147 (*map1)[iter->first] = iter->second;
155 std::string
vectorToString(
const std::vector<T>& vec,
const std::string& delim) {
163 std::string
setToString(
const std::set<T>&
set,
const std::string& delim) {
170 template<
typename InputIterator>
171 std::string
containerToString(
const InputIterator begin,
const InputIterator end,
const std::string& delim) {
175 std::ostringstream ss;
176 InputIterator iter = begin;
177 InputIterator ahead = begin;
179 for ( ; iter!=end; iter++ ) {
194 return std::vector<T>(
set.begin(),
set.end());