/*============================================================================= Copyright (c) 2006 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 #include #include #include #include #include #include #include #include #include #include #include #include // fwd declarations namespace boost { namespace fusion { namespace detail { template::value> struct static_find_if_s_recurse; } namespace result_of { template struct find_if_s; } }} namespace boost { namespace fusion { namespace detail { template::value> struct is_found : mpl::not_::type> > {}; template struct is_found : mpl::not_ > {}; 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::value > struct as_segmented_cons { typedef cons< SegmentedRange , cons > > type; static type call(SegmentedRange const &range, Where const &where) { return fusion::make_cons( range , fusion::make_cons( segmented_range(*fusion::begin(range), where) ) ); } }; template< typename SegmentedRange , typename Where , typename Sequence > struct as_segmented_cons { typedef cons 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::value > struct static_find_if_s_seg { typedef typename SegmentedRange::iterator_type first; typedef typename result_of::deref::type segment_ref; typedef typename remove_reference::type segment; typedef static_find_if_s_recurse where; typedef range_next next; typedef is_found is_found; typedef as_segmented_cons found; typedef static_find_if_s_seg not_found; typedef typename mpl::eval_if::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 { typedef nil type; static type call(SegmentedRange const &) { return nil(); } }; template struct static_find_if_s_recurse { typedef typename as_segmented_range::type range; typedef static_find_if_s_seg find_if; typedef typename find_if::type type; static type call(Sequence &seq) { return find_if::call(range(fusion::segments(seq))); } }; template struct static_find_if_s_recurse { typedef typename result_of::find_if::type type; static type call(Sequence &seq) { return fusion::find_if(seq); } }; template::value> struct static_find_if_s : static_find_if_s_recurse {}; template struct static_find_if_s { typedef typename as_segmented_range::type range; typedef static_find_if_s_recurse find_if; typedef typename find_if::type found; typedef segmented_iterator::type> type; static type call(Sequence &seq) { return type(reverse_cons::call(find_if::call(seq))); } }; }}} namespace boost { namespace fusion { namespace result_of { template struct find_if_s { typedef typename detail::static_find_if_s< Sequence , Pred >::type type; }; } template typename lazy_disable_if< is_const , result_of::find_if_s >::type find_if_s(Sequence& seq) { return detail::static_find_if_s::call(seq); } template typename result_of::find_if_s::type find_if_s(Sequence const& seq) { return detail::static_find_if_s::call(seq); } }} #endif