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
00042
00050 #ifndef STLSOFT_INCL_STLSOFT_ITERATORS_HPP_TRANSFORM_ITERATOR
00051 #define STLSOFT_INCL_STLSOFT_ITERATORS_HPP_TRANSFORM_ITERATOR
00052
00053 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00054 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_TRANSFORM_ITERATOR_MAJOR 2
00055 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_TRANSFORM_ITERATOR_MINOR 0
00056 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_TRANSFORM_ITERATOR_REVISION 16
00057 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_TRANSFORM_ITERATOR_EDIT 117
00058 #endif
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00076 # include <stlsoft/stlsoft.h>
00077 #endif
00078
00079 #if defined(STLSOFT_COMPILER_IS_MSVC) && \
00080 _MSC_VER < 1200
00081 # error stlsoft/iterators/transform_iterator.hpp is not compatible with Visual C++ 5.0 or earlier
00082 #endif
00083
00084 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
00085 # include <stlsoft/util/std/iterator_helper.hpp>
00086 #endif
00087
00088 #ifdef STLSOFT_UNITTEST
00089 # include <algorithm>
00090 # include <functional>
00091 # include <string>
00092 # include <vector>
00093 # include <stlsoft/conversion/integer_to_string.hpp>
00094 #endif
00095
00096
00097
00098
00099
00100
00101
00102 #ifdef STLSOFT_ITER_TXFM_ITER_OLD_DW
00103 # undef STLSOFT_ITER_TXFM_ITER_OLD_DW
00104 #endif
00105
00106 #if defined(STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_VC) && \
00107 STLSOFT_CF_STD_LIBRARY_DINKUMWARE_VC_VERSION < STLSOFT_CF_DINKUMWARE_VC_VERSION_7_1
00108 # define STLSOFT_ITER_TXFM_ITER_OLD_DW
00109 #endif
00110
00111
00112
00113
00114
00115 #ifndef _STLSOFT_NO_NAMESPACE
00116 namespace stlsoft
00117 {
00118 #endif
00119
00120
00121
00122
00123
00124 #if 0
00125 struct null_function
00126 {
00127 public:
00128 typedef void* result_type;
00129 };
00130 #endif
00131
00132
00146 template< ss_typename_param_k I
00147 , ss_typename_param_k F
00148 >
00149
00150 class transform_iterator
00151 #if 0
00152 : public stlsoft_ns_qual(iterator_base)<ss_typename_type_k stlsoft_ns_qual_std(iterator_traits)<I>::iterator_category
00153 , ss_typename_type_k transform_function_type::result_type
00154 , ????
00155 , void
00156 , void
00157 >
00158 #endif
00159 {
00162 public:
00164 typedef I iterator_type;
00166 typedef F transform_function_type;
00168 typedef ss_typename_type_k transform_function_type::result_type value_type;
00169 #ifdef STLSOFT_ITER_TXFM_ITER_OLD_DW
00171 typedef stlsoft_ns_qual_std(input_iterator_tag) iterator_category;
00173 typedef void difference_type;
00174 #else
00175 typedef stlsoft_ns_qual_std(iterator_traits)<I> traits_type;
00177 typedef ss_typename_type_k traits_type::iterator_category iterator_category;
00179 typedef ss_typename_type_k traits_type::difference_type difference_type;
00180 #endif
00182 typedef transform_iterator<I, F> class_type;
00187 typedef void pointer;
00192 typedef void reference;
00197 typedef value_type effective_reference;
00202 typedef const value_type effective_const_reference;
00204
00207 public:
00208 transform_iterator(iterator_type it, transform_function_type pr)
00209 : m_it(it)
00210 , m_transformer(pr)
00211 {}
00212 transform_iterator()
00213 : m_it()
00214 , m_transformer()
00215 {}
00216
00218 iterator_type base() const
00219 {
00220 return m_it;
00221 }
00223
00226 public:
00227 #if 0
00228 # if 1
00229 transform_iterator(class_type const& rhs)
00230 : m_it(rhs.m_it)
00231 , m_transformer(rhs.m_transformer)
00232 {}
00233 # endif
00234
00235 template <ss_typename_param_k F2>
00236 transform_iterator(transform_iterator<I, F2> const& rhs)
00237 : m_it(rhs.m_it)
00238 , m_transformer()
00239 {}
00240
00241 # if 0
00242 template <ss_typename_param_k F2>
00243 operator transform_iterator<I, F2>() const
00244 {
00245 return transform_iterator<I, F2>(m_it, F2());
00246 }
00247 # endif
00248 #endif
00250
00253 public:
00254 effective_reference operator *()
00255 {
00256 m_current = m_transformer(*m_it);
00257
00258 return m_current;
00259 }
00260 effective_const_reference operator *() const
00261 {
00262 m_current = m_transformer(*m_it);
00263
00264 return m_current;
00265 }
00267
00270 public:
00271 class_type& operator ++()
00272 {
00273 ++m_it;
00274
00275 return *this;
00276 }
00277 class_type operator ++(int)
00278 {
00279 class_type ret(*this);
00280
00281 operator ++();
00282
00283 return ret;
00284 }
00286
00289 public:
00290 class_type& operator --()
00291 {
00292 ++m_it;
00293
00294 return *this;
00295 }
00296 class_type operator --(int)
00297 {
00298 class_type ret(*this);
00299
00300 operator --();
00301
00302 return ret;
00303 }
00305
00306 #ifndef STLSOFT_ITER_TXFM_ITER_OLD_DW
00309 public:
00310 class_type& operator +=(difference_type d)
00311 {
00312 m_it += d;
00313
00314 return *this;
00315 }
00316 class_type& operator -=(difference_type d)
00317 {
00318 m_it -= d;
00319
00320 return *this;
00321 }
00322
00323
00324 effective_reference operator [](difference_type index)
00325 {
00326 return m_transformer(m_it[index]);
00327 }
00328
00329 effective_const_reference operator [](difference_type index) const
00330 {
00331 return m_transformer(m_it[index]);
00332 }
00334 #endif
00335
00338 public:
00340 ss_bool_t equal(class_type const& rhs) const
00341 {
00342 return m_it == rhs.m_it;
00343 }
00344 #if 0
00345 ss_bool_t equal(iterator_type rhs) const
00346 {
00347 return m_it == rhs;
00348 }
00349 #endif
00351 ss_sint_t compare(class_type const& rhs) const
00352 {
00353 return (m_it < rhs.m_it) ? -1 : (rhs.m_it < m_it) ? +1 : 0;
00354 }
00355 #ifndef STLSOFT_ITER_TXFM_ITER_OLD_DW
00357 difference_type distance(class_type const& rhs) const
00358 {
00359 return m_it - rhs.m_it;
00360 }
00361 #endif
00363
00366 private:
00367 #if 0
00368 public:
00369 #endif
00370 iterator_type m_it;
00371 private:
00372 transform_function_type m_transformer;
00373 value_type m_current;
00375
00378 private:
00379 struct transform_iterator_is_BVT_so_no_member_selection_operators
00380 {};
00381
00382 transform_iterator_is_BVT_so_no_member_selection_operators *operator ->() const;
00384 };
00385
00386
00387
00388
00389
00399 template< ss_typename_param_k I
00400 , ss_typename_param_k F
00401 >
00402 inline transform_iterator<I, F> make_transform_iterator(I it, F fn)
00403 {
00404 return transform_iterator<I, F>(it, fn);
00405 }
00406
00418 template< ss_typename_param_k I
00419 , ss_typename_param_k F
00420 >
00421 inline transform_iterator<I, F> transformer(I it, F fn)
00422 {
00423 return make_transform_iterator(it, fn);
00424 }
00425
00426 #if 0
00427 template< ss_typename_param_k I
00428 >
00429 inline transform_iterator<I, null_function> transformer(I it)
00430 {
00431 return transform_iterator<I, null_function>(it, null_function());
00432 }
00433 #endif
00434
00435 #if 0
00436 template< ss_typename_param_k I
00437 , ss_typename_param_k F
00438 >
00439 inline transform_iterator<I, F> transform(I it, F fn)
00440 {
00441 return transform_iterator<I, F>(it, fn);
00442 }
00443 #endif
00444
00445
00446
00447
00448
00449
00450
00451 template< ss_typename_param_k I
00452 , ss_typename_param_k F
00453 >
00454 inline ss_bool_t operator ==(transform_iterator<I, F> const& lhs, transform_iterator<I, F> const& rhs)
00455 {
00456 return lhs.equal(rhs);
00457 }
00458
00459
00460
00461 template< ss_typename_param_k I
00462 , ss_typename_param_k F
00463 >
00464 inline ss_bool_t operator !=(transform_iterator<I, F> const& lhs, transform_iterator<I, F> const& rhs)
00465 {
00466 return !lhs.equal(rhs);
00467 }
00468
00469 #if 0
00470 template< ss_typename_param_k I
00471 , ss_typename_param_k F
00472 >
00473 inline ss_bool_t operator !=(transform_iterator<I, F> const& lhs, I rhs)
00474 {
00475 return !lhs.equal(rhs);
00476 }
00477 #endif
00478
00479 #ifndef STLSOFT_ITER_TXFM_ITER_OLD_DW
00480
00481
00482 template< ss_typename_param_k I
00483 , ss_typename_param_k F
00484 >
00485 inline transform_iterator<I, F> operator +(transform_iterator<I, F> const& lhs, ss_typename_type_k transform_iterator<I, F>::difference_type rhs)
00486 {
00487 return transform_iterator<I, F>(lhs) += rhs;
00488 }
00489
00490
00491
00492 template< ss_typename_param_k I
00493 , ss_typename_param_k F
00494 >
00495 #if 0
00496 inline transform_iterator<I, F> operator -(transform_iterator<I, F> const& lhs, ss_typename_type_k transform_iterator<I, F>::difference_type rhs)
00497 #else
00498 inline transform_iterator<I, F> operator -(transform_iterator<I, F> const& lhs, ss_ptrdiff_t rhs)
00499 #endif
00500 {
00501 return transform_iterator<I, F>(lhs) -= rhs;
00502 }
00503
00504 template< ss_typename_param_k I
00505 , ss_typename_param_k F
00506 >
00507 inline ss_typename_type_ret_k transform_iterator<I, F>::difference_type operator -(transform_iterator<I, F> const& lhs, transform_iterator<I, F> const& rhs)
00508 {
00509 return lhs.distance(rhs);
00510 }
00511
00512
00513
00514 template< ss_typename_param_k I
00515 , ss_typename_param_k F
00516 >
00517 inline ss_bool_t operator <(transform_iterator<I, F> const& lhs, transform_iterator<I, F> const& rhs)
00518 {
00519 return lhs.compare(rhs) < 0;
00520 }
00521
00522
00523
00524 template< ss_typename_param_k I
00525 , ss_typename_param_k F
00526 >
00527 inline ss_bool_t operator <=(transform_iterator<I, F> const& lhs, transform_iterator<I, F> const& rhs)
00528 {
00529 return lhs.compare(rhs) <= 0;
00530 }
00531
00532
00533
00534 template< ss_typename_param_k I
00535 , ss_typename_param_k F
00536 >
00537 inline ss_bool_t operator >(transform_iterator<I, F> const& lhs, transform_iterator<I, F> const& rhs)
00538 {
00539 return lhs.compare(rhs) > 0;
00540 }
00541
00542
00543
00544 template< ss_typename_param_k I
00545 , ss_typename_param_k F
00546 >
00547 inline ss_bool_t operator >=(transform_iterator<I, F> const& lhs, transform_iterator<I, F> const& rhs)
00548 {
00549 return lhs.compare(rhs) >= 0;
00550 }
00551
00552 #endif
00553
00555
00556
00557 #ifdef STLSOFT_UNITTEST
00558 # include "./unittest/transform_iterator_unittest_.h"
00559 #endif
00560
00561
00562
00563 #ifndef _STLSOFT_NO_NAMESPACE
00564 }
00565 #endif
00566
00567
00568
00569 #endif
00570
00571