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

@@ -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,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/is_segmented.hpp>
#include <boost/fusion/iterator/segmented_iterator/detail/end_impl.hpp>
#include <boost/fusion/support/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/segments.hpp>
#include <boost/fusion/support/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,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