Go to the documentation of this file.00001
00002 #ifndef mbl_stl_h_
00003 #define mbl_stl_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <vcl_functional.h>
00019 #include <vcl_vector.h>
00020
00021 #include <vcl_ostream.h>
00022
00023
00024
00025
00026 template<class Out, class T>
00027 inline T mbl_stl_increments(Out first, Out last, T init)
00028 {
00029 for (; first != last; ++first, ++init) *first = init;
00030 return init;
00031 }
00032
00033
00034
00035
00036
00037 template<class Out, class Size, class T>
00038 inline T mbl_stl_increments_n(Out first, Size n, T init)
00039 {
00040 for (; 0 < n; ++first, --n, ++init) *first = init;
00041 return init;
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051 template<class Out, class T, class UnOp>
00052 inline T mbl_stl_sequence(Out first, Out last, UnOp op, T init)
00053 {
00054 for (;first != last; ++first, init = op(init)) *first = init;
00055 return init;
00056 }
00057
00058
00059
00060
00061
00062 template<class Out, class Size, class T, class UnOp>
00063 inline T mbl_stl_sequence_n(Out first, Size n, UnOp op, T init)
00064 {
00065 for (; 0 < n; ++first, --n, init = op(init)) *first = init;
00066 return init;
00067 }
00068
00069
00070
00071 template<class iterType>
00072 inline void mbl_stl_clean(iterType first, iterType last)
00073 {
00074 for (; first != last; ++first)
00075 {
00076 delete *first;
00077 *first=0;
00078 }
00079 }
00080
00081
00082
00083
00084 template<typename InputIterator,
00085 typename OutputIterator,
00086 typename Predicate>
00087 inline OutputIterator mbl_stl_copy_if(InputIterator begin, InputIterator end,
00088 OutputIterator destBegin,
00089 Predicate pred)
00090 {
00091 while (begin != end)
00092 {
00093 if (pred(*begin))
00094 {
00095 *destBegin++ = *begin;
00096 }
00097 ++begin;
00098 }
00099 return destBegin;
00100 }
00101
00102
00103
00104
00105
00106
00107
00108 template <class Pair>
00109 struct mbl_stl_select1st : public vcl_unary_function<Pair, typename Pair::first_type>
00110 {
00111 inline typename Pair::first_type const & operator()(Pair const & pair) const
00112 {
00113 return pair.first;
00114 }
00115 };
00116
00117
00118
00119
00120 template <class Pair>
00121 struct mbl_stl_select2nd : public vcl_unary_function<Pair, typename Pair::second_type>
00122 {
00123 inline typename Pair::second_type const & operator()(Pair const & pair) const
00124 {
00125 return pair.second;
00126 }
00127 };
00128
00129
00130 template <class Pair>
00131 struct mbl_stl_add2nd : public vcl_binary_function<typename Pair::second_type, Pair, typename Pair::second_type>
00132 {
00133 inline typename Pair::second_type operator()(typename Pair::second_type partSum, Pair const & x2 ) const
00134 {
00135 return partSum + x2.second;
00136 }
00137 };
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 template <class T>
00153 class mbl_stl_index_functor
00154 {
00155
00156
00157
00158 private:
00159
00160 const vcl_vector<T >& vec_;
00161
00162 public:
00163 mbl_stl_index_functor(const vcl_vector<T >& vec): vec_(vec) {}
00164 inline const T& operator()(unsigned index) const { return vec_[index]; }
00165 };
00166
00167
00168
00169
00170 template <class Cont>
00171 class mbl_stl_output_t1
00172 {
00173 public:
00174 const Cont &c;
00175 const char *sep;
00176 mbl_stl_output_t1(const Cont& c, const char * sep): c(c), sep(sep) {}
00177 };
00178
00179
00180 template <class Cont> inline
00181 vcl_ostream& operator<<(vcl_ostream& s, const mbl_stl_output_t1<Cont>& t)
00182 {
00183 if (t.c.empty()) return s;
00184 VCL_DISAPPEARING_TYPENAME Cont::const_iterator it=t.c.begin(), end=t.c.end();
00185 s << *it;
00186 ++it;
00187 for (; it!=end; ++it)
00188 s << t.sep << *it;
00189 return s;
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199 template <class Cont> inline
00200 mbl_stl_output_t1<Cont> mbl_stl_output(const Cont &c, const char * sep=" ")
00201 {
00202 return mbl_stl_output_t1<Cont>(c, sep);
00203 }
00204
00205 #endif // mbl_stl_h_