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_ALGORITHMS_STD_HPP_ALT
00050 #define STLSOFT_INCL_STLSOFT_ALGORITHMS_STD_HPP_ALT
00051 
00052 
00053 #define STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ALGORITHM
00054 
00055 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00056 # define STLSOFT_VER_STLSOFT_ALGORITHMS_STD_HPP_ALT_MAJOR       3
00057 # define STLSOFT_VER_STLSOFT_ALGORITHMS_STD_HPP_ALT_MINOR       4
00058 # define STLSOFT_VER_STLSOFT_ALGORITHMS_STD_HPP_ALT_REVISION    4
00059 # define STLSOFT_VER_STLSOFT_ALGORITHMS_STD_HPP_ALT_EDIT        76
00060 #endif 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00075 # include <stlsoft/stlsoft.h>
00076 #endif 
00077 #if defined(STLSOFT_CF_std_NAMESPACE)
00078 # include <algorithm>
00079 #endif 
00080 #if !defined(STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT)
00081 # ifndef STLSOFT_INCL_STLSOFT_META_HPP_YESNO
00082 #  include <stlsoft/meta/yesno.hpp> 
00083 # endif 
00084 #endif 
00085 
00086 #ifndef STLSOFT_INCL_STLSOFT_INTERNAL_H_SAFESTR
00087 # include <stlsoft/internal/safestr.h>
00088 #endif 
00089 
00090 
00091 
00092 
00093 
00094 #ifndef _STLSOFT_NO_NAMESPACE
00095 namespace stlsoft
00096 {
00097 #endif 
00098 
00099 
00100 
00101 
00102 
00103 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00104 # ifdef STLSOFT_CF_NAMESPACE_SUPPORT
00105 namespace std_alt_algorithms_util_
00106 {
00107 # endif 
00108 
00109 template<ss_typename_param_k I>
00110 void std_advance_impl(  I               &i
00111                     ,   ss_ptrdiff_t    n
00112 # if !defined(STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT)
00113                     ,   no_type
00114 # endif 
00115                     )
00116 {
00117     if(n < 0)
00118     {
00119         for(; 0 != n; --i, ++n)
00120         {}
00121     }
00122     else
00123     {
00124         for(; 0 != n; ++i, --n)
00125         {}
00126     }
00127 }
00128 
00129 template<ss_typename_param_k I>
00130 void std_advance_impl(  I               *&i
00131                     ,   ss_ptrdiff_t    n
00132 # if !defined(STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT)
00133                     ,   yes_type
00134 # endif 
00135                     )
00136 {
00137     i += n;
00138 }
00139 
00140 # if !defined(STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT)
00141 
00142 template<   ss_typename_param_k T1
00143         ,   ss_typename_param_k T2
00144         >
00145 no_type is_ptr_(T1 const&, T2 const*) { return no_type(); }
00146 
00147 template<ss_typename_param_k T>
00148 yes_type is_ptr_(T const*, T const**) { return yes_type(); }
00149 
00150 # endif 
00151 
00152 # ifdef STLSOFT_CF_NAMESPACE_SUPPORT
00153 } 
00154 # endif 
00155 #endif 
00156 
00157 
00158 
00159 
00160 
00165 template<ss_typename_param_k I>
00166 
00167 void std_advance(I &i, ss_ptrdiff_t n)
00168 {
00169 #ifdef STLSOFT_CF_std_NAMESPACE
00170     stlsoft_ns_qual_std(advance)(i, n);
00171 #else 
00172 # ifdef STLSOFT_CF_NAMESPACE_SUPPORT
00173     using std_alt_algorithms_util_::std_advance_impl;
00174 #  if !defined(STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT)
00175     using std_alt_algorithms_util_::is_ptr_;
00176 #  endif 
00177 # endif 
00178 
00179 # if defined(STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT)
00180     std_advance_impl(i, n);
00181 # else 
00182     std_advance_impl(i, n, is_ptr_(i, &i));
00183 # endif 
00184 #endif 
00185 }
00186 
00191 template<   ss_typename_param_k I
00192         ,   ss_typename_param_k O
00193         >
00194 
00195 inline O std_copy(I first, I last, O dest)
00196 {
00197 #if defined(STLSOFT_CF_std_NAMESPACE) && \
00198     !defined(STLSOFT_USING_SAFE_STR_FUNCTIONS)
00199     return stlsoft_ns_qual_std(copy)(first, last, dest);
00200 #else 
00201     for(; first != last; ++first, ++dest)
00202     {
00203         *dest = *first;
00204     }
00205 
00206     return dest;
00207 #endif 
00208 }
00209 
00214 template<   ss_typename_param_k I
00215         ,   ss_typename_param_k UP
00216         >
00217 
00218 inline ss_size_t std_count_if(I first, I last, UP pred)
00219 {
00220 #ifdef STLSOFT_CF_std_NAMESPACE
00221     return stlsoft_ns_qual_std(count_if)(first, last, pred);
00222 #else 
00223     ss_size_t r;
00224 
00225     for (r = 0; first != last; ++first)
00226     {
00227         if(pred(*first))
00228         {
00229             ++r;
00230         }
00231     }
00232 
00233     return r;
00234 #endif 
00235 }
00236 
00241 template<   ss_typename_param_k O
00242         ,   ss_typename_param_k V
00243         >
00244 
00245 inline void std_fill(O first, O last, V const& value)
00246 {
00247 #ifdef STLSOFT_CF_std_NAMESPACE
00248     stlsoft_ns_qual_std(fill)(first, last, value);
00249 #else 
00250     for(; first != last; ++first)
00251     {
00252         *first = value;
00253     }
00254 #endif 
00255 }
00256 
00261 template<   ss_typename_param_k O
00262         ,   ss_typename_param_k V
00263         >
00264 
00265 inline void std_fill_n(O dest, ss_size_t n, V const& value)
00266 {
00267 #if defined(STLSOFT_CF_std_NAMESPACE) && \
00268     !defined(STLSOFT_USING_SAFE_STR_FUNCTIONS)
00269     stlsoft_ns_qual_std(fill_n)(dest, n, value);
00270 #else 
00271     for(; 0 != n; ++dest, --n)
00272     {
00273         *dest = value;
00274     }
00275 #endif 
00276 }
00277 
00282 template<   ss_typename_param_k I
00283         ,   ss_typename_param_k V
00284         >
00285 
00286 inline I std_find(I first, I last, V const& value)
00287 {
00288 #ifdef STLSOFT_CF_std_NAMESPACE
00289     return stlsoft_ns_qual_std(find)(first, last, value);
00290 #else 
00291     for(; first != last; ++first)
00292     {
00293         if(value == *first)
00294         {
00295             break;
00296         }
00297     }
00298 
00299     return first;
00300 #endif 
00301 }
00302 
00307 template<   ss_typename_param_k I
00308         ,   ss_typename_param_k UP
00309         >
00310 
00311 inline I std_find_if(I first, I last, UP pred)
00312 {
00313 #ifdef STLSOFT_CF_std_NAMESPACE
00314     return stlsoft_ns_qual_std(find_if)(first, last, pred);
00315 #else 
00316     for(; first != last; ++first)
00317     {
00318         if(pred(*first))
00319         {
00320             break;
00321         }
00322     }
00323 
00324     return first;
00325 #endif 
00326 }
00327 
00332 template<   ss_typename_param_k I
00333         ,   ss_typename_param_k UF
00334         >
00335 
00336 inline UF std_for_each(I first, I last, UF func)
00337 {
00338 #ifdef STLSOFT_CF_std_NAMESPACE
00339     return stlsoft_ns_qual_std(for_each)(first, last, func);
00340 #else 
00341     for(; first != last; ++first)
00342     {
00343         func(*first);
00344     }
00345 
00346     return func;
00347 #endif 
00348 }
00349 
00354 template<   ss_typename_param_k I
00355         ,   ss_typename_param_k T
00356         >
00357 
00358 inline void std_replace(I first, I last, T const& valFind, T const& valReplace)
00359 {
00360     for(; first != last; ++first)
00361     {
00362         if(valFind == *first)
00363         {
00364             *first = valReplace;
00365         }
00366     }
00367 }
00368 
00369 #ifdef STLSOFT_CF_std_NAMESPACE
00370 
00374 template <ss_typename_param_k RI>
00375 
00376 inline void sort(RI first, RI last)
00377 {
00378     stlsoft_ns_qual_std(sort)(first, last);
00379 }
00380 
00385 template<   ss_typename_param_k RI
00386         ,   ss_typename_param_k BP
00387         >
00388 
00389 inline void std_sort(RI first, RI last, BP pred)
00390 {
00391     stlsoft_ns_qual_std(sort)(first, last, pred);
00392 }
00393 
00394 #else 
00395 
00396 
00397 template <ss_typename_param_k RI>
00398 inline void sort(RI first, RI last);
00399 
00400 
00401 template<   ss_typename_param_k RI
00402         ,   ss_typename_param_k BP
00403         >
00404 inline void std_sort(RI first, RI last, BP pred);
00405 
00406 #endif 
00407 
00412 template<   ss_typename_param_k I
00413         ,   ss_typename_param_k O
00414         ,   ss_typename_param_k UF
00415         >
00416 
00417 inline O std_transform(I first, I last, O dest, UF func)
00418 {
00419 #if defined(STLSOFT_CF_std_NAMESPACE) && \
00420     !defined(STLSOFT_USING_SAFE_STR_FUNCTIONS)
00421     return stlsoft_ns_qual_std(transform)(first, last, dest, func);
00422 #else 
00423     for(; first != last; ++first, ++dest)
00424     {
00425         *dest = func(*first);
00426     }
00427 
00428     return dest;
00429 #endif 
00430 }
00431 
00436 template<   ss_typename_param_k FI
00437         ,   ss_typename_param_k BP
00438         >
00439 
00440 inline FI std_unique(FI first, FI last, BP pred)
00441 {
00442 #ifdef STLSOFT_ENFORCE_ORDERING
00443     stlsoft_assert("range passed to unique() is not strict-weak ordered", is_strict_weak_ordered(first, last, pred));
00444 #endif 
00445 
00446 #ifdef STLSOFT_CF_std_NAMESPACE
00447     return stlsoft_ns_qual_std(unique)(first, last, pred);
00448 #else 
00449     if(first != last)
00450     {
00451 # ifdef _DEBUG
00452         const FI    start   =   first;
00453 # endif 
00454         FI          curr    =   first;  
00455 
00456         for(++first; first != last; ++first)
00457         {
00458             if(pred(*first, *curr))
00459             {
00460                 ; 
00461             }
00462             else
00463             {
00464                 ++curr;
00465                 if(first != curr)
00466                 {
00467                     *curr = *first;
00468                 }
00469             }
00470         }
00471 
00472         first = ++curr;
00473     }
00474 
00475     return first;
00476 #endif 
00477 }
00478 
00483 template <ss_typename_param_k FI>
00484 
00485 inline FI std_unique(FI first, FI last)
00486 {
00487 #ifdef STLSOFT_ENFORCE_ORDERING
00488     stlsoft_assert("range passed to unique() is not strict-weak ordered", is_strict_weak_ordered(first, last));
00489 #endif 
00490 
00491 #ifdef STLSOFT_CF_std_NAMESPACE
00492     return stlsoft_ns_qual_std(unique)(first, last);
00493 #else 
00494     if(first != last)
00495     {
00496 # ifdef _DEBUG
00497         const FI    start   =   first;
00498 # endif 
00499         FI          curr    =   first;  
00500 
00501         for(++first; first != last; ++first)
00502         {
00503             if(*first == *curr)
00504             {
00505                 ; 
00506             }
00507             else
00508             {
00509                 ++curr;
00510                 if(first != curr)
00511                 {
00512                     *curr = *first;
00513                 }
00514             }
00515         }
00516 
00517         first = ++curr;
00518     }
00519 
00520     return first;
00521 #endif 
00522 }
00523 
00528 template<   ss_typename_param_k FI
00529         ,   ss_typename_param_k OI
00530         >
00531 
00532 inline OI std_unique_copy(FI first, FI last, OI dest)
00533 {
00534 #ifdef STLSOFT_ENFORCE_ORDERING
00535     stlsoft_assert("range passed to unique_copy() is not strict-weak ordered", is_strict_weak_ordered(first, last));
00536 #endif 
00537 
00538 #ifdef STLSOFT_CF_std_NAMESPACE
00539     return stlsoft_ns_qual_std(unique_copy)(first, last, dest);
00540 #else 
00541     if(first != last)
00542     {
00543 # ifdef _DEBUG
00544         const FI    start   =   first;
00545 # endif 
00546         FI          curr    =   first;  
00547 
00548         *dest++ = *first++;
00549         for(; first != last; ++first)
00550         {
00551             if(*first == *curr)
00552             {
00553                 ; 
00554             }
00555             else
00556             {
00557                 curr = first;
00558                 *dest++ = *first;
00559             }
00560         }
00561 
00562         first = ++curr;
00563     }
00564 
00565     return dest;
00566 #endif 
00567 }
00568 
00573 template<   ss_typename_param_k FI
00574         ,   ss_typename_param_k OI
00575         ,   ss_typename_param_k BP
00576         >
00577 
00578 inline OI std_unique_copy(FI first, FI last, OI dest, BP pred)
00579 {
00580 #ifdef STLSOFT_ENFORCE_ORDERING
00581     stlsoft_assert("range passed to unique_copy() is not strict-weak ordered", is_strict_weak_ordered(first, last, pred));
00582 #endif 
00583 
00584 #ifdef STLSOFT_CF_std_NAMESPACE
00585     return stlsoft_ns_qual_std(unique_copy)(first, last, dest, pred);
00586 #else 
00587     if(first != last)
00588     {
00589 # ifdef _DEBUG
00590         const FI    start   =   first;
00591 # endif 
00592         FI          curr    =   first;  
00593 
00594         *dest++ = *first++;
00595         for(; first != last; ++first)
00596         {
00597             if(pred(*first, *curr))
00598             {
00599                 ; 
00600             }
00601             else
00602             {
00603                 curr = first;
00604                 *dest++ = *first;
00605             }
00606         }
00607 
00608         first = ++curr;
00609     }
00610 
00611     return dest;
00612 #endif 
00613 }
00614 
00616 
00618 
00620 
00621 
00622 #ifdef STLSOFT_UNITTEST
00623 # include "./unittest/alt_unittest_.h"
00624 #endif 
00625 
00626 
00627 
00628 #ifndef _STLSOFT_NO_NAMESPACE
00629 } 
00630 #endif 
00631 
00632 
00633 
00634 #endif 
00635 
00636