📄 iterator.hpp
字号:
// (C) Copyright David Abrahams 2002.// Distributed under the Boost Software License, Version 1.0. (See// accompanying file LICENSE_1_0.txt or copy at// http://www.boost.org/LICENSE_1_0.txt)// Boost versions of//// std::iterator_traits<>::iterator_category// std::iterator_traits<>::difference_type// std::distance()//// ...for all compilers and iterators//// Additionally, if X is a pointer// std::iterator_traits<X>::pointer// Otherwise, if partial specialization is supported or X is not a pointer// std::iterator_traits<X>::value_type// std::iterator_traits<X>::pointer// std::iterator_traits<X>::reference//// See http://www.boost.org for most recent version including documentation.// Revision History// 04 Mar 2001 - More attempted fixes for Intel C++ (David Abrahams)// 03 Mar 2001 - Put all implementation into namespace// boost::detail::iterator_traits_. Some progress made on fixes// for Intel compiler. (David Abrahams)// 02 Mar 2001 - Changed BOOST_MSVC to BOOST_MSVC_STD_ITERATOR in a few// places. (Jeremy Siek)// 19 Feb 2001 - Improved workarounds for stock MSVC6; use yes_type and// no_type from type_traits.hpp; stopped trying to remove_cv// before detecting is_pointer, in honor of the new type_traits// semantics. (David Abrahams)// 13 Feb 2001 - Make it work with nearly all standard-conforming iterators// under raw VC6. The one category remaining which will fail is// that of iterators derived from std::iterator but not// boost::iterator and which redefine difference_type.// 11 Feb 2001 - Clean away code which can never be used (David Abrahams)// 09 Feb 2001 - Always have a definition for each traits member, even if it// can't be properly deduced. These will be incomplete types in// some cases (undefined<void>), but it helps suppress MSVC errors// elsewhere (David Abrahams)// 07 Feb 2001 - Support for more of the traits members where possible, making// this useful as a replacement for std::iterator_traits<T> when// used as a default template parameter.// 06 Feb 2001 - Removed useless #includes of standard library headers// (David Abrahams)#ifndef ITERATOR_DWA122600_HPP_# define ITERATOR_DWA122600_HPP_# include <sysc/packages/boost/config.hpp># include <iterator>// STLPort 4.0 and betas have a bug when debugging is enabled and there is no// partial specialization: instead of an iterator_category typedef, the standard// container iterators have _Iterator_category.//// Also, whether debugging is enabled or not, there is a broken specialization// of std::iterator<output_iterator_tag,void,void,void,void> which has no// typedefs but iterator_category.# if defined(__SGI_STL_PORT)# if (__SGI_STL_PORT <= 0x410) && !defined(__STL_CLASS_PARTIAL_SPECIALIZATION) && defined(__STL_DEBUG)# define BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEF# endif# define BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION# endif // STLPort <= 4.1b4 && no partial specialization# if !defined(BOOST_NO_STD_ITERATOR_TRAITS) \ && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ && !defined(BOOST_MSVC_STD_ITERATOR) namespace boost { namespace detail {// Define a new template so it can be specializedtemplate <class Iterator>struct iterator_traits : std::iterator_traits<Iterator>{};using std::distance;}} // namespace boost::detail# else# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ && !defined(BOOST_MSVC_STD_ITERATOR)// This is the case where everything conforms except BOOST_NO_STD_ITERATOR_TRAITSnamespace boost { namespace detail {// Rogue Wave Standard Library fools itself into thinking partial// specialization is missing on some platforms (e.g. Sun), so fails to// supply iterator_traits!template <class Iterator>struct iterator_traits{ typedef typename Iterator::value_type value_type; typedef typename Iterator::reference reference; typedef typename Iterator::pointer pointer; typedef typename Iterator::difference_type difference_type; typedef typename Iterator::iterator_category iterator_category;};template <class T>struct iterator_traits<T*>{ typedef T value_type; typedef T& reference; typedef T* pointer; typedef std::ptrdiff_t difference_type; typedef std::random_access_iterator_tag iterator_category;};template <class T>struct iterator_traits<T const*>{ typedef T value_type; typedef T const& reference; typedef T const* pointer; typedef std::ptrdiff_t difference_type; typedef std::random_access_iterator_tag iterator_category;};}} // namespace boost::detail# else# include <sysc/packages/boost/type_traits/remove_const.hpp># include <sysc/packages/boost/type_traits/detail/yes_no_type.hpp># include <sysc/packages/boost/type_traits/is_pointer.hpp># ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION# include <sysc/packages/boost/type_traits/is_same.hpp># include <sysc/packages/boost/type_traits/remove_pointer.hpp># endif# ifdef BOOST_BAD_OUTPUT_ITERATOR_SPECIALIZATION# include <sysc/packages/boost/type_traits/is_base_and_derived.hpp># endif# include <sysc/packages/boost/mpl/if.hpp># include <sysc/packages/boost/mpl/has_xxx.hpp># include <cstddef>// should be the last #include# include "sysc/packages/boost/type_traits/detail/bool_trait_def.hpp"namespace boost { namespace detail {BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)BOOST_MPL_HAS_XXX_TRAIT_DEF(reference)BOOST_MPL_HAS_XXX_TRAIT_DEF(pointer)BOOST_MPL_HAS_XXX_TRAIT_DEF(difference_type)BOOST_MPL_HAS_XXX_TRAIT_DEF(iterator_category)// is_mutable_iterator --//// A metafunction returning true iff T is a mutable iterator type// with a nested value_type. Will only work portably with iterators// whose operator* returns a reference, but that seems to be OK for// the iterators supplied by Dinkumware. Some input iterators may// compile-time if they arrive here, and if the compiler is strict// about not taking the address of an rvalue.// This one detects ordinary mutable iterators - the result of// operator* is convertible to the value_type.template <class T>type_traits::yes_type is_mutable_iterator_helper(T const*, BOOST_DEDUCED_TYPENAME T::value_type*);// Since you can't take the address of an rvalue, the guts of// is_mutable_iterator_impl will fail if we use &*t directly. This// makes sure we can still work with non-lvalue iterators.template <class T> T* mutable_iterator_lvalue_helper(T& x);int mutable_iterator_lvalue_helper(...);// This one detects output iterators such as ostream_iterator which// return references to themselves.template <class T>type_traits::yes_type is_mutable_iterator_helper(T const*, T const*);type_traits::no_type is_mutable_iterator_helper(...);template <class T>struct is_mutable_iterator_impl{ static T t; BOOST_STATIC_CONSTANT( bool, value = sizeof( detail::is_mutable_iterator_helper( (T*)0 , mutable_iterator_lvalue_helper(*t) // like &*t )) == sizeof(type_traits::yes_type) );};BOOST_TT_AUX_BOOL_TRAIT_DEF1( is_mutable_iterator,T,::boost::detail::is_mutable_iterator_impl<T>::value)// is_full_iterator_traits --//// A metafunction returning true iff T has all the requisite nested// types to satisfy the requirements for a fully-conforming// iterator_traits implementation.template <class T>struct is_full_iterator_traits_impl{ enum { value = has_value_type<T>::value & has_reference<T>::value & has_pointer<T>::value & has_difference_type<T>::value & has_iterator_category<T>::value };};BOOST_TT_AUX_BOOL_TRAIT_DEF1( is_full_iterator_traits,T,::boost::detail::is_full_iterator_traits_impl<T>::value)# ifdef BOOST_BAD_CONTAINER_ITERATOR_CATEGORY_TYPEDEFBOOST_MPL_HAS_XXX_TRAIT_DEF(_Iterator_category) // is_stlport_40_debug_iterator --//// A metafunction returning true iff T has all the requisite nested// types to satisfy the requirements of an STLPort 4.0 debug iterator// iterator_traits implementation.template <class T>struct is_stlport_40_debug_iterator_impl{ enum { value = has_value_type<T>::value & has_reference<T>::value & has_pointer<T>::value & has_difference_type<T>::value & has__Iterator_category<T>::value };};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -