forked from boostorg/fusion
new cleaner(?) implementation for segmented fusion
[SVN r73644]
This commit is contained in:
77
include/boost/fusion/algorithm/iteration/ext_/fold_s.hpp
Normal file
77
include/boost/fusion/algorithm/iteration/ext_/fold_s.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
/*=============================================================================
|
||||
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_FOLD_S_HPP_INCLUDED)
|
||||
#define BOOST_FUSION_FOLD_S_HPP_INCLUDED
|
||||
|
||||
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||
#include <boost/fusion/view/ext_/segmented_fold_until.hpp>
|
||||
|
||||
namespace boost { namespace fusion { namespace detail
|
||||
{
|
||||
template<typename Fun>
|
||||
struct segmented_fold_fun
|
||||
{
|
||||
template<typename Sig>
|
||||
struct result;
|
||||
|
||||
template<typename This, typename Range, typename State, typename Context>
|
||||
struct result<This(Range&, State&, Context&)>
|
||||
{
|
||||
typedef
|
||||
fusion::result<
|
||||
typename result_of::fold<Range, typename State::value_type, Fun>::type,
|
||||
continue_
|
||||
>
|
||||
type;
|
||||
};
|
||||
|
||||
explicit segmented_fold_fun(Fun const& f)
|
||||
: fun(f)
|
||||
{}
|
||||
|
||||
template<typename Range, typename State, typename Context>
|
||||
typename result<segmented_fold_fun(Range&, State const&, Context const&)>::type
|
||||
operator()(Range& rng, State const& state, Context const&) const
|
||||
{
|
||||
return fusion::fold(rng, state.value, fun);
|
||||
}
|
||||
|
||||
Fun const& fun;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
namespace result_of
|
||||
{
|
||||
template <typename Sequence, typename State, typename F>
|
||||
struct fold_s
|
||||
: result_of::segmented_fold_until<
|
||||
Sequence,
|
||||
State,
|
||||
detail::segmented_fold_fun<F>
|
||||
>
|
||||
{};
|
||||
}
|
||||
|
||||
template <typename Sequence, typename State, typename F>
|
||||
typename result_of::fold_s<Sequence, State, F>::type
|
||||
fold_s(Sequence& seq, State const& state, F const& f)
|
||||
{
|
||||
return fusion::segmented_fold_until(seq, state, detail::segmented_fold_fun<F>(f));
|
||||
}
|
||||
|
||||
template <typename Sequence, typename State, typename F>
|
||||
typename result_of::fold_s<Sequence const, State, F>::type
|
||||
fold_s(Sequence const& seq, State const& state, F const& f)
|
||||
{
|
||||
return fusion::segmented_fold_until(seq, state, detail::segmented_fold_fun<F>(f));
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
64
include/boost/fusion/algorithm/iteration/ext_/for_each_s.hpp
Executable file → Normal file
64
include/boost/fusion/algorithm/iteration/ext_/for_each_s.hpp
Executable file → Normal file
@ -1,65 +1,37 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2006 Eric Niebler
|
||||
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(FUSION_FOR_EACH_S_05022006_1027)
|
||||
#define FUSION_FOR_EACH_S_05022006_1027
|
||||
#if !defined(BOOST_FUSION_FOR_EACH_S_HPP_INCLUDED)
|
||||
#define BOOST_FUSION_FOR_EACH_S_HPP_INCLUDED
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/fusion/support/void.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/for_each.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/ext_/segments.hpp>
|
||||
#include <boost/fusion/support/ext_/is_segmented.hpp>
|
||||
|
||||
// fwd declarations
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
template <typename Sequence, typename F>
|
||||
void
|
||||
for_each_s(Sequence& seq, F const& f);
|
||||
|
||||
template <typename Sequence, typename F>
|
||||
void
|
||||
for_each_s(Sequence const& seq, F const& f);
|
||||
}}
|
||||
#include <boost/fusion/view/ext_/segmented_fold_until.hpp>
|
||||
|
||||
namespace boost { namespace fusion { namespace detail
|
||||
{
|
||||
template<typename F>
|
||||
struct for_each_s_bind
|
||||
template<typename Fun>
|
||||
struct segmented_for_each_fun
|
||||
{
|
||||
explicit for_each_s_bind(F const &f)
|
||||
: f_(f)
|
||||
typedef result<void, continue_> result_type;
|
||||
|
||||
explicit segmented_for_each_fun(Fun const& f)
|
||||
: fun(f)
|
||||
{}
|
||||
|
||||
template<typename Sequence>
|
||||
void operator ()(Sequence &seq) const
|
||||
template<typename Range, typename State, typename Context>
|
||||
result_type operator()(Range& rng, State const&, Context const&) const
|
||||
{
|
||||
fusion::for_each_s(seq, this->f_);
|
||||
fusion::for_each(rng, fun);
|
||||
return void_();
|
||||
}
|
||||
|
||||
template<typename Sequence>
|
||||
void operator ()(Sequence const &seq) const
|
||||
{
|
||||
fusion::for_each_s(seq, this->f_);
|
||||
}
|
||||
private:
|
||||
F const &f_;
|
||||
Fun const& fun;
|
||||
};
|
||||
|
||||
template<typename Sequence, typename F>
|
||||
void for_each_s(Sequence &seq, F const &f, mpl::true_)
|
||||
{
|
||||
fusion::for_each_s(fusion::segments(seq), for_each_s_bind<F>(f));
|
||||
}
|
||||
|
||||
template<typename Sequence, typename F>
|
||||
void for_each_s(Sequence &seq, F const &f, mpl::false_)
|
||||
{
|
||||
fusion::for_each(seq, f);
|
||||
}
|
||||
}}}
|
||||
|
||||
namespace boost { namespace fusion
|
||||
@ -77,14 +49,14 @@ namespace boost { namespace fusion
|
||||
inline void
|
||||
for_each_s(Sequence& seq, F const& f)
|
||||
{
|
||||
detail::for_each_s(seq, f, traits::is_segmented<Sequence>());
|
||||
fusion::segmented_fold_until(seq, void_(), detail::segmented_for_each_fun<F>(f));
|
||||
}
|
||||
|
||||
template <typename Sequence, typename F>
|
||||
inline void
|
||||
for_each_s(Sequence const& seq, F const& f)
|
||||
{
|
||||
detail::for_each_s(seq, f, traits::is_segmented<Sequence>());
|
||||
fusion::segmented_fold_until(seq, void_(), detail::segmented_for_each_fun<F>(f));
|
||||
}
|
||||
}}
|
||||
|
||||
|
227
include/boost/fusion/algorithm/query/ext_/find_if_s.hpp
Executable file → Normal file
227
include/boost/fusion/algorithm/query/ext_/find_if_s.hpp
Executable file → Normal file
@ -1,188 +1,58 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2006 Eric Niebler
|
||||
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(FIND_IF_S_05152006_1027)
|
||||
#define FIND_IF_S_05152006_1027
|
||||
#if !defined(BOOST_FUSION_FIND_IF_S_HPP_INCLUDED)
|
||||
#define BOOST_FUSION_FIND_IF_S_HPP_INCLUDED
|
||||
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/eval_if.hpp>
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/fusion/algorithm/query/find_if.hpp>
|
||||
#include <boost/fusion/container/list/cons.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/ext_/segments.hpp>
|
||||
#include <boost/fusion/view/ext_/segmented_iterator.hpp>
|
||||
#include <boost/fusion/view/ext_/segmented_iterator_range.hpp>
|
||||
#include <boost/fusion/support/ext_/is_segmented.hpp>
|
||||
|
||||
// fwd declarations
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename Sequence, typename Pred, bool IsSegmented = traits::is_segmented<Sequence>::value>
|
||||
struct static_find_if_s_recurse;
|
||||
}
|
||||
|
||||
namespace result_of
|
||||
{
|
||||
template <typename Sequence, typename Pred>
|
||||
struct find_if_s;
|
||||
}
|
||||
}}
|
||||
#include <boost/fusion/view/ext_/segmented_fold_until.hpp>
|
||||
|
||||
namespace boost { namespace fusion { namespace detail
|
||||
{
|
||||
|
||||
template<typename Sequence, typename Where, bool IsSegmented = traits::is_segmented<Sequence>::value>
|
||||
struct is_found
|
||||
: mpl::not_<result_of::equal_to<Where, typename result_of::end<Sequence>::type> >
|
||||
{};
|
||||
|
||||
template<typename Sequence, typename Cons>
|
||||
struct is_found<Sequence, Cons, true>
|
||||
: mpl::not_<is_same<nil, Cons> >
|
||||
{};
|
||||
|
||||
template<
|
||||
typename SegmentedRange
|
||||
, typename Where
|
||||
, typename Sequence = typename remove_reference<
|
||||
typename result_of::deref<
|
||||
typename SegmentedRange::iterator_type
|
||||
>::type
|
||||
>::type
|
||||
, bool IsSegmented = traits::is_segmented<Sequence>::value
|
||||
>
|
||||
struct as_segmented_cons
|
||||
template<typename Pred>
|
||||
struct segmented_find_if_fun
|
||||
{
|
||||
typedef cons<
|
||||
SegmentedRange
|
||||
, cons<segmented_range<Sequence, Where, false> >
|
||||
> type;
|
||||
template<typename Sig>
|
||||
struct result;
|
||||
|
||||
static type call(SegmentedRange const &range, Where const &where)
|
||||
template<typename This, typename Range, typename State, typename Context>
|
||||
struct result<This(Range&, State&, Context&)>
|
||||
{
|
||||
return fusion::make_cons(
|
||||
range
|
||||
, fusion::make_cons(
|
||||
segmented_range<Sequence, Where, false>(*fusion::begin(range), where)
|
||||
)
|
||||
);
|
||||
typedef
|
||||
typename result_of::find_if<Range, Pred>::type
|
||||
iterator_type;
|
||||
|
||||
typedef
|
||||
typename result_of::make_segmented_iterator<
|
||||
iterator_type,
|
||||
typename remove_const<Context>::type
|
||||
>::type
|
||||
segmented_iterator_type;
|
||||
|
||||
typedef
|
||||
typename mpl::if_<
|
||||
result_of::equal_to<
|
||||
iterator_type,
|
||||
typename result_of::end<Range>::type
|
||||
>,
|
||||
fusion::result<segmented_iterator_type, continue_>, // NOT FOUND
|
||||
fusion::result<segmented_iterator_type, break_> // FOUND
|
||||
>::type
|
||||
type;
|
||||
};
|
||||
|
||||
template<typename Range, typename State, typename Context>
|
||||
typename result<segmented_find_if_fun(Range&, State const&, Context const&)>::type
|
||||
operator()(Range& rng, State const&, Context const& context) const
|
||||
{
|
||||
return fusion::make_segmented_iterator(fusion::find_if<Pred>(rng), context);
|
||||
}
|
||||
};
|
||||
|
||||
template<
|
||||
typename SegmentedRange
|
||||
, typename Where
|
||||
, typename Sequence
|
||||
>
|
||||
struct as_segmented_cons<SegmentedRange, Where, Sequence, true>
|
||||
{
|
||||
typedef cons<SegmentedRange, Where> type;
|
||||
|
||||
static type call(SegmentedRange const &range, Where const &where)
|
||||
{
|
||||
return fusion::make_cons(range, where);
|
||||
}
|
||||
};
|
||||
|
||||
template<
|
||||
typename SegmentedRange
|
||||
, typename Pred
|
||||
, bool IsEmpty = is_empty<SegmentedRange>::value
|
||||
>
|
||||
struct static_find_if_s_seg
|
||||
{
|
||||
typedef typename SegmentedRange::iterator_type first;
|
||||
typedef typename result_of::deref<first>::type segment_ref;
|
||||
typedef typename remove_reference<segment_ref>::type segment;
|
||||
typedef static_find_if_s_recurse<segment, Pred> where;
|
||||
typedef range_next<SegmentedRange> next;
|
||||
typedef is_found<segment, typename where::type> is_found;
|
||||
typedef as_segmented_cons<SegmentedRange, typename where::type> found;
|
||||
typedef static_find_if_s_seg<typename next::type, Pred> not_found;
|
||||
typedef typename mpl::eval_if<is_found, found, not_found>::type type;
|
||||
|
||||
static type call(SegmentedRange const &range)
|
||||
{
|
||||
return call_(range, is_found());
|
||||
}
|
||||
|
||||
private:
|
||||
static type call_(SegmentedRange const &range, mpl::true_)
|
||||
{
|
||||
return found::call(range, where::call(*range.where_));
|
||||
}
|
||||
|
||||
static type call_(SegmentedRange const &range, mpl::false_)
|
||||
{
|
||||
return not_found::call(next::call(range));
|
||||
}
|
||||
};
|
||||
|
||||
template<
|
||||
typename SegmentedRange
|
||||
, typename Pred
|
||||
>
|
||||
struct static_find_if_s_seg<SegmentedRange, Pred, true>
|
||||
{
|
||||
typedef nil type;
|
||||
|
||||
static type call(SegmentedRange const &)
|
||||
{
|
||||
return nil();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Sequence, typename Pred>
|
||||
struct static_find_if_s_recurse<Sequence, Pred, true>
|
||||
{
|
||||
typedef typename as_segmented_range<Sequence>::type range;
|
||||
typedef static_find_if_s_seg<range, Pred> find_if;
|
||||
typedef typename find_if::type type;
|
||||
|
||||
static type call(Sequence &seq)
|
||||
{
|
||||
return find_if::call(range(fusion::segments(seq)));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Sequence, typename Pred>
|
||||
struct static_find_if_s_recurse<Sequence, Pred, false>
|
||||
{
|
||||
typedef typename result_of::find_if<Sequence, Pred>::type type;
|
||||
|
||||
static type call(Sequence &seq)
|
||||
{
|
||||
return fusion::find_if<Pred>(seq);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Sequence, typename Pred, bool IsSegmented = traits::is_segmented<Sequence>::value>
|
||||
struct static_find_if_s
|
||||
: static_find_if_s_recurse<Sequence, Pred, IsSegmented>
|
||||
{};
|
||||
|
||||
template<typename Sequence, typename Pred>
|
||||
struct static_find_if_s<Sequence, Pred, true>
|
||||
{
|
||||
typedef typename as_segmented_range<Sequence>::type range;
|
||||
typedef static_find_if_s_recurse<Sequence, Pred> find_if;
|
||||
typedef typename find_if::type found;
|
||||
|
||||
typedef segmented_iterator<typename reverse_cons<found>::type> type;
|
||||
|
||||
static type call(Sequence &seq)
|
||||
{
|
||||
return type(reverse_cons<found>::call(find_if::call(seq)));
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
namespace boost { namespace fusion
|
||||
@ -191,31 +61,22 @@ namespace boost { namespace fusion
|
||||
{
|
||||
template <typename Sequence, typename Pred>
|
||||
struct find_if_s
|
||||
{
|
||||
typedef typename
|
||||
detail::static_find_if_s<
|
||||
Sequence
|
||||
, Pred
|
||||
>::type
|
||||
type;
|
||||
};
|
||||
: result_of::segmented_fold_until<Sequence, void_, detail::segmented_find_if_fun<Pred> >
|
||||
{};
|
||||
}
|
||||
|
||||
template <typename Pred, typename Sequence>
|
||||
typename lazy_disable_if<
|
||||
is_const<Sequence>
|
||||
, result_of::find_if_s<Sequence, Pred>
|
||||
>::type
|
||||
typename result_of::find_if_s<Sequence, Pred>::type
|
||||
find_if_s(Sequence& seq)
|
||||
{
|
||||
return detail::static_find_if_s<Sequence, Pred>::call(seq);
|
||||
return fusion::segmented_fold_until(seq, void_(), detail::segmented_find_if_fun<Pred>());
|
||||
}
|
||||
|
||||
template <typename Pred, typename Sequence>
|
||||
typename result_of::find_if_s<Sequence const, Pred>::type
|
||||
find_if_s(Sequence const& seq)
|
||||
{
|
||||
return detail::static_find_if_s<Sequence const, Pred>::call(seq);
|
||||
return fusion::segmented_fold_until(seq, void_(), detail::segmented_find_if_fun<Pred>());
|
||||
}
|
||||
}}
|
||||
|
||||
|
83
include/boost/fusion/algorithm/query/ext_/find_s.hpp
Normal file
83
include/boost/fusion/algorithm/query/ext_/find_s.hpp
Normal file
@ -0,0 +1,83 @@
|
||||
/*=============================================================================
|
||||
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_FIND_S_HPP_INCLUDED)
|
||||
#define BOOST_FUSION_FIND_S_HPP_INCLUDED
|
||||
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/fusion/algorithm/query/find.hpp>
|
||||
#include <boost/fusion/view/ext_/segmented_fold_until.hpp>
|
||||
|
||||
namespace boost { namespace fusion { namespace detail
|
||||
{
|
||||
template<typename T>
|
||||
struct segmented_find_fun
|
||||
{
|
||||
template<typename Sig>
|
||||
struct result;
|
||||
|
||||
template<typename This, typename Range, typename State, typename Context>
|
||||
struct result<This(Range&, State&, Context&)>
|
||||
{
|
||||
typedef
|
||||
typename result_of::find<Range, T>::type
|
||||
iterator_type;
|
||||
|
||||
typedef
|
||||
typename result_of::make_segmented_iterator<
|
||||
iterator_type,
|
||||
typename remove_const<Context>::type
|
||||
>::type
|
||||
segmented_iterator_type;
|
||||
|
||||
typedef
|
||||
typename mpl::if_<
|
||||
result_of::equal_to<
|
||||
iterator_type,
|
||||
typename result_of::end<Range>::type
|
||||
>,
|
||||
fusion::result<segmented_iterator_type, continue_>, // NOT FOUND
|
||||
fusion::result<segmented_iterator_type, break_> // FOUND
|
||||
>::type
|
||||
type;
|
||||
};
|
||||
|
||||
template<typename Range, typename State, typename Context>
|
||||
typename result<segmented_find_fun(Range&, State const&, Context const&)>::type
|
||||
operator()(Range& rng, State const&, Context const& context) const
|
||||
{
|
||||
return fusion::make_segmented_iterator(fusion::find<T>(rng), context);
|
||||
}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
namespace result_of
|
||||
{
|
||||
template <typename Sequence, typename T>
|
||||
struct find_s
|
||||
: result_of::segmented_fold_until<Sequence, void_, detail::segmented_find_fun<T> >
|
||||
{};
|
||||
}
|
||||
|
||||
template <typename T, typename Sequence>
|
||||
typename result_of::find_s<Sequence, T>::type
|
||||
find_s(Sequence& seq)
|
||||
{
|
||||
return fusion::segmented_fold_until(seq, void_(), detail::segmented_find_fun<T>());
|
||||
}
|
||||
|
||||
template <typename T, typename Sequence>
|
||||
typename result_of::find_s<Sequence const, T>::type
|
||||
find_s(Sequence const& seq)
|
||||
{
|
||||
return fusion::segmented_fold_until(seq, void_(), detail::segmented_find_fun<T>());
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user