/*============================================================================= Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2008 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) ==============================================================================*/ #ifndef BOOST_PROTO_DETAIL_FUSION_REVERSE_EAH_01_22_2008 #define BOOST_PROTO_DETAIL_FUSION_REVERSE_EAH_01_22_2008 #include #include #include #include #include #include #include #include #include #include namespace boost { namespace fusion { struct reverse_view_tag; struct reverse_view_iterator_tag; template struct reverse_view_iterator : iterator_base > { typedef as_fusion_iterator converter; typedef typename converter::type first_type; typedef reverse_view_iterator_tag tag; reverse_view_iterator(First const& first) : first(converter::convert(first)) {} first_type first; }; template struct reverse_view : sequence_base > { typedef as_fusion_sequence seq_converter; typedef typename seq_converter::type seq; typedef reverse_view_tag tag; typedef typename meta::begin::type first_type; typedef typename meta::end::type last_type; reverse_view(Sequence& seq) : first(fusion::begin(seq)) , last(fusion::end(seq)) {} first_type first; last_type last; }; namespace meta { template <> struct deref_impl { template struct apply { typedef typename meta::deref< typename meta::prior< typename Iterator::first_type >::type >::type type; static type call(Iterator const& i) { return *fusion::prior(i.first); } }; }; template <> struct prior_impl { template struct apply { typedef typename Iterator::first_type first_type; typedef typename next_impl:: template apply wrapped; typedef reverse_view_iterator type; static type call(Iterator const& i) { return type(wrapped::call(i.first)); } }; }; template <> struct next_impl { template struct apply { typedef typename Iterator::first_type first_type; typedef typename prior_impl:: template apply wrapped; typedef reverse_view_iterator type; static type call(Iterator const& i) { return type(wrapped::call(i.first)); } }; }; template <> struct value_impl { template struct apply { typedef typename meta::value_of< typename meta::prior< typename Iterator::first_type >::type >::type type; }; }; template <> struct begin_impl { template struct apply { typedef reverse_view_iterator type; static type call(Sequence const& s) { return type(s.last); } }; }; template <> struct end_impl { template struct apply { typedef reverse_view_iterator type; static type call(Sequence const& s) { return type(s.first); } }; }; template struct reverse { typedef reverse_view type; }; } template inline reverse_view reverse(Sequence const& view) { return reverse_view(view); } }} #endif