00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _CJ_CONTAINTER_HELPER_H_
00021 #define _CJ_CONTAINTER_HELPER_H_ 1
00022
00024 namespace jsplib {
00025
00027
00033 template <typename InIter, typename OutIter, typename Pred> OutIter copy_if(InIter begin, InIter end, OutIter outBegin, Pred p ) {
00034 while ( begin != end ) {
00035 if(p(*begin)) *outBegin++ = *begin;
00036 ++begin;
00037 }
00038 return outBegin;
00039 }
00040
00042
00047 template < typename T, typename OutIter, typename Pred > void move_if( std::list <T> & from, OutIter to, Pred p ) {
00048 typename std::list<T>::iterator begin = from.begin();
00049 typename std::list<T>::iterator end = from.end();
00050 while ( begin != end ) {
00051 if(p(*begin)) {
00052 *to++ = *begin;
00053 begin = from.erase(begin);
00054 continue;
00055 }
00056 ++begin;
00057 }
00058 }
00059
00061
00066 template < class InIter, class searchT > inline InIter searchFirstField(const InIter start, const InIter end, const searchT & what) {
00067 InIter i (start);
00068 while ( i != end ) { if(i->first == what) break; ++i; }
00069 return i;
00070 }
00071
00073
00078 template < class InIter, class searchT > inline InIter searchSecondField(const InIter start, const InIter end, const searchT & what) {
00079 InIter i (start);
00080 while ( i != end ) { if(i->second == what) break; ++i; }
00081 return i;
00082 }
00083
00085
00088 template < typename U, typename V > U & first_of (std::pair<U,V> & p) { return p.first; }
00090 template < typename U, typename V > V & second_of (std::pair<U,V> & p) { return p.second; }
00092 template < typename U, typename V > const U & first_of_const (const std::pair<U,V> & p) { return p.first; }
00094 template < typename U, typename V > const V & second_of_const (const std::pair<U,V> & p) { return p.second; }
00095
00096
00097 }
00098
00099 #endif // _CJ_CONTAINTER_HELPER_H_