Go to the documentation of this file.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
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef ITERATOR_DWA122600_HPP_
00051 # define ITERATOR_DWA122600_HPP_
00052
00053 # include <boost/config.hpp>
00054 # include <iterator>
00055
00056
00057
00058
00059
00060
00061
00062
00063 # if defined(__SGI_STL_PORT)
00064
00065 # if (__SGI_STL_PORT <= 0x410) && !defined(__STL_CLASS_PARTIAL_SPECIALIZATION) && defined(__STL_DEBUG)
00066 # define BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
00067 # endif
00068
00069 # define BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
00070
00071 # endif // STLPort <= 4.1b4 && no partial specialization
00072
00073 # if !defined(BOOST_NO_STD_ITERATOR_TRAITS) \
00074 && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
00075 && !defined(BOOST_MSVC_STD_ITERATOR)
00076
00077 namespace boost { namespace detail {
00078
00079
00080 template <class Iterator>
00081 struct iterator_traits
00082 : std::iterator_traits<Iterator>
00083 {};
00084 using std::distance;
00085
00086 }}
00087
00088 # else
00089
00090 # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
00091 && !defined(BOOST_MSVC_STD_ITERATOR)
00092
00093
00094
00095 namespace boost { namespace detail {
00096
00097
00098
00099
00100 template <class Iterator>
00101 struct iterator_traits
00102 {
00103 typedef typename Iterator::value_type value_type;
00104 typedef typename Iterator::reference reference;
00105 typedef typename Iterator::pointer pointer;
00106 typedef typename Iterator::difference_type difference_type;
00107 typedef typename Iterator::iterator_category iterator_category;
00108 };
00109
00110 template <class T>
00111 struct iterator_traits<T*>
00112 {
00113 typedef T value_type;
00114 typedef T& reference;
00115 typedef T* pointer;
00116 typedef std::ptrdiff_t difference_type;
00117 typedef std::random_access_iterator_tag iterator_category;
00118 };
00119
00120 template <class T>
00121 struct iterator_traits<T const*>
00122 {
00123 typedef T value_type;
00124 typedef T const& reference;
00125 typedef T const* pointer;
00126 typedef std::ptrdiff_t difference_type;
00127 typedef std::random_access_iterator_tag iterator_category;
00128 };
00129
00130 }}
00131
00132 # else
00133
00134 # include <boost/type_traits/remove_const.hpp>
00135 # include <boost/type_traits/detail/yes_no_type.hpp>
00136 # include <boost/type_traits/is_pointer.hpp>
00137
00138 # ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
00139 # include <boost/type_traits/is_same.hpp>
00140 # include <boost/type_traits/remove_pointer.hpp>
00141 # endif
00142 # ifdef BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
00143 # include <boost/type_traits/is_base_and_derived.hpp>
00144 # endif
00145
00146 # include <boost/mpl/if.hpp>
00147 # include <boost/mpl/has_xxx.hpp>
00148 # include <cstddef>
00149
00150
00151 # include "boost/type_traits/detail/bool_trait_def.hpp"
00152
00153 namespace boost { namespace detail {
00154
00155 BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
00156 BOOST_MPL_HAS_XXX_TRAIT_DEF(reference)
00157 BOOST_MPL_HAS_XXX_TRAIT_DEF(pointer)
00158 BOOST_MPL_HAS_XXX_TRAIT_DEF(difference_type)
00159 BOOST_MPL_HAS_XXX_TRAIT_DEF(iterator_category)
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 template <class T>
00173 type_traits::yes_type is_mutable_iterator_helper(T const*, BOOST_DEDUCED_TYPENAME T::value_type*);
00174
00175
00176
00177
00178 template <class T> T* mutable_iterator_lvalue_helper(T& x);
00179 int mutable_iterator_lvalue_helper(...);
00180
00181
00182
00183
00184 template <class T>
00185 type_traits::yes_type is_mutable_iterator_helper(T const*, T const*);
00186
00187 type_traits::no_type is_mutable_iterator_helper(...);
00188
00189 template <class T>
00190 struct is_mutable_iterator_impl
00191 {
00192 static T t;
00193
00194 BOOST_STATIC_CONSTANT(
00195 bool, value = sizeof(
00196 detail::is_mutable_iterator_helper(
00197 (T*)0
00198 , mutable_iterator_lvalue_helper(*t)
00199 ))
00200 == sizeof(type_traits::yes_type)
00201 );
00202 };
00203
00204 BOOST_TT_AUX_BOOL_TRAIT_DEF1(
00205 is_mutable_iterator,T,::boost::detail::is_mutable_iterator_impl<T>::value)
00206
00207
00208
00209
00210
00211
00212
00213 template <class T>
00214 struct is_full_iterator_traits_impl
00215 {
00216 enum { value =
00217 has_value_type<T>::value
00218 & has_reference<T>::value
00219 & has_pointer<T>::value
00220 & has_difference_type<T>::value
00221 & has_iterator_category<T>::value
00222 };
00223 };
00224
00225 BOOST_TT_AUX_BOOL_TRAIT_DEF1(
00226 is_full_iterator_traits,T,::boost::detail::is_full_iterator_traits_impl<T>::value)
00227
00228
00229 # ifdef BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
00230 BOOST_MPL_HAS_XXX_TRAIT_DEF(_Iterator_category)
00231
00232
00233
00234
00235
00236
00237 template <class T>
00238 struct is_stlport_40_debug_iterator_impl
00239 {
00240 enum { value =
00241 has_value_type<T>::value
00242 & has_reference<T>::value
00243 & has_pointer<T>::value
00244 & has_difference_type<T>::value
00245 & has__Iterator_category<T>::value
00246 };
00247 };
00248
00249 BOOST_TT_AUX_BOOL_TRAIT_DEF1(
00250 is_stlport_40_debug_iterator,T,::boost::detail::is_stlport_40_debug_iterator_impl<T>::value)
00251
00252 template <class T>
00253 struct stlport_40_debug_iterator_traits
00254 {
00255 typedef typename T::value_type value_type;
00256 typedef typename T::reference reference;
00257 typedef typename T::pointer pointer;
00258 typedef typename T::difference_type difference_type;
00259 typedef typename T::_Iterator_category iterator_category;
00260 };
00261 # endif // BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
00262
00263 template <class T> struct pointer_iterator_traits;
00264
00265 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
00266 template <class T>
00267 struct pointer_iterator_traits<T*>
00268 {
00269 typedef typename remove_const<T>::type value_type;
00270 typedef T* pointer;
00271 typedef T& reference;
00272 typedef std::random_access_iterator_tag iterator_category;
00273 typedef std::ptrdiff_t difference_type;
00274 };
00275 # else
00276
00277
00278
00279
00280
00281
00282 template<class P> class please_invoke_BOOST_TT_BROKEN_COMPILER_SPEC_on_cv_unqualified_pointee;
00283
00284 template<class P>
00285 struct pointer_value_type
00286 : mpl::if_<
00287 is_same<P, typename remove_pointer<P>::type>
00288 , please_invoke_BOOST_TT_BROKEN_COMPILER_SPEC_on_cv_unqualified_pointee<P>
00289 , typename remove_const<
00290 typename remove_pointer<P>::type
00291 >::type
00292 >
00293 {
00294 };
00295
00296
00297 template<class P>
00298 struct pointer_reference
00299 : mpl::if_<
00300 is_same<P, typename remove_pointer<P>::type>
00301 , please_invoke_BOOST_TT_BROKEN_COMPILER_SPEC_on_cv_unqualified_pointee<P>
00302 , typename remove_pointer<P>::type&
00303 >
00304 {
00305 };
00306
00307 template <class T>
00308 struct pointer_iterator_traits
00309 {
00310 typedef T pointer;
00311 typedef std::random_access_iterator_tag iterator_category;
00312 typedef std::ptrdiff_t difference_type;
00313
00314 typedef typename pointer_value_type<T>::type value_type;
00315 typedef typename pointer_reference<T>::type reference;
00316 };
00317
00318 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
00319
00320
00321
00322 template <class Iterator>
00323 struct standard_iterator_traits
00324 {
00325 typedef typename Iterator::difference_type difference_type;
00326 typedef typename Iterator::value_type value_type;
00327 typedef typename Iterator::pointer pointer;
00328 typedef typename Iterator::reference reference;
00329 typedef typename Iterator::iterator_category iterator_category;
00330 };
00331
00332 template <class Iterator>
00333 struct msvc_stdlib_mutable_traits
00334 : std::iterator_traits<Iterator>
00335 {
00336 typedef typename std::iterator_traits<Iterator>::distance_type difference_type;
00337 typedef typename std::iterator_traits<Iterator>::value_type* pointer;
00338 typedef typename std::iterator_traits<Iterator>::value_type& reference;
00339 };
00340
00341 template <class Iterator>
00342 struct msvc_stdlib_const_traits
00343 : std::iterator_traits<Iterator>
00344 {
00345 typedef typename std::iterator_traits<Iterator>::distance_type difference_type;
00346 typedef const typename std::iterator_traits<Iterator>::value_type* pointer;
00347 typedef const typename std::iterator_traits<Iterator>::value_type& reference;
00348 };
00349
00350 # ifdef BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
00351 template <class Iterator>
00352 struct is_bad_output_iterator
00353 : is_base_and_derived<
00354 std::iterator<std::output_iterator_tag,void,void,void,void>
00355 , Iterator>
00356 {
00357 };
00358
00359 struct bad_output_iterator_traits
00360 {
00361 typedef void value_type;
00362 typedef void difference_type;
00363 typedef std::output_iterator_tag iterator_category;
00364 typedef void pointer;
00365 typedef void reference;
00366 };
00367 # endif
00368
00369
00370
00371 template <class Iterator>
00372 struct msvc_stdlib_iterator_traits
00373 : mpl::if_<
00374 is_mutable_iterator<Iterator>
00375 , msvc_stdlib_mutable_traits<Iterator>
00376 , msvc_stdlib_const_traits<Iterator>
00377 >::type
00378 {};
00379
00380 template <class Iterator>
00381 struct non_pointer_iterator_traits
00382 : mpl::if_<
00383
00384 is_full_iterator_traits<Iterator>
00385
00386 , standard_iterator_traits<Iterator>
00387 # ifdef BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
00388
00389 , mpl::if_<
00390 is_stlport_40_debug_iterator<Iterator>
00391 , stlport_40_debug_iterator_traits<Iterator>
00392 # endif
00393
00394 , msvc_stdlib_iterator_traits<Iterator>
00395 # ifdef BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
00396 >::type
00397 # endif
00398 >::type
00399 {
00400 };
00401
00402 template <class Iterator>
00403 struct iterator_traits_aux
00404 : mpl::if_<
00405 is_pointer<Iterator>
00406 , pointer_iterator_traits<Iterator>
00407 , non_pointer_iterator_traits<Iterator>
00408 >::type
00409 {
00410 };
00411
00412 template <class Iterator>
00413 struct iterator_traits
00414 {
00415
00416
00417 private:
00418 # ifdef BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
00419 typedef
00420 typename mpl::if_<
00421 is_bad_output_iterator<Iterator>
00422 , bad_output_iterator_traits
00423 , iterator_traits_aux<Iterator>
00424 >::type base;
00425 # else
00426 typedef iterator_traits_aux<Iterator> base;
00427 # endif
00428 public:
00429 typedef typename base::value_type value_type;
00430 typedef typename base::pointer pointer;
00431 typedef typename base::reference reference;
00432 typedef typename base::difference_type difference_type;
00433 typedef typename base::iterator_category iterator_category;
00434 };
00435
00436
00437 template <> struct iterator_traits<int>
00438 {
00439 typedef int value_type;
00440 typedef int pointer;
00441 typedef int reference;
00442 typedef int difference_type;
00443 typedef int iterator_category;
00444 };
00445
00446 }}
00447
00448 # endif // workarounds
00449
00450 namespace boost { namespace detail {
00451
00452 namespace iterator_traits_
00453 {
00454 template <class Iterator, class Difference>
00455 struct distance_select
00456 {
00457 static Difference execute(Iterator i1, const Iterator i2, ...)
00458 {
00459 Difference result = 0;
00460 while (i1 != i2)
00461 {
00462 ++i1;
00463 ++result;
00464 }
00465 return result;
00466 }
00467
00468 static Difference execute(Iterator i1, const Iterator i2, std::random_access_iterator_tag*)
00469 {
00470 return i2 - i1;
00471 }
00472 };
00473 }
00474
00475 template <class Iterator>
00476 inline typename iterator_traits<Iterator>::difference_type
00477 distance(Iterator first, Iterator last)
00478 {
00479 typedef typename iterator_traits<Iterator>::difference_type diff_t;
00480 typedef typename ::boost::detail::iterator_traits<Iterator>::iterator_category iterator_category;
00481
00482 return iterator_traits_::distance_select<Iterator,diff_t>::execute(
00483 first, last, (iterator_category*)0);
00484 }
00485
00486 }}
00487
00488 # endif
00489
00490
00491 # undef BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF
00492 # undef BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION
00493
00494 #endif // ITERATOR_DWA122600_HPP_