segmented_iterator_range.hpp

来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 538 行 · 第 1/2 页

HPP
538
字号
                    multiple_view<size_minus_1, detail::full_view> const                  , single_view<detail::left_view> const                > mask;                typedef transform_view<mask const, segmented_range const, tfx> type;                static type call(Sequence &seq)                {                    return type(                        mask(                            make_multiple_view<size_minus_1>(detail::full_view())                          , make_single_view(detail::left_view())                        )                      , segmented_range(fusion::begin(seq.cons.car.sequence), fusion::next(seq.cons.car.where_))                      , tfx(seq.cons.cdr)                    );                }            };            template<typename Sequence>            struct apply<Sequence, nil>            {                typedef typename Sequence::cons_type::car_type segmented_range;                typedef typename segmented_range::sequence_non_ref_type sequence_type;                typedef typename result_of::begin<sequence_type>::type begin;                typedef typename segmented_range::iterator_type end;                typedef iterator_range<begin, end> range;                typedef single_view<range> type;                static type call(Sequence &seq)                {                    return type(range(fusion::begin(seq.cons.car.sequence), seq.cons.car.where_));                }            };        };        ////////////////////////////////////////////////////////////////////////////        template<>        struct segments_impl<detail::segmented_view_tag<detail::center_view> >        {            template<typename Sequence>            struct apply            {                typedef typename Sequence::right_cons_type right_cons_type;                typedef typename Sequence::left_cons_type left_cons_type;                typedef typename right_cons_type::car_type right_segmented_range;                typedef typename left_cons_type::car_type left_segmented_range;                typedef iterator_range<                    typename result_of::begin<left_segmented_range>::type                  , typename result_of::next<typename result_of::begin<right_segmented_range>::type>::type                > segmented_range;                typedef typename mpl::minus<                    typename result_of::size<segmented_range>::type                  , mpl::int_<2>                >::type size_minus_2;                BOOST_MPL_ASSERT_RELATION(0, <=, size_minus_2::value);                typedef detail::segments_transform<                    typename left_cons_type::cdr_type                  , typename right_cons_type::cdr_type                > tfx;                typedef joint_view<                    multiple_view<size_minus_2, detail::full_view> const                  , single_view<detail::left_view> const                > left_mask;                typedef joint_view<                    single_view<detail::right_view> const                  , left_mask const                > mask;                typedef transform_view<mask const, segmented_range const, tfx> type;                static type call(Sequence &seq)                {                    left_mask lmask(                        make_multiple_view<size_minus_2>(detail::full_view())                      , make_single_view(detail::left_view())                    );                    return type(                        mask(make_single_view(detail::right_view()), lmask)                      , segmented_range(fusion::begin(seq.left_cons.car), fusion::next(fusion::begin(seq.right_cons.car)))                      , tfx(seq.left_cons.cdr, seq.right_cons.cdr)                    );                }            };        };    }    // specialize iterator_range for use with segmented iterators, so that    // it presents a segmented view of the range.    template<typename First, typename Last>    struct iterator_range;    template<typename First, typename Last>    struct iterator_range<segmented_iterator<First>, segmented_iterator<Last> >      : sequence_base<iterator_range<segmented_iterator<First>, segmented_iterator<Last> > >    {        typedef typename convert_iterator<segmented_iterator<First> >::type begin_type;        typedef typename convert_iterator<segmented_iterator<Last> >::type end_type;        typedef typename detail::reverse_cons<First>::type begin_cons_type;        typedef typename detail::reverse_cons<Last>::type end_cons_type;        typedef iterator_range_tag fusion_tag;        typedef fusion_sequence_tag tag; // this gets picked up by MPL        typedef typename traits::category_of<begin_type>::type category;        typedef typename result_of::distance<begin_type, end_type>::type size;        typedef mpl::true_ is_view;        iterator_range(segmented_iterator<First> const& first_, segmented_iterator<Last> const& last_)          : first(convert_iterator<segmented_iterator<First> >::call(first_))          , last(convert_iterator<segmented_iterator<Last> >::call(last_))          , first_cons(detail::reverse_cons<First>::call(first_.cons()))          , last_cons(detail::reverse_cons<Last>::call(last_.cons()))        {}        begin_type first;        end_type last;        begin_cons_type first_cons;        end_cons_type last_cons;    };    namespace detail    {        template<typename Cons1, typename Cons2>        struct same_segment          : mpl::false_        {};        template<typename Car1, typename Cdr1, typename Car2, typename Cdr2>        struct same_segment<cons<Car1, Cdr1>, cons<Car2, Cdr2> >          : mpl::and_<                traits::is_segmented<Car1>              , is_same<Car1, Car2>            >        {};        ////////////////////////////////////////////////////////////////////////////        template<typename Cons1, typename Cons2>        struct segments_gen;        ////////////////////////////////////////////////////////////////////////////        template<typename Cons1, typename Cons2, bool SameSegment>        struct segments_gen2        {            typedef segments_gen<typename Cons1::cdr_type, typename Cons2::cdr_type> gen;            typedef typename gen::type type;            static type call(Cons1 const &cons1, Cons2 const &cons2)            {                return gen::call(cons1.cdr, cons2.cdr);            }        };        template<typename Cons1, typename Cons2>        struct segments_gen2<Cons1, Cons2, false>        {            typedef segmented_view<center_view, Cons1, Cons2> view;            typedef typename result_of::segments<view>::type type;            static type call(Cons1 const &cons1, Cons2 const &cons2)            {                view v(cons1, cons2);                return fusion::segments(v);            }        };        template<typename Car1, typename Car2>        struct segments_gen2<cons<Car1>, cons<Car2>, false>        {            typedef iterator_range<                typename Car1::iterator_type              , typename Car2::iterator_type            > range;            typedef single_view<range> type;            static type call(cons<Car1> const &cons1, cons<Car2> const &cons2)            {                return type(range(cons1.car.where_, cons2.car.where_));            }        };        ////////////////////////////////////////////////////////////////////////////        template<typename Cons1, typename Cons2>        struct segments_gen          : segments_gen2<Cons1, Cons2, same_segment<Cons1, Cons2>::value>        {};        template<typename Car, typename Cdr>        struct segments_gen<cons<Car, Cdr>, nil>        {            typedef segmented_view<right_view, cons<Car, Cdr> > view;            typedef typename result_of::segments<view>::type type;            static type call(cons<Car, Cdr> const &cons, nil const &)            {                view v(cons);                return fusion::segments(v);            }        };        template<>        struct segments_gen<nil, nil>        {            typedef nil type;            static type call(nil const &, nil const &)            {                return nil();            }        };    } // namespace detail    namespace extension    {        template<typename Tag>        struct is_segmented_impl;        // An iterator_range of segmented_iterators is segmented        template<>        struct is_segmented_impl<iterator_range_tag>        {            template<typename Iterator>            struct is_segmented_iterator : mpl::false_ {};            template<typename Cons>            struct is_segmented_iterator<segmented_iterator<Cons> > : mpl::true_ {};            template<typename Sequence>            struct apply              : mpl::and_<                    is_segmented_iterator<typename Sequence::begin_type>                  , is_segmented_iterator<typename Sequence::end_type>                >            {};        };        template<typename Sequence>        struct segments_impl;        template<>        struct segments_impl<iterator_range_tag>        {            template<typename Sequence>            struct apply            {                typedef typename Sequence::begin_cons_type begin_cons;                typedef typename Sequence::end_cons_type end_cons;                typedef detail::segments_gen<begin_cons, end_cons> gen;                typedef typename gen::type type;                static type call(Sequence &sequence)                {                    return gen::call(sequence.first_cons, sequence.last_cons);                }            };        };    }}}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?