progress with integrating the segmented Fusion work

[SVN r73831]
This commit is contained in:
Eric Niebler
2011-08-16 23:07:51 +00:00
parent 2212f57287
commit 2ccb8d604f
23 changed files with 74 additions and 42 deletions

View File

@ -1,100 +0,0 @@
/*=============================================================================
Copyright (c) 2011 Eric Niebler
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_FUSION_SEGMENTED_BEGIN_IMPL_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_BEGIN_IMPL_HPP_INCLUDED
#include <boost/type_traits/remove_const.hpp>
#include <boost/fusion/view/iterator_range.hpp>
#include <boost/fusion/container/list/cons.hpp>
#include <boost/fusion/container/generation/make_cons.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/support/ext_/is_segmented.hpp>
#include <boost/fusion/view/ext_/detail/end_impl.hpp>
#include <boost/fusion/view/ext_/segmented_fold_until.hpp>
namespace boost { namespace fusion { namespace detail
{
struct segmented_begin_fun
{
template<typename Sig>
struct result;
template<typename This, typename Range, typename State, typename Context>
struct result<This(Range&, State&, Context&)>
{
typedef
iterator_range<
typename fusion::result_of::begin<Range>::type,
typename fusion::result_of::end<Range>::type
>
range_type;
typedef
fusion::result<
cons<range_type, typename remove_const<Context>::type>,
fusion::break_
>
type;
};
template<typename Range, typename State, typename Context>
typename result<segmented_begin_fun(Range&, State const&, Context const&)>::type
operator()(Range& rng, State const&, Context const& context) const
{
typedef
iterator_range<
typename fusion::result_of::begin<Range>::type,
typename fusion::result_of::end<Range>::type
>
range_type;
return fusion::make_cons(range_type(fusion::begin(rng), fusion::end(rng)), context);
}
};
template<typename Range, typename Stack, bool IsSegmented = traits::is_segmented<Range>::type::value>
struct segmented_begin_impl
{
typedef
segmented_end_impl<Range, Stack>
end_impl;
typedef
segmented_fold_until_impl<
Range,
result<typename end_impl::type, continue_>,
Stack,
segmented_begin_fun
>
fold_impl;
typedef typename fold_impl::type::value_type type;
static type call(Range& rng, Stack const& stack)
{
return fold_impl::call(rng, end_impl::call(rng, stack), stack, segmented_begin_fun()).value;
}
};
template<typename Range, typename Stack>
struct segmented_begin_impl<Range, Stack, false>
{
typedef typename result_of::begin<Range>::type begin_type;
typedef typename result_of::end<Range>::type end_type;
typedef iterator_range<begin_type, end_type> pair_type;
typedef cons<pair_type, Stack> type;
static type call(Range& rng, Stack stack)
{
return type(pair_type(fusion::begin(rng), fusion::end(rng)), stack);
}
};
}}}
#endif

View File

@ -1,55 +0,0 @@
/*=============================================================================
Copyright (c) 2011 Eric Niebler
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_FUSION_SEGMENTED_END_IMPL_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_END_IMPL_HPP_INCLUDED
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/fusion/view/iterator_range.hpp>
#include <boost/fusion/container/list/cons.hpp>
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/sequence/intrinsic/ext_/segments.hpp>
#include <boost/fusion/support/ext_/is_segmented.hpp>
namespace boost { namespace fusion { namespace detail
{
//auto segmented_end_impl( rng, stack )
//{
// assert(is_segmented(rng));
// auto it = end(segments(rng));
// return cons(iterator_range(it, it), stack);
//}
template<typename Range, typename Stack>
struct segmented_end_impl
{
BOOST_MPL_ASSERT((traits::is_segmented<Range>));
typedef
typename result_of::end<
typename remove_reference<
typename add_const<
typename result_of::segments<Range>::type
>::type
>::type
>::type
end_type;
typedef iterator_range<end_type, end_type> pair_type;
typedef cons<pair_type, Stack> type;
static type call(Range & rng, Stack stack)
{
end_type end = fusion::end(fusion::segments(rng));
return type(pair_type(end, end), stack);
}
};
}}}
#endif

View File

@ -1,247 +0,0 @@
/*=============================================================================
Copyright (c) 2011 Eric Niebler
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_FUSION_SEGMENTED_ITERATOR_NEXT_IMPL_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_ITERATOR_NEXT_IMPL_HPP_INCLUDED
#include <boost/type_traits/add_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/fusion/container/list/cons.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/view/ext_/detail/begin_impl.hpp>
namespace boost { namespace fusion
{
template<typename First, typename Second>
struct iterator_range;
template<typename Context>
struct segmented_iterator;
namespace detail
{
//bool is_invalid(stack)
//{
// return empty(car(stack));
//}
template<typename Stack>
struct is_invalid
: result_of::equal_to<
typename Stack::car_type::begin_type,
typename Stack::car_type::end_type
>
{};
////Advance the first iterator in the range at the
////top of a stack of iterator ranges. Return the
////new stack.
//auto pop_front_car(stack)
//{
// return cons(iterator_range(next(begin(car(stack))), end(car(stack))), cdr(stack));
//}
template<typename Stack>
struct pop_front_car
{
typedef
iterator_range<
typename result_of::next<
typename Stack::car_type::begin_type
>::type
, typename Stack::car_type::end_type
>
car_type;
typedef
cons<car_type, typename Stack::cdr_type>
type;
static type call(Stack const & stack)
{
return type(
car_type(fusion::next(stack.car.first), stack.car.last),
stack.cdr);
}
};
template<
typename Stack,
typename Next = typename pop_front_car<Stack>::type,
bool IsInvalid = is_invalid<Next>::value,
int StackSize = Stack::size::value>
struct segmented_next_impl_recurse;
// Handle the case where the top of the stack has no usable
//auto segmented_next_impl_recurse3(stack)
//{
// if (size(stack) == 1)
// return cons(iterator_range(end(car(stack)), end(car(stack))), nil);
// else
// return segmented_next_impl_recurse(stack.cdr);
//}
template<
typename Stack,
int StackSize = Stack::size::value>
struct segmented_next_impl_recurse3
{
typedef segmented_next_impl_recurse<typename Stack::cdr_type> impl;
typedef typename impl::type type;
static type call(Stack const & stack)
{
return impl::call(stack.cdr);
}
};
template<typename Stack>
struct segmented_next_impl_recurse3<Stack, 1>
{
typedef typename Stack::car_type::end_type end_type;
typedef iterator_range<end_type, end_type> range_type;
typedef cons<range_type> type;
static type call(Stack const & stack)
{
return type(range_type(stack.car.last, stack.car.last));
}
};
//auto segmented_next_impl_recurse2(stack)
//{
// auto res = segmented_begin_impl(front(car(stack)), stack);
// if (is_invalid(res))
// return segmented_next_impl_recurse3(stack);
// else
// return res;
//}
template<
typename Stack,
typename Range =
typename remove_reference<
typename add_const<
typename result_of::deref<
typename Stack::car_type::begin_type
>::type
>::type
>::type,
typename Result =
typename segmented_begin_impl<Range, Stack>::type,
bool IsInvalid =
is_invalid<Result>::value>
struct segmented_next_impl_recurse2
{
typedef segmented_next_impl_recurse3<Stack> impl;
typedef typename impl::type type;
static type call(Stack const & stack)
{
return impl::call(stack);
}
};
template<typename Stack, typename Range, typename Result>
struct segmented_next_impl_recurse2<Stack, Range, Result, false>
{
typedef Result type;
static type call(Stack const & stack)
{
return segmented_begin_impl<Range, Stack>::call(*stack.car.first, stack);
}
};
//auto segmented_next_impl_recurse(stack)
//{
// auto next = pop_front_car(stack);
// if (is_invalid(next))
// if (1 == size(stack))
// return next;
// else
// return segmented_next_impl_recurse(cdr(stack));
// else
// return segmented_next_impl_recurse2(next)
//}
template<typename Stack, typename Next, bool IsInvalid, int StackSize>
struct segmented_next_impl_recurse
{
typedef
typename segmented_next_impl_recurse<typename Stack::cdr_type>::type
type;
static type call(Stack const& stack)
{
return segmented_next_impl_recurse<typename Stack::cdr_type>::call(stack.cdr);
}
};
template<typename Stack, typename Next>
struct segmented_next_impl_recurse<Stack, Next, true, 1>
{
typedef Next type;
static type call(Stack const & stack)
{
return pop_front_car<Stack>::call(stack);
}
};
template<typename Stack, typename Next, int StackSize>
struct segmented_next_impl_recurse<Stack, Next, false, StackSize>
{
typedef segmented_next_impl_recurse2<Next> impl;
typedef typename impl::type type;
static type call(Stack const & stack)
{
return impl::call(pop_front_car<Stack>::call(stack));
}
};
//auto segmented_next_impl(stack)
//{
// // car(stack) is a range of values, not a range of segments
// auto next = pop_front_car(stack);
// if (is_invalid(next))
// return segmented_next_impl_recurse(cdr(next));
// else
// return next;
//}
template<
typename Stack,
typename Next = typename pop_front_car<Stack>::type,
bool IsInvalid = is_invalid<Next>::value>
struct segmented_next_impl
{
typedef segmented_next_impl_recurse<typename Stack::cdr_type> impl;
typedef typename impl::type type;
static type call(Stack const & stack)
{
return impl::call(stack.cdr);
}
};
template<typename Stack, typename Next>
struct segmented_next_impl<Stack, Next, false>
{
typedef Next type;
static type call(Stack const & stack)
{
return pop_front_car<Stack>::call(stack);
}
};
}
}}
#endif

View File

@ -1,43 +0,0 @@
/*=============================================================================
Copyright (c) 2011 Eric Niebler
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_FUSION_REVERSE_CONS_HPP_INCLUDED)
#define BOOST_FUSION_REVERSE_CONS_HPP_INCLUDED
#include <boost/fusion/container/list/cons.hpp>
#include <boost/fusion/container/generation/make_cons.hpp>
namespace boost { namespace fusion { namespace detail
{
////////////////////////////////////////////////////////////////////////////
template<typename Cons, typename State = nil>
struct reverse_cons;
template<typename Car, typename Cdr, typename State>
struct reverse_cons<cons<Car, Cdr>, State>
{
typedef reverse_cons<Cdr, cons<Car, State> > impl;
typedef typename impl::type type;
static type call(cons<Car, Cdr> const &cons, State const &state = State())
{
return impl::call(cons.cdr, fusion::make_cons(cons.car, state));
}
};
template<typename State>
struct reverse_cons<nil, State>
{
typedef State type;
static State const &call(nil const &, State const &state = State())
{
return state;
}
};
}}}
#endif

View File

@ -1,112 +0,0 @@
/*=============================================================================
Copyright (c) 2011 Eric Niebler
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_FUSION_SEGMENTED_SEQUENCE_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_SEQUENCE_HPP_INCLUDED
#include <boost/mpl/bool.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/fusion/support/tag_of.hpp>
#include <boost/fusion/sequence/intrinsic/ext_/segments.hpp>
#include <boost/fusion/sequence/intrinsic/ext_/segmented_size.hpp>
namespace boost { namespace fusion
{
namespace detail
{
struct segment_sequence_tag {};
// Here, Sequence is a sequence of ranges (which may or may not be
// segmented).
template<typename Sequence>
struct segment_sequence
: sequence_base<segment_sequence<Sequence> >
{
typedef fusion_sequence_tag tag;
typedef segment_sequence_tag fusion_tag;
typedef typename Sequence::is_view is_view;
typedef typename Sequence::category category;
typedef Sequence sequence_type;
sequence_type sequence;
explicit segment_sequence(Sequence const & seq)
: sequence(seq)
{}
};
}
namespace extension
{
template<typename Tag>
struct is_segmented_impl;
template<>
struct is_segmented_impl<detail::segment_sequence_tag>
{
template<typename Sequence>
struct apply
: mpl::true_
{};
};
template<typename Tag>
struct segments_impl;
template<>
struct segments_impl<detail::segment_sequence_tag>
{
template<typename Sequence>
struct apply
{
typedef typename Sequence::sequence_type type;
static type call(Sequence & seq)
{
return seq.sequence;
}
};
};
template<typename Tag>
struct begin_impl;
template<>
struct begin_impl<detail::segment_sequence_tag>
{
template<typename Sequence>
struct apply
: segmented_begin<Sequence>
{};
};
template<typename Tag>
struct end_impl;
template<>
struct end_impl<detail::segment_sequence_tag>
{
template<typename Sequence>
struct apply
: segmented_end<Sequence>
{};
};
template<typename Tag>
struct size_impl;
template<>
struct size_impl<detail::segment_sequence_tag>
{
template<typename Sequence>
struct apply
: segmented_size<Sequence>::type
{};
};
}
}}
#endif

View File

@ -1,40 +0,0 @@
/*=============================================================================
Copyright (c) 2011 Eric Niebler
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_FUSION_SEGMENTED_BEGIN_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_BEGIN_HPP_INCLUDED
#include <boost/fusion/view/ext_/detail/begin_impl.hpp>
namespace boost { namespace fusion
{
template<typename Context>
struct segmented_iterator;
//auto segmented_begin( rng )
//{
// return make_segmented_iterator( segmented_begin_impl( rng, nil ) );
//}
template<typename Range>
struct segmented_begin
{
typedef
segmented_iterator<
typename detail::segmented_begin_impl<Range, fusion::nil>::type
>
type;
static type call(Range & rng)
{
return type(
detail::segmented_begin_impl<Range, fusion::nil>::call(rng, fusion::nil()));
}
};
}}
#endif

View File

@ -1,41 +0,0 @@
/*=============================================================================
Copyright (c) 2011 Eric Niebler
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_FUSION_SEGMENTED_END_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_END_HPP_INCLUDED
#include <boost/fusion/container/list/cons.hpp>
#include <boost/fusion/view/ext_/detail/end_impl.hpp>
namespace boost { namespace fusion
{
template<typename Context>
struct segmented_iterator;
//auto segmented_end( rng )
//{
// return make_segmented_iterator( segmented_end_impl( rng ) );
//}
template<typename Range>
struct segmented_end
{
typedef
segmented_iterator<
typename detail::segmented_end_impl<Range, fusion::nil>::type
>
type;
static type call(Range & rng)
{
return type(
detail::segmented_end_impl<Range, fusion::nil>::call(rng, fusion::nil()));
}
};
}}
#endif

View File

@ -1,443 +0,0 @@
/*=============================================================================
Copyright (c) 2011 Eric Niebler
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_FUSION_SEGMENTED_FOLD_UNTIL_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_FOLD_UNTIL_HPP_INCLUDED
#include <boost/mpl/bool.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/utility/result_of.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/fusion/support/void.hpp>
#include <boost/fusion/container/list/cons.hpp>
#include <boost/fusion/container/generation/make_cons.hpp>
#include <boost/fusion/view/iterator_range.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/sequence/intrinsic/empty.hpp>
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/iterator/value_of.hpp>
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/support/ext_/is_segmented.hpp>
#include <boost/fusion/sequence/intrinsic/ext_/segments.hpp>
// fun(rng, state, context)
// rng: a non-segmented range
// state: the state of the fold so far
// context: the path to the current range
//
// returns: (state', fcontinue)
namespace boost { namespace fusion
{
template<typename Context>
struct segmented_iterator;
namespace result_of
{
template<typename Cur, typename Context>
struct make_segmented_iterator
{
typedef
iterator_range<
Cur,
typename result_of::end<
typename remove_reference<
typename add_const<
typename result_of::deref<
typename Context::car_type::begin_type
>::type
>::type
>::type
>::type
>
range_type;
typedef
segmented_iterator<cons<range_type, Context> >
type;
};
}
template<typename Cur, typename Context>
typename result_of::make_segmented_iterator<Cur, Context>::type
make_segmented_iterator(Cur const& cur, Context const& context)
{
typedef result_of::make_segmented_iterator<Cur, Context> impl_type;
typedef typename impl_type::type type;
typedef typename impl_type::range_type range_type;
return type(fusion::make_cons(range_type(cur, fusion::end(*context.car.first)), context));
}
typedef mpl::true_ continue_;
typedef mpl::false_ break_;
template<typename Value, typename Continue>
struct result
{
typedef Value value_type;
typedef Continue continue_type;
result(Value const& val)
: value(val)
{}
value_type value;
};
template<typename Continue>
struct result<void, Continue>
{
typedef void_ value_type;
typedef Continue continue_type;
result(void_ const&)
{}
value_type value;
};
template<typename Value>
result<Value, continue_> make_result_continue(Value const& val)
{
return result<Value, continue_>(val);
}
template<typename Value>
result<Value, break_> make_result_break(Value const& val)
{
return result<Value, break_>(val);
}
namespace detail
{
template<
typename Begin,
typename End,
typename State,
typename Context,
typename Fun,
bool IsEmpty = result_of::empty<
typename result_of::value_of<Begin>::type
>::type::value>
struct segmented_fold_until_iterate_skip_empty;
template<
typename Begin,
typename End,
typename State,
typename Context,
typename Fun,
bool IsDone = result_of::equal_to<Begin, End>::type::value>
struct segmented_fold_until_iterate;
template<
typename Range,
typename State,
typename Context,
typename Fun,
bool IsSegmented = traits::is_segmented<Range>::type::value>
struct segmented_fold_until_impl;
template<typename Segments, typename State, typename Context, typename Fun>
struct segmented_fold_until_on_segments;
//auto push_context(cur, end, context)
//{
// return push_back(context, segment_sequence(iterator_range(cur, end)));
//}
template<typename Cur, typename End, typename Context>
struct push_context
{
typedef iterator_range<Cur, End> range_type;
typedef cons<range_type, Context> type;
static type call(Cur const& cur, End const& end, Context const& context)
{
return fusion::make_cons(range_type(cur, end), context);
}
};
//auto make_segmented_iterator(cur, end, context)
//{
// return segmented_iterator(push_context(cur, end, context));
//}
//
//auto segmented_fold_until_impl(rng, state, context, fun)
//{
// if (is_segmented(rng))
// {
// segmented_fold_until_on_segments(segments(rng), state, context, fun);
// }
// else
// {
// return fun(rng, state, context);
// }
//}
template<
typename Range,
typename State,
typename Context,
typename Fun,
bool IsSegmented>
struct segmented_fold_until_impl
{
typedef
segmented_fold_until_on_segments<
typename remove_reference<
typename add_const<
typename result_of::segments<Range>::type
>::type
>::type,
State,
Context,
Fun
>
impl;
typedef typename impl::type type;
static type call(Range& rng, State const& state, Context const& context, Fun const& fun)
{
return impl::call(fusion::segments(rng), state, context, fun);
}
};
template<
typename Range,
typename State,
typename Context,
typename Fun>
struct segmented_fold_until_impl<Range, State, Context, Fun, false>
{
typedef
typename boost::result_of<Fun(
Range&,
typename add_reference<typename add_const<typename State::value_type>::type>::type,
Context const&
)>::type
type;
static type call(Range& rng, State const& state, Context const& context, Fun const& fun)
{
return fun(rng, state.value, context);
}
};
//auto segmented_fold_until_on_segments(segs, state, context, fun)
//{
// auto cur = begin(segs), end = end(segs);
// for (; cur != end; ++cur)
// {
// if (empty(*cur))
// continue;
// auto context` = push_context(cur, end, context);
// state = segmented_fold_until_impl(*cur, state, context`, fun);
// if (!second(state))
// return state;
// }
//}
template<typename Begin,typename End,typename State,typename Context,typename Fun,bool IsEmpty>
struct segmented_fold_until_iterate_skip_empty
{
// begin != end and !empty(*begin)
typedef
push_context<Begin, End, Context>
push_context_impl;
typedef
typename push_context_impl::type
next_context_type;
typedef
segmented_fold_until_impl<
typename remove_reference<
typename add_const<
typename result_of::deref<Begin>::type
>::type
>::type,
State,
next_context_type,
Fun
>
fold_recurse_impl;
typedef
typename fold_recurse_impl::type
next_state_type;
typedef
segmented_fold_until_iterate<
typename result_of::next<Begin>::type,
End,
next_state_type,
Context,
Fun
>
next_iteration_impl;
typedef
typename mpl::eval_if<
typename next_state_type::continue_type,
next_iteration_impl,
mpl::identity<next_state_type>
>::type
type;
static type call(Begin const& beg, End const& end, State const& state,
Context const& context, Fun const& fun)
{
return call(beg, end, state, context, fun, typename next_state_type::continue_type());
}
static type call(Begin const& beg, End const& end, State const& state,
Context const& context, Fun const& fun, mpl::true_) // continue
{
return next_iteration_impl::call(
fusion::next(beg),
end,
fold_recurse_impl::call(
*beg,
state,
push_context_impl::call(beg, end, context),
fun),
context,
fun);
}
static type call(Begin const& beg, End const& end, State const& state,
Context const& context, Fun const& fun, mpl::false_) // break
{
return fold_recurse_impl::call(
*beg,
state,
push_context_impl::call(beg, end, context),
fun);
}
};
template<typename Begin, typename End, typename State, typename Context, typename Fun>
struct segmented_fold_until_iterate_skip_empty<Begin, End, State, Context, Fun, true>
{
typedef
segmented_fold_until_iterate<
typename result_of::next<Begin>::type,
End,
State,
Context,
Fun
>
impl;
typedef typename impl::type type;
static type call(Begin const& beg, End const& end, State const& state,
Context const& context, Fun const& fun)
{
return impl::call(fusion::next(beg), end, state, context, fun);
}
};
template<typename Begin, typename End, typename State, typename Context, typename Fun, bool IsDone>
struct segmented_fold_until_iterate
{
typedef
segmented_fold_until_iterate_skip_empty<Begin, End, State, Context, Fun>
impl;
typedef typename impl::type type;
static type call(Begin const& beg, End const& end, State const& state,
Context const& context, Fun const& fun)
{
return impl::call(beg, end, state, context, fun);
}
};
template<typename Begin, typename End, typename State, typename Context, typename Fun>
struct segmented_fold_until_iterate<Begin, End, State, Context, Fun, true>
{
typedef State type;
static type call(Begin const&, End const&, State const& state,
Context const&, Fun const&)
{
return state;
}
};
template<typename Segments, typename State, typename Context, typename Fun>
struct segmented_fold_until_on_segments
{
typedef
segmented_fold_until_iterate<
typename result_of::begin<Segments>::type,
typename result_of::end<Segments>::type,
State,
Context,
Fun
>
impl;
typedef typename impl::type type;
static type call(Segments& segs, State const& state, Context const& context, Fun const& fun)
{
return impl::call(fusion::begin(segs), fusion::end(segs), state, context, fun);
}
};
}
//auto segmented_fold_until(rng, state, fun)
//{
// return first(segmented_fold_until_impl(rng, state, nil, fun));
//}
namespace result_of
{
template<typename Range, typename State, typename Fun>
struct segmented_fold_until
{
typedef
detail::segmented_fold_until_impl<
Range,
result<State, continue_>,
fusion::nil,
Fun
>
impl;
typedef
typename impl::type::value_type
type;
};
}
template<typename Range, typename State, typename Fun>
typename result_of::segmented_fold_until<Range, State, Fun>::type
segmented_fold_until(Range& rng, State const& state, Fun const& fun)
{
typedef typename result_of::segmented_fold_until<Range, State, Fun>::impl impl;
return impl::call(rng, state, fusion::nil(), fun).value;
}
template<typename Range, typename State, typename Fun>
typename result_of::segmented_fold_until<Range const, State, Fun>::type
segmented_fold_until(Range const& rng, State const& state, Fun const& fun)
{
typedef typename result_of::segmented_fold_until<Range const, State, Fun>::impl impl;
return impl::call(rng, state, fusion::nil(), fun).value;
}
}}
#endif

View File

@ -1,93 +0,0 @@
/*=============================================================================
Copyright (c) 2011 Eric Niebler
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_FUSION_SEGMENTED_ITERATOR_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_ITERATOR_HPP_INCLUDED
#include <boost/mpl/equal.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/fusion/mpl/begin.hpp>
#include <boost/fusion/mpl/end.hpp>
#include <boost/fusion/mpl/clear.hpp>
#include <boost/fusion/mpl/push_front.hpp>
#include <boost/fusion/iterator/iterator_facade.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/view/ext_/detail/next_impl.hpp>
#include <boost/fusion/view/ext_/segmented_begin.hpp>
#include <boost/fusion/view/ext_/segmented_end.hpp>
#include <boost/fusion/container/vector/convert.hpp>
namespace boost { namespace fusion
{
// A segmented iterator wraps a "context", which is a cons list
// of ranges, the frontmost is range over values and the rest
// are ranges over internal segments.
template<typename Context>
struct segmented_iterator
: iterator_facade<segmented_iterator<Context>, forward_traversal_tag>
{
explicit segmented_iterator(Context const& ctx)
: context(ctx)
{}
//auto deref(it)
//{
// return deref(begin(car(it.context)))
//}
template<typename It>
struct deref
{
typedef
typename result_of::deref<
typename It::context_type::car_type::begin_type
>::type
type;
static type call(It const& it)
{
return *it.context.car.first;
}
};
// Compare all the segment iterators in each stack, starting with
// the bottom-most.
template<typename It1, typename It2>
struct equal_to
: mpl::equal<
typename mpl::reverse_transform<
typename result_of::as_vector<typename It1::context_type>::type,
result_of::begin<mpl::_1>
>::type,
typename mpl::reverse_transform<
typename result_of::as_vector<typename It2::context_type>::type,
result_of::begin<mpl::_1>
>::type,
result_of::equal_to<mpl::_1, mpl::_2>
>
{};
template<typename It>
struct next
{
typedef detail::segmented_next_impl<typename It::context_type> impl;
typedef segmented_iterator<typename impl::type> type;
static type call(It const& it)
{
return type(impl::call(it.context));
}
};
typedef Context context_type;
context_type context;
};
}}
#endif

View File

@ -15,15 +15,15 @@
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/sequence/intrinsic/ext_/segments.hpp>
#include <boost/fusion/sequence/intrinsic/ext_/segmented_size.hpp>
#include <boost/fusion/sequence/intrinsic/segments.hpp>
#include <boost/fusion/sequence/intrinsic/detail/segmented_size.hpp>
#include <boost/fusion/algorithm/transformation/push_back.hpp>
#include <boost/fusion/algorithm/transformation/push_front.hpp>
#include <boost/fusion/view/iterator_range.hpp>
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/fusion/view/ext_/segmented_iterator.hpp>
#include <boost/fusion/view/ext_/detail/reverse_cons.hpp>
#include <boost/fusion/view/ext_/detail/segment_sequence.hpp>
#include <boost/fusion/iterator/segmented_iterator.hpp>
#include <boost/fusion/container/list/detail/reverse_cons.hpp>
#include <boost/fusion/iterator/segmented_iterator/detail/segment_sequence.hpp>
// Invariants:
// - Each segmented iterator has a stack