Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:37

0001 /////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2007-2013
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 //    (See accompanying file LICENSE_1_0.txt or copy at
0007 //          http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // See http://www.boost.org/libs/intrusive for documentation.
0010 //
0011 /////////////////////////////////////////////////////////////////////////////
0012 
0013 #ifndef BOOST_INTRUSIVE_DETAIL_TRANSFORM_ITERATOR_HPP
0014 #define BOOST_INTRUSIVE_DETAIL_TRANSFORM_ITERATOR_HPP
0015 
0016 #ifndef BOOST_CONFIG_HPP
0017 #  include <boost/config.hpp>
0018 #endif
0019 
0020 #if defined(BOOST_HAS_PRAGMA_ONCE)
0021 #  pragma once
0022 #endif
0023 
0024 #include <boost/intrusive/detail/config_begin.hpp>
0025 #include <boost/intrusive/detail/workaround.hpp>
0026 #include <boost/intrusive/detail/mpl.hpp>
0027 #include <boost/intrusive/detail/iterator.hpp>
0028 
0029 namespace boost {
0030 namespace intrusive {
0031 namespace detail {
0032 
0033 template <class PseudoReference>
0034 struct operator_arrow_proxy
0035 {
0036    BOOST_INTRUSIVE_FORCEINLINE operator_arrow_proxy(const PseudoReference &px)
0037       :  m_value(px)
0038    {}
0039 
0040    BOOST_INTRUSIVE_FORCEINLINE PseudoReference* operator->() const { return &m_value; }
0041    // This function is needed for MWCW and BCC, which won't call operator->
0042    // again automatically per 13.3.1.2 para 8
0043 //   operator T*() const { return &m_value; }
0044    mutable PseudoReference m_value;
0045 };
0046 
0047 template <class T>
0048 struct operator_arrow_proxy<T&>
0049 {
0050    BOOST_INTRUSIVE_FORCEINLINE operator_arrow_proxy(T &px)
0051       :  m_value(px)
0052    {}
0053 
0054    BOOST_INTRUSIVE_FORCEINLINE T* operator->() const { return &m_value; }
0055    // This function is needed for MWCW and BCC, which won't call operator->
0056    // again automatically per 13.3.1.2 para 8
0057 //   operator T*() const { return &m_value; }
0058    T &m_value;
0059 };
0060 
0061 template <class Iterator, class UnaryFunction>
0062 class transform_iterator
0063 {
0064    public:
0065    typedef typename Iterator::iterator_category                                           iterator_category;
0066    typedef typename detail::remove_reference<typename UnaryFunction::result_type>::type   value_type;
0067    typedef typename Iterator::difference_type                                             difference_type;
0068    typedef operator_arrow_proxy<typename UnaryFunction::result_type>                      pointer;
0069    typedef typename UnaryFunction::result_type                                            reference;
0070    
0071    explicit transform_iterator(const Iterator &it, const UnaryFunction &f = UnaryFunction())
0072       :  members_(it, f)
0073    {}
0074 
0075    explicit transform_iterator()
0076       :  members_()
0077    {}
0078 
0079    BOOST_INTRUSIVE_FORCEINLINE Iterator get_it() const
0080    {  return members_.m_it;   }
0081 
0082    //Constructors
0083    BOOST_INTRUSIVE_FORCEINLINE transform_iterator& operator++()
0084    { increment();   return *this;   }
0085 
0086    BOOST_INTRUSIVE_FORCEINLINE transform_iterator operator++(int)
0087    {
0088       transform_iterator result (*this);
0089       increment();
0090       return result;
0091    }
0092 
0093    BOOST_INTRUSIVE_FORCEINLINE friend bool operator== (const transform_iterator& i, const transform_iterator& i2)
0094    { return i.equal(i2); }
0095 
0096    BOOST_INTRUSIVE_FORCEINLINE friend bool operator!= (const transform_iterator& i, const transform_iterator& i2)
0097    { return !(i == i2); }
0098 
0099    BOOST_INTRUSIVE_FORCEINLINE friend typename Iterator::difference_type operator- (const transform_iterator& i, const transform_iterator& i2)
0100    { return i2.distance_to(i); }
0101 
0102    //Arithmetic
0103    transform_iterator& operator+=(typename Iterator::difference_type off)
0104    {  this->advance(off); return *this;   }
0105 
0106    BOOST_INTRUSIVE_FORCEINLINE transform_iterator operator+(typename Iterator::difference_type off) const
0107    {
0108       transform_iterator other(*this);
0109       other.advance(off);
0110       return other;
0111    }
0112 
0113    BOOST_INTRUSIVE_FORCEINLINE friend transform_iterator operator+(typename Iterator::difference_type off, const transform_iterator& right)
0114    {  return right + off; }
0115 
0116    BOOST_INTRUSIVE_FORCEINLINE transform_iterator& operator-=(typename Iterator::difference_type off)
0117    {  this->advance(-off); return *this;   }
0118 
0119    BOOST_INTRUSIVE_FORCEINLINE transform_iterator operator-(typename Iterator::difference_type off) const
0120    {  return *this + (-off);  }
0121 
0122    BOOST_INTRUSIVE_FORCEINLINE typename UnaryFunction::result_type operator*() const
0123    { return dereference(); }
0124 
0125    BOOST_INTRUSIVE_FORCEINLINE operator_arrow_proxy<typename UnaryFunction::result_type>
0126       operator->() const
0127    { return operator_arrow_proxy<typename UnaryFunction::result_type>(dereference());  }
0128 
0129    private:
0130    struct members
0131       :  UnaryFunction
0132    {
0133       BOOST_INTRUSIVE_FORCEINLINE members(const Iterator &it, const UnaryFunction &f)
0134          :  UnaryFunction(f), m_it(it)
0135       {}
0136 
0137       BOOST_INTRUSIVE_FORCEINLINE members()
0138       {}
0139 
0140       Iterator m_it;
0141    } members_;
0142 
0143 
0144    BOOST_INTRUSIVE_FORCEINLINE void increment()
0145    { ++members_.m_it; }
0146 
0147    BOOST_INTRUSIVE_FORCEINLINE void decrement()
0148    { --members_.m_it; }
0149 
0150    BOOST_INTRUSIVE_FORCEINLINE bool equal(const transform_iterator &other) const
0151    {  return members_.m_it == other.members_.m_it;   }
0152 
0153    BOOST_INTRUSIVE_FORCEINLINE bool less(const transform_iterator &other) const
0154    {  return other.members_.m_it < members_.m_it;   }
0155 
0156    typename UnaryFunction::result_type dereference() const
0157    { return members_(*members_.m_it); }
0158 
0159    void advance(typename Iterator::difference_type n)
0160    {  boost::intrusive::iterator_advance(members_.m_it, n); }
0161 
0162    typename Iterator::difference_type distance_to(const transform_iterator &other)const
0163    {  return boost::intrusive::iterator_distance(other.members_.m_it, members_.m_it); }
0164 };
0165 
0166 } //namespace detail
0167 } //namespace intrusive
0168 } //namespace boost
0169 
0170 #include <boost/intrusive/detail/config_end.hpp>
0171 
0172 #endif //BOOST_INTRUSIVE_DETAIL_TRANSFORM_ITERATOR_HPP