Ticket #5697: iterator_facade.hpp.patch

File iterator_facade.hpp.patch, 4.4 KB (added by Jeffrey Hellrung <jeffrey.hellrung@…>, 11 years ago)
  • D:/boost_1_47_0/boost/iterator/iterator_facade.

    old new  
    1414#include <boost/iterator/detail/facade_iterator_category.hpp>
    1515#include <boost/iterator/detail/enable_if.hpp>
    1616
    17 #include <boost/implicit_cast.hpp>
    1817#include <boost/static_assert.hpp>
     18#include <boost/utility/addressof.hpp>
    1919
    2020#include <boost/type_traits/is_same.hpp>
    2121#include <boost/type_traits/add_const.hpp>
     
    294294
    295295    // operator->() needs special support for input iterators to strictly meet the
    296296    // standard's requirements. If *i is not a reference type, we must still
    297     // produce a lvalue to which a pointer can be formed. We do that by
    298     // returning an instantiation of this special proxy class template.
    299     template <class T>
    300     struct operator_arrow_proxy
     297    // produce a lvalue to which a pointer can be formed.  We do that by
     298    // returning a proxy object containing an instance of the reference object.
     299    template <class Reference, class Pointer>
     300    struct operator_arrow_dispatch // proxy references
    301301    {
    302         operator_arrow_proxy(T const* px) : m_value(*px) {}
    303         T* operator->() const { return &m_value; }
    304         // This function is needed for MWCW and BCC, which won't call operator->
    305         // again automatically per 13.3.1.2 para 8
    306         operator T*() const { return &m_value; }
    307         mutable T m_value;
     302        struct proxy
     303        {
     304            explicit proxy(Reference const & x) : m_ref(x) {}
     305            Reference* operator->() { return boost::addressof(m_ref); }
     306            // This function is needed for MWCW and BCC, which won't call
     307            // operator-> again automatically per 13.3.1.2 para 8
     308            operator Reference*() { return boost::addressof(m_ref); }
     309            Reference m_ref;
     310        };
     311        typedef proxy result_type;
     312        static result_type apply(Reference const & x)
     313        {
     314            return result_type(x);
     315        }
    308316    };
    309317
    310     // A metafunction that gets the result type for operator->.  Also
    311     // has a static function make() which builds the result from a
    312     // Reference
    313     template <class ValueType, class Reference, class Pointer>
    314     struct operator_arrow_result
     318    template <class T, class Pointer>
     319    struct operator_arrow_dispatch<T&, Pointer> // "real" references
    315320    {
    316         // CWPro8.3 won't accept "operator_arrow_result::type", and we
    317         // need that type below, so metafunction forwarding would be a
    318         // losing proposition here.
    319         typedef typename mpl::if_<
    320             is_reference<Reference>
    321           , Pointer
    322           , operator_arrow_proxy<ValueType>
    323         >::type type;
    324 
    325         static type make(Reference x)
     321        typedef Pointer result_type;
     322        static result_type apply(T& x)
    326323        {
    327             return boost::implicit_cast<type>(&x);
     324            return boost::addressof(x);
    328325        }
    329326    };
    330327
    331328# if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
    332329    // Deal with ETI
    333330    template<>
    334     struct operator_arrow_result<int, int, int>
     331    struct operator_arrow_dispatch<int, int>
    335332    {
    336         typedef int type;
     333        typedef int result_type;
    337334    };
    338335# endif
    339336
     
    618615         Value, CategoryOrTraversal, Reference, Difference
    619616      > associated_types;
    620617
    621       typedef boost::detail::operator_arrow_result<
    622         typename associated_types::value_type
    623         , Reference
     618      typedef boost::detail::operator_arrow_dispatch<
     619          Reference
    624620        , typename associated_types::pointer
    625       > pointer_;
     621      > operator_arrow_dispatch_;
    626622
    627623   protected:
    628624      // For use by derived classes
     
    634630      typedef Reference reference;
    635631      typedef Difference difference_type;
    636632
    637       typedef typename pointer_::type pointer;
     633      typedef typename operator_arrow_dispatch_::result_type pointer;
    638634
    639635      typedef typename associated_types::iterator_category iterator_category;
    640636
     
    645641
    646642      pointer operator->() const
    647643      {
    648           return pointer_::make(*this->derived());
     644          return operator_arrow_dispatch_::apply(*this->derived());
    649645      }
    650646       
    651647      typename boost::detail::operator_brackets_result<Derived,Value,reference>::type