baking segmented Fusion

[SVN r73854]
This commit is contained in:
Eric Niebler
2011-08-17 18:53:56 +00:00
parent 2baebc560a
commit 528ad04fdb
86 changed files with 1403 additions and 1041 deletions

View File

@ -8,6 +8,7 @@
#if !defined(FUSION_CONS_07172005_0843)
#define FUSION_CONS_07172005_0843
#include <boost/fusion/container/list/cons_fwd.hpp>
#include <boost/fusion/support/detail/access.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/sequence/intrinsic/end.hpp>
@ -55,7 +56,7 @@ namespace boost { namespace fusion
}
};
template <typename Car, typename Cdr = nil>
template <typename Car, typename Cdr /*= nil*/>
struct cons : sequence_base<cons<Car, Cdr> >
{
typedef mpl::int_<Cdr::size::value+1> size;

View File

@ -0,0 +1,20 @@
/*=============================================================================
Copyright (c) 2005 Joel de Guzman
Copyright (c) 2005 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_CONS_FWD_HPP_INCLUDED)
#define BOOST_FUSION_CONS_FWD_HPP_INCLUDED
namespace boost { namespace fusion
{
struct nil;
template <typename Car, typename Cdr = nil>
struct cons;
}}
#endif

View File

@ -7,8 +7,7 @@
#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>
#include <boost/fusion/container/list/cons_fwd.hpp>
namespace boost { namespace fusion { namespace detail
{
@ -24,7 +23,8 @@ namespace boost { namespace fusion { namespace detail
static type call(cons<Car, Cdr> const &cons, State const &state = State())
{
return impl::call(cons.cdr, fusion::make_cons(cons.car, state));
typedef fusion::cons<Car, State> cdr_type;
return impl::call(cons.cdr, cdr_type(cons.car, state));
}
};

View File

@ -0,0 +1,12 @@
/*=============================================================================
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_INCLUDE_IS_SEGMENTED)
#define BOOST_FUSION_INCLUDE_IS_SEGMENTED
#include <boost/fusion/support/is_segmented.hpp>
#endif

View File

@ -0,0 +1,12 @@
/*=============================================================================
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_INCLUDE_SEGMENTED_FOLD_UNTIL)
#define BOOST_FUSION_INCLUDE_SEGMENTED_FOLD_UNTIL
#include <boost/fusion/support/segmented_fold_until.hpp>
#endif

View File

@ -0,0 +1,12 @@
/*=============================================================================
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_INCLUDE_SEGMENTED_ITERATOR)
#define BOOST_FUSION_INCLUDE_SEGMENTED_ITERATOR
#include <boost/fusion/iterator/segmented_iterator.hpp>
#endif

View File

@ -0,0 +1,12 @@
/*=============================================================================
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_INCLUDE_SEGMENTS)
#define BOOST_FUSION_INCLUDE_SEGMENTS
#include <boost/fusion/sequence/intrinsic/segments.hpp>
#endif

View File

@ -0,0 +1,71 @@
/*=============================================================================
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_fwd.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;
}
};
};
}}}
#endif

View File

@ -0,0 +1,51 @@
/*=============================================================================
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_EQUAL_TO_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_ITERATOR_EQUAL_TO_HPP_INCLUDED
#include <boost/mpl/and.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/fusion/iterator/equal_to.hpp>
namespace boost { namespace fusion
{
struct nil;
namespace detail
{
template <typename Stack1, typename Stack2>
struct segmented_equal_to
: mpl::and_<
result_of::equal_to<
typename Stack1::car_type::begin_type,
typename Stack2::car_type::begin_type
>,
segmented_equal_to<
typename Stack1::cdr_type,
typename Stack2::cdr_type
>
>
{};
template <typename Stack1>
struct segmented_equal_to<Stack1, fusion::nil>
: mpl::false_
{};
template <typename Stack2>
struct segmented_equal_to<fusion::nil, Stack2>
: mpl::false_
{};
template <>
struct segmented_equal_to<fusion::nil, fusion::nil>
: mpl::true_
{};
}
}}
#endif

View File

@ -7,24 +7,22 @@
#if !defined(BOOST_FUSION_SEGMENTED_ITERATOR_SEGMENTED_ITERATOR_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_ITERATOR_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/sequence/intrinsic_fwd.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/iterator/segmented_iterator/detail/next_impl.hpp>
#include <boost/fusion/sequence/intrinsic/detail/segmented_begin.hpp>
#include <boost/fusion/sequence/intrinsic/detail/segmented_end.hpp>
#include <boost/fusion/container/vector/convert.hpp>
#include <boost/fusion/iterator/detail/segmented_equal_to.hpp>
#include <boost/fusion/container/list/detail/reverse_cons.hpp>
namespace boost { namespace fusion
{
struct nil;
namespace detail
{
template <typename Stack>
struct segmented_next_impl;
}
// 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.
@ -59,16 +57,9 @@ namespace boost { namespace fusion
// 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>
: detail::segmented_equal_to<
typename detail::reverse_cons<typename It1::context_type>::type,
typename detail::reverse_cons<typename It2::context_type>::type
>
{};

View File

@ -10,27 +10,29 @@
#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/container/list/cons_fwd.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/iterator/segmented_iterator/detail/begin_impl.hpp>
namespace boost { namespace fusion
{
template<typename First, typename Second>
template <typename First, typename Second>
struct iterator_range;
template<typename Context>
template <typename Context>
struct segmented_iterator;
namespace detail
{
template <typename Range, typename Stack>
struct segmented_begin_impl;
//bool is_invalid(stack)
//{
// return empty(car(stack));
//}
template<typename Stack>
template <typename Stack>
struct is_invalid
: result_of::equal_to<
typename Stack::car_type::begin_type,
@ -46,7 +48,7 @@ namespace boost { namespace fusion
// return cons(iterator_range(next(begin(car(stack))), end(car(stack))), cdr(stack));
//}
template<typename Stack>
template <typename Stack>
struct pop_front_car
{
typedef
@ -70,7 +72,7 @@ namespace boost { namespace fusion
}
};
template<
template <
typename Stack,
typename Next = typename pop_front_car<Stack>::type,
bool IsInvalid = is_invalid<Next>::value,
@ -86,7 +88,7 @@ namespace boost { namespace fusion
// return segmented_next_impl_recurse(stack.cdr);
//}
template<
template <
typename Stack,
int StackSize = Stack::size::value>
struct segmented_next_impl_recurse3
@ -100,7 +102,7 @@ namespace boost { namespace fusion
}
};
template<typename Stack>
template <typename Stack>
struct segmented_next_impl_recurse3<Stack, 1>
{
typedef typename Stack::car_type::end_type end_type;
@ -122,7 +124,7 @@ namespace boost { namespace fusion
// return res;
//}
template<
template <
typename Stack,
typename Range =
typename remove_reference<
@ -147,7 +149,7 @@ namespace boost { namespace fusion
}
};
template<typename Stack, typename Range, typename Result>
template <typename Stack, typename Range, typename Result>
struct segmented_next_impl_recurse2<Stack, Range, Result, false>
{
typedef Result type;
@ -170,7 +172,7 @@ namespace boost { namespace fusion
// return segmented_next_impl_recurse2(next)
//}
template<typename Stack, typename Next, bool IsInvalid, int StackSize>
template <typename Stack, typename Next, bool IsInvalid, int StackSize>
struct segmented_next_impl_recurse
{
typedef
@ -183,7 +185,7 @@ namespace boost { namespace fusion
}
};
template<typename Stack, typename Next>
template <typename Stack, typename Next>
struct segmented_next_impl_recurse<Stack, Next, true, 1>
{
typedef Next type;
@ -194,7 +196,7 @@ namespace boost { namespace fusion
}
};
template<typename Stack, typename Next, int StackSize>
template <typename Stack, typename Next, int StackSize>
struct segmented_next_impl_recurse<Stack, Next, false, StackSize>
{
typedef segmented_next_impl_recurse2<Next> impl;
@ -216,11 +218,11 @@ namespace boost { namespace fusion
// return next;
//}
template<
template <
typename Stack,
typename Next = typename pop_front_car<Stack>::type,
bool IsInvalid = is_invalid<Next>::value>
struct segmented_next_impl
struct segmented_next_impl_aux
{
typedef segmented_next_impl_recurse<typename Stack::cdr_type> impl;
typedef typename impl::type type;
@ -231,8 +233,8 @@ namespace boost { namespace fusion
}
};
template<typename Stack, typename Next>
struct segmented_next_impl<Stack, Next, false>
template <typename Stack, typename Next>
struct segmented_next_impl_aux<Stack, Next, false>
{
typedef Next type;
@ -241,6 +243,11 @@ namespace boost { namespace fusion
return pop_front_car<Stack>::call(stack);
}
};
template <typename Stack>
struct segmented_next_impl
: segmented_next_impl_aux<Stack>
{};
}
}}

View File

@ -7,6 +7,9 @@
#if !defined(BOOST_FUSION_SEGMENTED_ITERATOR_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_ITERATOR_HPP_INCLUDED
#include <boost/fusion/iterator/segmented_iterator/segmented_iterator.hpp>
#include <boost/fusion/iterator/detail/segmented_iterator.hpp>
#include <boost/fusion/iterator/detail/segmented_next_impl.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/container/list/cons.hpp>
#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/segments.hpp>
#include <boost/fusion/sequence/intrinsic/detail/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

@ -9,6 +9,7 @@
#include <boost/mpl/int.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/support/tag_of.hpp>
#include <boost/fusion/support/detail/access.hpp>

View File

@ -9,6 +9,7 @@
#define BOOST_FUSION_AT_KEY_20060304_1755
#include <boost/type_traits/is_const.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/algorithm/query/find.hpp>
#include <boost/fusion/iterator/deref_data.hpp>
#include <boost/fusion/support/tag_of.hpp>

View File

@ -7,6 +7,7 @@
#if !defined(FUSION_BACK_09162005_0350)
#define FUSION_BACK_09162005_0350
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/iterator/prior.hpp>
#include <boost/fusion/iterator/deref.hpp>

View File

@ -7,9 +7,14 @@
#if !defined(FUSION_BEGIN_04052005_1132)
#define FUSION_BEGIN_04052005_1132
#include <boost/blank.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/mpl/if.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/support/tag_of.hpp>
#include <boost/fusion/support/is_sequence.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/fusion/support/is_segmented.hpp>
#include <boost/fusion/sequence/intrinsic/detail/segmented_begin.hpp>
namespace boost { namespace fusion
{
@ -26,7 +31,13 @@ namespace boost { namespace fusion
struct begin_impl
{
template <typename Sequence>
struct apply;
struct apply
: mpl::if_<
traits::is_segmented<Sequence>
, detail::segmented_begin<Sequence>
, blank
>::type
{};
};
template <>

View File

@ -7,13 +7,11 @@
#if !defined(BOOST_FUSION_SEGMENTED_BEGIN_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_BEGIN_HPP_INCLUDED
#include <boost/fusion/iterator/segmented_iterator/detail/begin_impl.hpp>
#include <boost/fusion/sequence/intrinsic/detail/segmented_begin_impl.hpp>
#include <boost/fusion/iterator/segmented_iterator.hpp>
namespace boost { namespace fusion
namespace boost { namespace fusion { namespace detail
{
template<typename Context>
struct segmented_iterator;
//auto segmented_begin( rng )
//{
// return make_segmented_iterator( segmented_begin_impl( rng, nil ) );
@ -24,17 +22,17 @@ namespace boost { namespace fusion
{
typedef
segmented_iterator<
typename detail::segmented_begin_impl<Range, fusion::nil>::type
typename 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()));
segmented_begin_impl<Range, fusion::nil>::call(rng, fusion::nil()));
}
};
}}
}}}
#endif

View File

@ -8,23 +8,26 @@
#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/container/list/cons_fwd.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/support/is_segmented.hpp>
#include <boost/fusion/iterator/segmented_iterator/detail/end_impl.hpp>
#include <boost/fusion/support/segmented_fold_until.hpp>
#include <boost/fusion/sequence/intrinsic/detail/segmented_end_impl.hpp>
#include <boost/fusion/support/detail/segmented_fold_until_impl.hpp>
namespace boost { namespace fusion
{
template <typename First, typename Last>
struct iterator_range;
}}
namespace boost { namespace fusion { namespace detail
{
struct segmented_begin_fun
{
template<typename Sig>
template <typename Sig>
struct result;
template<typename This, typename Range, typename State, typename Context>
template <typename This, typename Range, typename State, typename Context>
struct result<This(Range&, State&, Context&)>
{
typedef
@ -42,7 +45,7 @@ namespace boost { namespace fusion { namespace detail
type;
};
template<typename Range, typename State, typename Context>
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
{
@ -53,12 +56,12 @@ namespace boost { namespace fusion { namespace detail
>
range_type;
return fusion::make_cons(range_type(fusion::begin(rng), fusion::end(rng)), context);
return cons<range_type, Context>(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
template <typename Range, typename Stack, bool IsSegmented = traits::is_segmented<Range>::type::value>
struct segmented_begin_impl_aux
{
typedef
segmented_end_impl<Range, Stack>
@ -81,8 +84,8 @@ namespace boost { namespace fusion { namespace detail
}
};
template<typename Range, typename Stack>
struct segmented_begin_impl<Range, Stack, false>
template <typename Range, typename Stack>
struct segmented_begin_impl_aux<Range, Stack, false>
{
typedef typename result_of::begin<Range>::type begin_type;
typedef typename result_of::end<Range>::type end_type;
@ -95,6 +98,11 @@ namespace boost { namespace fusion { namespace detail
}
};
template <typename Range, typename Stack>
struct segmented_begin_impl
: segmented_begin_impl_aux<Range, Stack>
{};
}}}
#endif

View File

@ -7,14 +7,12 @@
#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/iterator/segmented_iterator/detail/end_impl.hpp>
#include <boost/fusion/container/list/cons_fwd.hpp>
#include <boost/fusion/sequence/intrinsic/detail/segmented_end_impl.hpp>
#include <boost/fusion/iterator/segmented_iterator.hpp>
namespace boost { namespace fusion
namespace boost { namespace fusion { namespace detail
{
template<typename Context>
struct segmented_iterator;
//auto segmented_end( rng )
//{
// return make_segmented_iterator( segmented_end_impl( rng ) );
@ -25,17 +23,17 @@ namespace boost { namespace fusion
{
typedef
segmented_iterator<
typename detail::segmented_end_impl<Range, fusion::nil>::type
typename 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()));
segmented_end_impl<Range, fusion::nil>::call(rng, fusion::nil()));
}
};
}}
}}}
#endif

View File

@ -10,12 +10,16 @@
#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/segments.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/container/list/cons_fwd.hpp>
#include <boost/fusion/support/is_segmented.hpp>
namespace boost { namespace fusion
{
template <typename First, typename Last>
struct iterator_range;
}}
namespace boost { namespace fusion { namespace detail
{
//auto segmented_end_impl( rng, stack )

View File

@ -13,48 +13,42 @@
#include <boost/mpl/plus.hpp>
#include <boost/mpl/size_t.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.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/sequence/intrinsic/size.hpp>
#include <boost/fusion/sequence/intrinsic/segments.hpp>
#include <boost/fusion/support/is_segmented.hpp>
namespace boost { namespace fusion
namespace boost { namespace fusion { namespace detail
{
///////////////////////////////////////////////////////////////////////////
// calculates the size of any segmented data structure.
template<typename Sequence>
struct segmented_size;
namespace detail
{
///////////////////////////////////////////////////////////////////////////
template<typename Sequence, bool IsSegmented = traits::is_segmented<Sequence>::value>
struct segmented_size_impl
: mpl::fold<
typename remove_reference<
typename add_const<
typename result_of::segments<Sequence>::type
>::type
>::type,
mpl::size_t<0>,
mpl::plus<mpl::_1, segmented_size<mpl::_2> >
>::type
{};
///////////////////////////////////////////////////////////////////////////
template<typename Sequence, bool IsSegmented = traits::is_segmented<Sequence>::value>
struct segmented_size_impl
: mpl::fold<
typename remove_reference<
typename add_const<
typename result_of::segments<Sequence>::type
>::type
>::type,
mpl::size_t<0>,
mpl::plus<mpl::_1, segmented_size<mpl::_2> >
>::type
{};
template<typename Sequence>
struct segmented_size_impl<Sequence, false>
: result_of::size<Sequence>::type
{};
}
template<typename Sequence>
struct segmented_size_impl<Sequence, false>
: result_of::size<Sequence>::type
{};
template<typename Sequence>
struct segmented_size
: detail::segmented_size_impl<Sequence>
: segmented_size_impl<Sequence>
{};
}}
}}}
#endif

View File

@ -7,6 +7,7 @@
#if !defined(FUSION_EMPTY_09162005_0335)
#define FUSION_EMPTY_09162005_0335
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/fusion/support/tag_of.hpp>

View File

@ -7,9 +7,14 @@
#if !defined(FUSION_END_04052005_1141)
#define FUSION_END_04052005_1141
#include <boost/blank.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/mpl/if.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/support/tag_of.hpp>
#include <boost/fusion/support/is_sequence.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/fusion/support/is_segmented.hpp>
#include <boost/fusion/sequence/intrinsic/detail/segmented_end.hpp>
namespace boost { namespace fusion
{
@ -26,7 +31,13 @@ namespace boost { namespace fusion
struct end_impl
{
template <typename Sequence>
struct apply;
struct apply
: mpl::if_<
traits::is_segmented<Sequence>
, detail::segmented_end<Sequence>
, blank
>::type
{};
};
template <>

View File

@ -7,6 +7,7 @@
#if !defined(FUSION_FRONT_09162005_0343)
#define FUSION_FRONT_09162005_0343
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/mpl/bool.hpp>

View File

@ -7,6 +7,7 @@
#if !defined(FUSION_HAS_KEY_09232005_1454)
#define FUSION_HAS_KEY_09232005_1454
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/support/tag_of.hpp>
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/fusion/algorithm/query/find.hpp>

View File

@ -7,6 +7,9 @@
#if !defined(BOOST_FUSION_SEGMENTS_04052005_1141)
#define BOOST_FUSION_SEGMENTS_04052005_1141
#include <boost/type_traits/is_const.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/support/tag_of.hpp>
namespace boost { namespace fusion
@ -50,15 +53,19 @@ namespace boost { namespace fusion
}
template <typename Sequence>
typename result_of::segments<Sequence>::type
segments(Sequence & seq)
inline typename
lazy_disable_if<
is_const<Sequence>
, result_of::segments<Sequence>
>::type
segments(Sequence& seq)
{
typedef typename traits::tag_of<Sequence>::type tag_type;
return extension::segments_impl<tag_type>::template apply<Sequence>::call(seq);
}
template <typename Sequence>
typename result_of::segments<Sequence const>::type
inline typename result_of::segments<Sequence const>::type
segments(Sequence const& seq)
{
typedef typename traits::tag_of<Sequence const>::type tag_type;

View File

@ -7,8 +7,13 @@
#if !defined(FUSION_SIZE_05052005_0214)
#define FUSION_SIZE_05052005_0214
#include <boost/utility/enable_if.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/support/tag_of.hpp>
#include <boost/fusion/support/is_segmented.hpp>
#include <boost/fusion/sequence/intrinsic/detail/segmented_size.hpp>
namespace boost { namespace fusion
{
@ -24,8 +29,17 @@ namespace boost { namespace fusion
template <typename Tag>
struct size_impl
{
template<typename Sequence>
struct unsegmented_size : Sequence::size {};
template <typename Sequence>
struct apply : Sequence::size {};
struct apply
: mpl::if_<
traits::is_segmented<Sequence>
, detail::segmented_size<Sequence>
, unsegmented_size<Sequence>
>::type
{};
};
template <>

View File

@ -8,6 +8,7 @@
#define FUSION_VALUE_AT_05052005_0229
#include <boost/mpl/int.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/support/tag_of.hpp>
namespace boost { namespace fusion

View File

@ -9,6 +9,7 @@
#define FUSION_VALUE_AT_KEY_05052005_0229
#include <boost/mpl/int.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/iterator/value_of_data.hpp>
#include <boost/fusion/algorithm/query/find.hpp>
#include <boost/fusion/support/tag_of.hpp>

View File

@ -0,0 +1,203 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
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_SEQUENCE_INTRINSIC_FWD_HPP_INCLUDED)
#define BOOST_FUSION_SEQUENCE_INTRINSIC_FWD_HPP_INCLUDED
#include <boost/type_traits/is_const.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/fusion/support/is_sequence.hpp>
namespace boost { namespace fusion
{
namespace extension
{
template <typename Tag>
struct at_impl;
template <typename Tag>
struct begin_impl;
template <typename Tag>
struct empty_impl;
template <typename Tag>
struct end_impl;
template <typename Tag>
struct has_key_impl;
template <typename Tag>
struct segments_impl;
template <typename Tag>
struct size_impl;
template <typename Tag>
struct value_at_impl;
template <typename Tag>
struct at_key_impl;
template <typename Tag>
struct value_at_key_impl;
}
namespace result_of
{
template <typename Sequence, typename N>
struct at;
template <typename Sequence, int N>
struct at_c;
template <typename Sequence>
struct back;
template <typename Sequence>
struct begin;
template <typename Sequence>
struct empty;
template <typename Sequence>
struct end;
template <typename Sequence>
struct front;
template <typename Sequence, typename Key>
struct has_key;
template <typename Sequence>
struct segments;
template <typename Sequence>
struct size;
template <typename Sequence, typename N>
struct value_at;
template <typename Sequence, int N>
struct value_at_c;
template <typename Sequence, typename Key>
struct at_key;
template <typename Sequence, typename N>
struct value_at_key;
}
template <typename N, typename Sequence>
typename
lazy_disable_if<
is_const<Sequence>
, result_of::at<Sequence, N>
>::type
at(Sequence& seq);
template <typename N, typename Sequence>
typename result_of::at<Sequence const, N>::type
at(Sequence const& seq);
template <int N, typename Sequence>
typename
lazy_disable_if<
is_const<Sequence>
, result_of::at_c<Sequence, N>
>::type
at_c(Sequence& seq);
template <int N, typename Sequence>
typename result_of::at_c<Sequence const, N>::type
at_c(Sequence const& seq);
template <typename Sequence>
typename result_of::back<Sequence>::type
back(Sequence& seq);
template <typename Sequence>
typename result_of::back<Sequence const>::type
back(Sequence const& seq);
template <typename Sequence>
typename
lazy_enable_if<
traits::is_sequence<Sequence>
, result_of::begin<Sequence>
>::type const
begin(Sequence& seq);
template <typename Sequence>
typename
lazy_enable_if<
traits::is_sequence<Sequence>
, result_of::begin<Sequence const>
>::type const
begin(Sequence const& seq);
template <typename Sequence>
typename result_of::empty<Sequence>::type
empty(Sequence const&);
template <typename Sequence>
typename
lazy_enable_if<
traits::is_sequence<Sequence>
, result_of::end<Sequence>
>::type const
end(Sequence& seq);
template <typename Sequence>
typename
lazy_enable_if<
traits::is_sequence<Sequence>
, result_of::end<Sequence const>
>::type const
end(Sequence const& seq);
template <typename Sequence>
typename result_of::front<Sequence>::type
front(Sequence& seq);
template <typename Sequence>
typename result_of::front<Sequence const>::type
front(Sequence const& seq);
template <typename Key, typename Sequence>
typename result_of::has_key<Sequence, Key>::type
has_key(Sequence const& seq);
template <typename Sequence>
typename
lazy_disable_if<
is_const<Sequence>
, result_of::segments<Sequence>
>::type
segments(Sequence& seq);
template <typename Sequence>
typename result_of::segments<Sequence const>::type
segments(Sequence const& seq);
template <typename Sequence>
typename result_of::size<Sequence>::type
size(Sequence const&);
template <typename Key, typename Sequence>
typename
lazy_disable_if<
is_const<Sequence>
, result_of::at_key<Sequence, Key>
>::type
at_key(Sequence& seq);
template <typename Key, typename Sequence>
typename result_of::at_key<Sequence const, Key>::type
at_key(Sequence const& seq);
}}
#endif

View File

@ -0,0 +1,401 @@
/*=============================================================================
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_IMPL_HPP_INCLUDED)
#define BOOST_FUSION_SEGMENTED_FOLD_UNTIL_IMPL_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_fwd.hpp>
#include <boost/fusion/sequence/intrinsic_fwd.hpp>
#include <boost/fusion/iterator/value_of.hpp>
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/support/is_segmented.hpp>
#include <boost/fusion/sequence/intrinsic/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 First, typename Last>
struct iterator_range;
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(cons<range_type, Context>(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 cons<range_type, Context>(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);
}
};
}
}}
#endif

View File

@ -7,397 +7,15 @@
#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/support/detail/segmented_fold_until_impl.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/is_segmented.hpp>
#include <boost/fusion/sequence/intrinsic/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)
#include <boost/fusion/sequence/intrinsic/empty.hpp>
#include <boost/fusion/container/list/cons.hpp>
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));
@ -405,7 +23,7 @@ namespace boost { namespace fusion
namespace result_of
{
template<typename Range, typename State, typename Fun>
template <typename Range, typename State, typename Fun>
struct segmented_fold_until
{
typedef
@ -423,7 +41,7 @@ namespace boost { namespace fusion
};
}
template<typename Range, typename State, typename Fun>
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)
{
@ -431,7 +49,7 @@ namespace boost { namespace fusion
return impl::call(rng, state, fusion::nil(), fun).value;
}
template<typename Range, typename State, typename Fun>
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)
{
@ -439,5 +57,4 @@ namespace boost { namespace fusion
return impl::call(rng, state, fusion::nil(), fun).value;
}
}}
#endif

View File

@ -0,0 +1,66 @@
/*=============================================================================
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_ITERATOR_RANGE_IS_SEGMENTED_HPP_INCLUDED)
#define BOOST_FUSION_ITERATOR_RANGE_IS_SEGMENTED_HPP_INCLUDED
#include <boost/mpl/assert.hpp>
#include <boost/mpl/bool.hpp>
namespace boost { namespace fusion
{
struct iterator_range_tag;
template <typename Context>
struct segmented_iterator;
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>
{
private:
template <typename Iterator>
struct is_segmented_iterator
: mpl::false_
{};
template <typename Iterator>
struct is_segmented_iterator<Iterator &>
: is_segmented_iterator<Iterator>
{};
template <typename Iterator>
struct is_segmented_iterator<Iterator const>
: is_segmented_iterator<Iterator>
{};
template <typename Context>
struct is_segmented_iterator<segmented_iterator<Context> >
: mpl::true_
{};
public:
template <typename Sequence>
struct apply
: is_segmented_iterator<typename Sequence::begin_type>
{
BOOST_MPL_ASSERT_RELATION(
is_segmented_iterator<typename Sequence::begin_type>::value,
==,
is_segmented_iterator<typename Sequence::end_type>::value);
};
};
}
}}
#endif

View File

@ -16,14 +16,11 @@
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/deref.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/iterator/segmented_iterator.hpp>
#include <boost/fusion/container/list/detail/reverse_cons.hpp>
#include <boost/fusion/iterator/segmented_iterator/detail/segment_sequence.hpp>
#include <boost/fusion/iterator/detail/segment_sequence.hpp>
// Invariants:
// - Each segmented iterator has a stack
@ -35,8 +32,8 @@
namespace boost { namespace fusion
{
template<typename Context>
struct segmented_iterator;
template <typename First, typename Last>
struct iterator_range;
}}
namespace boost { namespace fusion { namespace detail
@ -65,7 +62,7 @@ namespace boost { namespace fusion { namespace detail
// }
//}
template<typename Stack, std::size_t Size = Stack::size::value>
template <typename Stack, std::size_t Size = Stack::size::value>
struct make_segment_sequence_front
{
// assert(end(segments(front(car(stack_begin)))) == end(car(cdr(stack_begin))));
@ -138,7 +135,7 @@ namespace boost { namespace fusion { namespace detail
}
};
template<typename Stack>
template <typename Stack>
struct make_segment_sequence_front<Stack, 2>
{
// assert(end(front(car(stack_begin))) == end(car(cdr(stack_begin))));
@ -178,7 +175,7 @@ namespace boost { namespace fusion { namespace detail
}
};
template<typename Stack>
template <typename Stack>
struct make_segment_sequence_front<Stack, 1>
{
typedef nil type;
@ -209,7 +206,7 @@ namespace boost { namespace fusion { namespace detail
// }
//}
template<typename Stack, std::size_t Size = Stack::size::value>
template <typename Stack, std::size_t Size = Stack::size::value>
struct make_segment_sequence_back
{
// assert(end(segments(front(car(stack_begin)))) == end(car(cdr(stack_begin))));
@ -280,7 +277,7 @@ namespace boost { namespace fusion { namespace detail
}
};
template<typename Stack>
template <typename Stack>
struct make_segment_sequence_back<Stack, 2>
{
// assert(end(front(car(stack_end))) == end(car(cdr(stack_end))));
@ -320,7 +317,7 @@ namespace boost { namespace fusion { namespace detail
}
};
template<typename Stack>
template <typename Stack>
struct make_segment_sequence_back<Stack, 1>
{
typedef nil type;
@ -364,14 +361,14 @@ namespace boost { namespace fusion { namespace detail
// }
//}
template<
template <
typename StackBegin,
typename StackEnd,
int StackBeginSize = StackBegin::size::value,
int StackEndSize = StackEnd::size::value>
struct make_segmented_range_reduce;
template<
template <
typename StackBegin,
typename StackEnd,
bool SameSegment =
@ -421,7 +418,7 @@ namespace boost { namespace fusion { namespace detail
}
};
template<typename StackBegin, typename StackEnd>
template <typename StackBegin, typename StackEnd>
struct make_segmented_range_reduce2<StackBegin, StackEnd, true>
{
typedef
@ -441,12 +438,12 @@ namespace boost { namespace fusion { namespace detail
}
};
template<typename StackBegin, typename StackEnd, int StackBeginSize, int StackEndSize>
template <typename StackBegin, typename StackEnd, int StackBeginSize, int StackEndSize>
struct make_segmented_range_reduce
: make_segmented_range_reduce2<StackBegin, StackEnd>
{};
template<typename StackBegin, typename StackEnd>
template <typename StackBegin, typename StackEnd>
struct make_segmented_range_reduce<StackBegin, StackEnd, 1, 1>
{
typedef
@ -478,7 +475,7 @@ namespace boost { namespace fusion { namespace detail
// return make_segmented_range_reduce(reverse(begin.context), reverse(end.context));
//}
template<typename Begin, typename End>
template <typename Begin, typename End>
struct make_segmented_range
{
typedef reverse_cons<typename Begin::context_type> reverse_begin_cons;
@ -503,81 +500,4 @@ namespace boost { namespace fusion { namespace detail
}}}
namespace boost { namespace fusion { 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>
{
private:
template<typename Iterator>
struct is_segmented_iterator
: mpl::false_
{};
template<typename Iterator>
struct is_segmented_iterator<Iterator &>
: is_segmented_iterator<Iterator>
{};
template<typename Iterator>
struct is_segmented_iterator<Iterator const>
: is_segmented_iterator<Iterator>
{};
template<typename Context>
struct is_segmented_iterator<segmented_iterator<Context> >
: mpl::true_
{};
public:
template<typename Sequence>
struct apply
: is_segmented_iterator<typename Sequence::begin_type>
{
BOOST_MPL_ASSERT_RELATION(
is_segmented_iterator<typename Sequence::begin_type>::value,
==,
is_segmented_iterator<typename Sequence::end_type>::value);
};
};
template<typename Tag>
struct segments_impl;
template<>
struct segments_impl<iterator_range_tag>
{
template<typename Sequence>
struct apply
{
typedef
detail::make_segmented_range<
typename Sequence::begin_type,
typename Sequence::end_type
>
impl;
BOOST_MPL_ASSERT((traits::is_segmented<typename impl::type>));
typedef
typename result_of::segments<typename impl::type>::type
type;
static type call(Sequence & seq)
{
return fusion::segments(impl::call(seq.first, seq.last));
}
};
};
// TODO: default implementation of begin, end, and size
// should check if the sequence is segmented and to
// the right thing.
}}}
#endif

View File

@ -0,0 +1,52 @@
/*=============================================================================
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_ITERATOR_RANGE_SEGMENTS_HPP_INCLUDED)
#define BOOST_FUSION_ITERATOR_RANGE_SEGMENTS_HPP_INCLUDED
#include <boost/mpl/assert.hpp>
#include <boost/fusion/sequence/intrinsic/segments.hpp>
#include <boost/fusion/support/is_segmented.hpp>
#include <boost/fusion/view/iterator_range/detail/segmented_iterator_range.hpp>
namespace boost { namespace fusion
{
struct iterator_range_tag;
namespace extension
{
template <typename Tag>
struct segments_impl;
template <>
struct segments_impl<iterator_range_tag>
{
template <typename Sequence>
struct apply
{
typedef
detail::make_segmented_range<
typename Sequence::begin_type,
typename Sequence::end_type
>
impl;
BOOST_MPL_ASSERT((traits::is_segmented<typename impl::type>));
typedef
typename result_of::segments<typename impl::type>::type
type;
static type call(Sequence & seq)
{
return fusion::segments(impl::call(seq.first, seq.last));
}
};
};
}
}}
#endif

View File

@ -17,6 +17,8 @@
#include <boost/fusion/view/iterator_range/detail/at_impl.hpp>
#include <boost/fusion/view/iterator_range/detail/size_impl.hpp>
#include <boost/fusion/view/iterator_range/detail/value_at_impl.hpp>
#include <boost/fusion/view/iterator_range/detail/is_segmented_impl.hpp>
#include <boost/fusion/view/iterator_range/detail/segments_impl.hpp>
#include <boost/fusion/adapted/mpl/mpl_iterator.hpp>
#include <boost/config.hpp>