00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00049 #ifndef STLSOFT_INCL_STLSOFT_ITERATORS_HPP_ASSOCIATIVE_SELECT_ITERATOR
00050 #define STLSOFT_INCL_STLSOFT_ITERATORS_HPP_ASSOCIATIVE_SELECT_ITERATOR
00051
00052 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00053 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_ASSOCIATIVE_SELECT_ITERATOR_MAJOR 2
00054 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_ASSOCIATIVE_SELECT_ITERATOR_MINOR 1
00055 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_ASSOCIATIVE_SELECT_ITERATOR_REVISION 1
00056 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_ASSOCIATIVE_SELECT_ITERATOR_EDIT 26
00057 #endif
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00074 # include <stlsoft/stlsoft.h>
00075 #endif
00076 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
00077 # include <stlsoft/util/std/iterator_helper.hpp>
00078 #endif
00079
00080
00081
00082
00083
00084 #ifndef _STLSOFT_NO_NAMESPACE
00085 namespace stlsoft
00086 {
00087 #endif
00088
00089
00090
00091
00092
00097
00098 template <class P>
00099 struct select_first
00100 {
00101 public:
00102 typedef ss_typename_type_k P::first_type value_type;
00103 typedef value_type& reference;
00104 typedef value_type const& const_reference;
00105
00106 public:
00107 reference operator ()(P const& p)
00108 {
00109 return p.first;
00110 }
00111 const_reference operator ()(P const& p) const
00112 {
00113 return p.first;
00114 }
00115 };
00116
00121
00122 template <class P>
00123 struct select_second
00124 {
00125 public:
00126 typedef ss_typename_type_k P::second_type value_type;
00127 typedef value_type& reference;
00128 typedef value_type const& const_reference;
00129
00130 public:
00131 reference operator ()(P const& p)
00132 {
00133 return p.second;
00134 }
00135 const_reference operator ()(P const& p) const
00136 {
00137 return p.second;
00138 }
00139 };
00140
00141 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00142
00143 template <class P>
00144 struct select_second_const
00145 {
00146 public:
00147 typedef const ss_typename_type_k P::second_type value_type;
00148 typedef value_type& reference;
00149 typedef value_type& const_reference;
00150
00151 public:
00152 const_reference operator ()(P const& p) const
00153 {
00154 return p.second;
00155 }
00156 };
00157
00158 #endif
00159
00165 template< ss_typename_param_k I
00166 , ss_typename_param_k F
00167 >
00168 class associative_select_iterator
00169 {
00170 public:
00171 typedef I adapted_iterator_type;
00172 typedef F selecting_function_type;
00173 typedef ss_typename_type_k I::iterator_category iterator_category;
00174 typedef ss_typename_type_k F::value_type value_type;
00175 typedef ss_typename_type_k I::distance_type distance_type;
00176 typedef associative_select_iterator<I, F> class_type;
00177
00178 typedef value_type& reference;
00179 typedef value_type const& const_reference;
00180 typedef value_type* pointer;
00181 typedef value_type const* const_pointer;
00182
00183 public:
00184 ss_explicit_k associative_select_iterator( adapted_iterator_type i
00185 , selecting_function_type f = selecting_function_type())
00186 : m_i(i)
00187 , m_f(f)
00188 {}
00189
00190 public:
00191 ss_bool_t equal(class_type const& rhs) const
00192 {
00193 return m_i == rhs.m_i;
00194 }
00195
00196 public:
00197 class_type& operator ++()
00198 {
00199 ++m_i;
00200
00201 return *this;
00202 }
00203 class_type operator ++(int)
00204 {
00205 class_type ret(*this);
00206
00207 operator ++();
00208
00209 return ret;
00210 }
00211
00212 reference operator *()
00213 {
00214 return m_f(*m_i);
00215 }
00216
00217 private:
00218 adapted_iterator_type m_i;
00219 selecting_function_type m_f;
00220 };
00221
00222
00223
00224
00225
00226 template< ss_typename_param_k I
00227 , ss_typename_param_k F
00228 >
00229 inline associative_select_iterator<I, F> associative_select(I i, F f)
00230 {
00231 return associative_select_iterator<I, F>(i, f);
00232 }
00233
00234 #if 0
00235 template< ss_typename_param_k I
00236 >
00237 inline associative_select_iterator<I, select_first<I> > associative_select_first(I i)
00238 {
00239 return associative_select_iterator<I, select_first<I> >(i, select_first<I>());
00240 }
00241
00242 template< ss_typename_param_k I
00243 , ss_typename_param_k F
00244 >
00245 inline associative_select_iterator<I, F> associative_select_second(I i, F f)
00246 {
00247 return associative_select_iterator<I, F>(i, f);
00248 }
00249 #endif
00250
00251
00252
00253
00254
00255 template< ss_typename_param_k I
00256 , ss_typename_param_k F
00257 >
00258 inline ss_bool_t operator ==(associative_select_iterator<I, F> const& lhs, associative_select_iterator<I, F> const& rhs)
00259 {
00260 return lhs.equal(rhs);
00261 }
00262
00263 template< ss_typename_param_k I
00264 , ss_typename_param_k F
00265 >
00266 inline ss_bool_t operator !=(associative_select_iterator<I, F> const& lhs, associative_select_iterator<I, F> const& rhs)
00267 {
00268 return !lhs.equal(rhs);
00269 }
00270
00271
00272
00273 #ifndef _STLSOFT_NO_NAMESPACE
00274 }
00275 #endif
00276
00277
00278
00279 #endif
00280
00281