Ticket #7526: std_pair-specialization.patch

File std_pair-specialization.patch, 3.4 KB (added by Kohei Takahashi <flast@…>, 10 years ago)
  • boost/iterator/zip_iterator.hpp

    From 596d5e132a2dee3badcd7bb68264dc37d280af01 Mon Sep 17 00:00:00 2001
    From: Kohei Takahashi <flast@flast.jp>
    Date: Thu, 18 Oct 2012 20:40:12 +0900
    Subject: [PATCH] Specialization for std::pair
    
    ---
     boost/iterator/zip_iterator.hpp |   58 +++++++++++++++++++++++++++++++++++++--
     1 file changed, 56 insertions(+), 2 deletions(-)
    
    diff --git a/boost/iterator/zip_iterator.hpp b/boost/iterator/zip_iterator.hpp
    index 28785e6..d788e63 100644
    a b  
    1818
    1919#include <boost/iterator/detail/minimum_category.hpp>
    2020
     21#include <utility>
    2122#include <boost/fusion/adapted/boost_tuple.hpp> // for backward compatibility
    2223
    2324#include <boost/type_traits/remove_reference.hpp>
    namespace boost {  
    130131    {
    131132    };
    132133
     134    // Specialization for std::pair
     135    template<typename Iterator1, typename Iterator2>
     136    struct tuple_of_references<std::pair<Iterator1, Iterator2> >
     137    {
     138        typedef std::pair<
     139            typename iterator_reference<Iterator1>::type
     140          , typename iterator_reference<Iterator2>::type
     141        > type;
     142    };
     143
    133144    // Metafunction to obtain the minimal traversal tag in a tuple
    134145    // of iterators.
    135146    //
    namespace boost {  
    148159      >::type type;
    149160    };
    150161
     162    template<typename Iterator1, typename Iterator2>
     163    struct minimum_traversal_category_in_iterator_tuple<std::pair<Iterator1, Iterator2> >
     164    {
     165        typedef typename pure_traversal_tag<
     166            typename iterator_traversal<Iterator1>::type
     167        >::type iterator1_traversal;
     168        typedef typename pure_traversal_tag<
     169            typename iterator_traversal<Iterator2>::type
     170        >::type iterator2_traversal;
     171
     172        typedef typename minimum_category<
     173            iterator1_traversal
     174          , typename minimum_category<
     175                iterator2_traversal
     176              , random_access_traversal_tag
     177            >::type
     178        >::type type;
     179    };
     180
    151181#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) // ETI workaround
    152182      template <>
    153183      struct minimum_traversal_category_in_iterator_tuple<int>
    namespace boost {  
    204234    {
    205235        typedef int type;
    206236    };
     237
     238    template <typename reference>
     239    struct converter
     240    {
     241        template <typename Seq>
     242        static reference call(Seq seq)
     243        {
     244            typedef typename fusion::traits::tag_of<reference>::type tag;
     245            return fusion::convert<tag>(seq);
     246        }
     247    };
     248
     249    template <typename Reference1, typename Reference2>
     250    struct converter<std::pair<Reference1, Reference2> >
     251    {
     252        typedef std::pair<Reference1, Reference2> reference;
     253        template <typename Seq>
     254        static reference call(Seq seq)
     255        {
     256            return reference(
     257                fusion::at_c<0>(seq)
     258              , fusion::at_c<1>(seq));
     259        }
     260    };
    207261  }
    208262
    209263  /////////////////////////////////////////////////////////////////////
    namespace boost {  
    260314    typename super_t::reference dereference() const
    261315    {
    262316        typedef typename super_t::reference reference;
    263         typedef typename fusion::traits::tag_of<reference>::type tag;
    264         return fusion::convert<tag>(fusion::transform(
     317        typedef detail::converter<reference> gen;
     318        return gen::call(fusion::transform(
    265319          get_iterator_tuple(),
    266320          detail::dereference_iterator()));
    267321    }