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 #ifndef _GLIBCXX_DEBUG_FUNCTIONS_H
00032 #define _GLIBCXX_DEBUG_FUNCTIONS_H 1
00033 
00034 #include <stddef.h>                       
00035 #include <bits/stl_iterator_base_types.h> 
00036 #include <bits/cpp_type_traits.h>         
00037 
00038 namespace __gnu_debug
00039 {
00040   template<typename _Iterator, typename _Sequence>
00041     class _Safe_iterator;
00042 
00043   
00044   inline bool
00045   __check_singular_aux(const void*) { return false; }
00046 
00047   
00048   
00049   template<typename _Iterator>
00050     inline bool
00051     __check_singular(_Iterator& __x)
00052     { return __gnu_debug::__check_singular_aux(&__x); }
00053 
00055   template<typename _Tp>
00056     inline bool
00057     __check_singular(const _Tp* __ptr)
00058     { return __ptr == 0; }
00059 
00061   template<typename _Iterator, typename _Sequence>
00062     inline bool
00063     __check_singular(const _Safe_iterator<_Iterator, _Sequence>& __x)
00064     { return __x._M_singular(); }
00065 
00068   template<typename _Iterator>
00069     inline bool
00070     __check_dereferenceable(_Iterator&)
00071     { return true; }
00072 
00074   template<typename _Tp>
00075     inline bool
00076     __check_dereferenceable(const _Tp* __ptr)
00077     { return __ptr; }
00078 
00080   template<typename _Iterator, typename _Sequence>
00081     inline bool
00082     __check_dereferenceable(const _Safe_iterator<_Iterator, _Sequence>& __x)
00083     { return __x._M_dereferenceable(); }
00084 
00088   template<typename _RandomAccessIterator>
00089     inline bool
00090     __valid_range_aux2(const _RandomAccessIterator& __first,
00091                const _RandomAccessIterator& __last,
00092                std::random_access_iterator_tag)
00093     { return __last - __first >= 0; }
00094 
00099   template<typename _InputIterator>
00100     inline bool
00101     __valid_range_aux2(const _InputIterator&, const _InputIterator&,
00102                std::input_iterator_tag)
00103     { return true; }
00104 
00109   template<typename _Integral>
00110     inline bool
00111     __valid_range_aux(const _Integral&, const _Integral&, __true_type)
00112     { return true; }
00113 
00117   template<typename _InputIterator>
00118     inline bool
00119     __valid_range_aux(const _InputIterator& __first,
00120               const _InputIterator& __last, __false_type)
00121   {
00122     typedef typename std::iterator_traits<_InputIterator>::iterator_category
00123       _Category;
00124     return __gnu_debug::__valid_range_aux2(__first, __last, _Category());
00125   }
00126 
00132   template<typename _InputIterator>
00133     inline bool
00134     __valid_range(const _InputIterator& __first, const _InputIterator& __last)
00135     {
00136       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
00137       return __gnu_debug::__valid_range_aux(__first, __last, _Integral());
00138     }
00139 
00141   template<typename _Iterator, typename _Sequence>
00142     inline bool
00143     __valid_range(const _Safe_iterator<_Iterator, _Sequence>& __first,
00144           const _Safe_iterator<_Iterator, _Sequence>& __last)
00145     { return __first._M_valid_range(__last); }
00146 
00147   
00148 
00149 
00150 
00151   template<typename _InputIterator>
00152     inline _InputIterator
00153     __check_valid_range(const _InputIterator& __first,
00154             const _InputIterator& __last
00155             __attribute__((__unused__)))
00156     {
00157       _GLIBCXX_DEBUG_ASSERT(__gnu_debug::__valid_range(__first, __last));
00158       return __first;
00159     }
00160 
00162   template<typename _CharT, typename _Integer>
00163     inline const _CharT*
00164     __check_string(const _CharT* __s,
00165            const _Integer& __n __attribute__((__unused__)))
00166     {
00167 #ifdef _GLIBCXX_DEBUG_PEDANTIC
00168       _GLIBCXX_DEBUG_ASSERT(__s != 0 || __n == 0);
00169 #endif
00170       return __s;
00171     }
00172 
00174   template<typename _CharT>
00175     inline const _CharT*
00176     __check_string(const _CharT* __s)
00177     {
00178 #ifdef _GLIBCXX_DEBUG_PEDANTIC
00179       _GLIBCXX_DEBUG_ASSERT(__s != 0);
00180 #endif
00181       return __s;
00182     }
00183 
00184   
00185   
00186   template<typename _InputIterator>
00187     inline bool
00188     __check_sorted_aux(const _InputIterator&, const _InputIterator&,
00189                        std::input_iterator_tag)
00190     { return true; }
00191 
00192   
00193   
00194   template<typename _ForwardIterator>
00195     inline bool
00196     __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
00197                        std::forward_iterator_tag)
00198     {
00199       if (__first == __last)
00200         return true;
00201 
00202       _ForwardIterator __next = __first;
00203       for (++__next; __next != __last; __first = __next, ++__next) {
00204         if (*__next < *__first)
00205           return false;
00206       }
00207 
00208       return true;
00209     }
00210 
00211   
00212   
00213   template<typename _InputIterator, typename _Predicate>
00214     inline bool
00215     __check_sorted_aux(const _InputIterator&, const _InputIterator&,
00216                        _Predicate, std::input_iterator_tag)
00217     { return true; }
00218 
00219   
00220   
00221   template<typename _ForwardIterator, typename _Predicate>
00222     inline bool
00223     __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
00224                        _Predicate __pred, std::forward_iterator_tag)
00225     {
00226       if (__first == __last)
00227         return true;
00228 
00229       _ForwardIterator __next = __first;
00230       for (++__next; __next != __last; __first = __next, ++__next) {
00231         if (__pred(*__next, *__first))
00232           return false;
00233       }
00234 
00235       return true;
00236     }
00237 
00238   
00239   template<typename _InputIterator>
00240     inline bool
00241     __check_sorted(const _InputIterator& __first, const _InputIterator& __last)
00242     {
00243       typedef typename std::iterator_traits<_InputIterator>::iterator_category
00244         _Category;
00245       return __gnu_debug::__check_sorted_aux(__first, __last, _Category());
00246     }
00247 
00248   template<typename _InputIterator, typename _Predicate>
00249     inline bool
00250     __check_sorted(const _InputIterator& __first, const _InputIterator& __last,
00251                    _Predicate __pred)
00252     {
00253       typedef typename std::iterator_traits<_InputIterator>::iterator_category
00254         _Category;
00255       return __gnu_debug::__check_sorted_aux(__first, __last, __pred,
00256                          _Category());
00257     }
00258 
00259   
00260   
00261   
00262   template<typename _ForwardIterator, typename _Tp>
00263     inline bool
00264     __check_partitioned(_ForwardIterator __first, _ForwardIterator __last,
00265             const _Tp& __value)
00266     {
00267       while (__first != __last && *__first < __value)
00268     ++__first;
00269       while (__first != __last && !(*__first < __value))
00270     ++__first;
00271       return __first == __last;
00272     }
00273 
00274   
00275   template<typename _ForwardIterator, typename _Tp, typename _Pred>
00276     inline bool
00277     __check_partitioned(_ForwardIterator __first, _ForwardIterator __last,
00278             const _Tp& __value, _Pred __pred)
00279     {
00280       while (__first != __last && __pred(*__first, __value))
00281     ++__first;
00282       while (__first != __last && !__pred(*__first, __value))
00283     ++__first;
00284       return __first == __last;
00285     }
00286 } 
00287 
00288 #endif