mirror of
				https://github.com/boostorg/iterator.git
				synced 2025-11-04 02:11:37 +01:00 
			
		
		
		
	rigged new iterator_traits for backward compatibility
[SVN r9577]
This commit is contained in:
		@@ -2,21 +2,14 @@
 | 
			
		||||
#define BOOST_ITERATOR_TRAITS_HPP
 | 
			
		||||
 | 
			
		||||
#include <boost/config.hpp>
 | 
			
		||||
#include <boost/type_traits.hpp>
 | 
			
		||||
#include <boost/type_traits/conversion_traits.hpp>
 | 
			
		||||
#include <boost/type_traits/cv_traits.hpp>
 | 
			
		||||
#include <boost/pending/ct_if.hpp>
 | 
			
		||||
#include <boost/detail/iterator.hpp>
 | 
			
		||||
 | 
			
		||||
namespace boost {
 | 
			
		||||
  
 | 
			
		||||
  template <typename 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::return_category return_category;
 | 
			
		||||
    typedef typename Iterator::motion_category motion_category;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  // Motion Categories
 | 
			
		||||
  // Traversal Categories
 | 
			
		||||
  struct single_pass_iterator_tag { };
 | 
			
		||||
  struct forward_iterator_tag : public single_pass_iterator_tag { };
 | 
			
		||||
  struct bidirectional_iterator_tag : public forward_iterator_tag { };
 | 
			
		||||
@@ -28,29 +21,113 @@ namespace boost {
 | 
			
		||||
  struct mutable_lvalue_iterator_tag : virtual public writable_iterator_tag,
 | 
			
		||||
    virtual public readable_iterator_tag { };
 | 
			
		||||
  struct constant_lvalue_iterator_tag : public readable_iterator_tag { };
 | 
			
		||||
  
 | 
			
		||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
 | 
			
		||||
 | 
			
		||||
  struct error_iterator_tag { };
 | 
			
		||||
 | 
			
		||||
  // Inherit from iterator_base if your iterator defines its own
 | 
			
		||||
  // return_category and traversal_category. Otherwise, the "old style"
 | 
			
		||||
  // iterator category will be mapped to the return_category and
 | 
			
		||||
  // traversal_category.
 | 
			
		||||
  struct new_iterator_base { };
 | 
			
		||||
 | 
			
		||||
  namespace detail {
 | 
			
		||||
    template <bool IsConst>
 | 
			
		||||
    struct pointer_return_category {
 | 
			
		||||
      typedef constant_lvalue_iterator_tag type;
 | 
			
		||||
 | 
			
		||||
    struct iter_traits_from_nested_types {
 | 
			
		||||
      template <typename Iterator> struct bind {
 | 
			
		||||
        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::return_category return_category;
 | 
			
		||||
        typedef typename Iterator::traversal_category traversal_category;
 | 
			
		||||
      };
 | 
			
		||||
    };
 | 
			
		||||
    template <>
 | 
			
		||||
    struct pointer_return_category<false> {
 | 
			
		||||
      typedef mutable_lvalue_iterator_tag type;
 | 
			
		||||
 | 
			
		||||
    template <typename ValueType>
 | 
			
		||||
    struct choose_lvalue_return {
 | 
			
		||||
      typedef typename ct_if<is_const<ValueType>::value,
 | 
			
		||||
			     boost::constant_lvalue_iterator_tag,
 | 
			
		||||
			     boost::mutable_lvalue_iterator_tag>::type type;
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    template <typename Category, typename ValueType>
 | 
			
		||||
    struct iter_category_to_return {
 | 
			
		||||
      typedef typename ct_if<
 | 
			
		||||
        is_convertible<Category*, std::forward_iterator_tag*>::value,
 | 
			
		||||
        typename choose_lvalue_return<ValueType>::type,
 | 
			
		||||
        typename ct_if<
 | 
			
		||||
          is_convertible<Category*, std::input_iterator_tag*>::value,
 | 
			
		||||
          boost::readable_iterator_tag,
 | 
			
		||||
          typename ct_if<
 | 
			
		||||
            is_convertible<Category*, std::output_iterator_tag*>::value,
 | 
			
		||||
            boost::writable_iterator_tag,
 | 
			
		||||
            boost::error_iterator_tag
 | 
			
		||||
          >::type
 | 
			
		||||
       >::type
 | 
			
		||||
      >::type type;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    template <typename Category>
 | 
			
		||||
    struct iter_category_to_traversal {
 | 
			
		||||
      typedef typename ct_if<
 | 
			
		||||
        is_convertible<Category*, std::random_access_iterator_tag*>::value,
 | 
			
		||||
        boost::random_access_iterator_tag,
 | 
			
		||||
        typename ct_if<
 | 
			
		||||
          is_convertible<Category*, std::bidirectional_iterator_tag*>::value,
 | 
			
		||||
          boost::bidirectional_iterator_tag,
 | 
			
		||||
          typename ct_if<
 | 
			
		||||
            is_convertible<Category*, std::forward_iterator_tag*>::value,
 | 
			
		||||
            boost::forward_iterator_tag,
 | 
			
		||||
            boost::single_pass_iterator_tag>::type
 | 
			
		||||
          >::type
 | 
			
		||||
        >::type type;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    struct iter_traits_from_old_traits {
 | 
			
		||||
      template <typename Iterator> class bind {
 | 
			
		||||
        typedef boost::detail::iterator_traits<Iterator> OldTraits;
 | 
			
		||||
        typedef typename OldTraits::iterator_category Cat;
 | 
			
		||||
      public:
 | 
			
		||||
        typedef typename OldTraits::value_type value_type;
 | 
			
		||||
        typedef typename OldTraits::reference reference;
 | 
			
		||||
        typedef typename OldTraits::pointer pointer;
 | 
			
		||||
        typedef typename OldTraits::difference_type difference_type;
 | 
			
		||||
        typedef iter_category_to_return<Cat,value_type>::type return_category;
 | 
			
		||||
        typedef iter_category_to_traversal<Cat>::type traversal_category;
 | 
			
		||||
      };      
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    template <typename Iterator>
 | 
			
		||||
    class choose_iter_traits {
 | 
			
		||||
      typedef typename ct_if<is_convertible<Iterator*,
 | 
			
		||||
                                            new_iterator_base*>::value,
 | 
			
		||||
                             iter_traits_from_nested_types,
 | 
			
		||||
                             iter_traits_from_old_traits>::type Choice;
 | 
			
		||||
    public:
 | 
			
		||||
      typedef typename Choice:: template bind<Iterator> type;
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
  } // namespace detail
 | 
			
		||||
  
 | 
			
		||||
  template <typename Iterator>
 | 
			
		||||
  class iterator_traits
 | 
			
		||||
    : public detail::choose_iter_traits<Iterator>::type { };
 | 
			
		||||
 | 
			
		||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
 | 
			
		||||
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  struct iterator_traits<T*> {
 | 
			
		||||
  struct iterator_traits<T*>
 | 
			
		||||
  {
 | 
			
		||||
    typedef T value_type;
 | 
			
		||||
    typedef T& reference;
 | 
			
		||||
    typedef T* pointer;
 | 
			
		||||
    typedef std::ptrdiff_t difference_type;
 | 
			
		||||
    typedef typename detail::pointer_return_category<is_const<T>::value>::type
 | 
			
		||||
    typedef typename ct_if<is_const<T>::value,
 | 
			
		||||
			   boost::constant_lvalue_iterator_tag,
 | 
			
		||||
			   boost::mutable_lvalue_iterator_tag>::type
 | 
			
		||||
      return_category;
 | 
			
		||||
    typedef random_access_iterator_tag motion_category;
 | 
			
		||||
    typedef boost::random_access_iterator_tag traversal_category;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user