From fd64eec23d5952bca457ea52f2ccd61eda166138 Mon Sep 17 00:00:00 2001 From: Tobias Schwinger Date: Mon, 19 Mar 2007 21:03:35 +0000 Subject: [PATCH] adds repetitive_view [SVN r37233] --- .../fusion/sequence/view/repetitive_view.hpp | 15 ++++ .../repetitive_view/detail/begin_impl.hpp | 49 ++++++++++ .../repetitive_view/detail/deref_impl.hpp | 44 +++++++++ .../view/repetitive_view/detail/end_impl.hpp | 49 ++++++++++ .../view/repetitive_view/detail/next_impl.hpp | 90 +++++++++++++++++++ .../repetitive_view/detail/value_of_impl.hpp | 34 +++++++ .../view/repetitive_view/repetitive_view.hpp | 48 ++++++++++ .../repetitive_view/repetitive_view_fwd.hpp | 19 ++++ .../repetitive_view_iterator.hpp | 50 +++++++++++ 9 files changed, 398 insertions(+) create mode 100644 include/boost/fusion/sequence/view/repetitive_view.hpp create mode 100644 include/boost/fusion/sequence/view/repetitive_view/detail/begin_impl.hpp create mode 100644 include/boost/fusion/sequence/view/repetitive_view/detail/deref_impl.hpp create mode 100644 include/boost/fusion/sequence/view/repetitive_view/detail/end_impl.hpp create mode 100644 include/boost/fusion/sequence/view/repetitive_view/detail/next_impl.hpp create mode 100644 include/boost/fusion/sequence/view/repetitive_view/detail/value_of_impl.hpp create mode 100644 include/boost/fusion/sequence/view/repetitive_view/repetitive_view.hpp create mode 100644 include/boost/fusion/sequence/view/repetitive_view/repetitive_view_fwd.hpp create mode 100644 include/boost/fusion/sequence/view/repetitive_view/repetitive_view_iterator.hpp diff --git a/include/boost/fusion/sequence/view/repetitive_view.hpp b/include/boost/fusion/sequence/view/repetitive_view.hpp new file mode 100644 index 00000000..8940174b --- /dev/null +++ b/include/boost/fusion/sequence/view/repetitive_view.hpp @@ -0,0 +1,15 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + 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_REPETITIVE_VIEW_HPP_INCLUDED) +#define BOOST_FUSION_REPETITIVE_VIEW_HPP_INCLUDED + +#include +#include + +#endif + diff --git a/include/boost/fusion/sequence/view/repetitive_view/detail/begin_impl.hpp b/include/boost/fusion/sequence/view/repetitive_view/detail/begin_impl.hpp new file mode 100644 index 00000000..b5c4c29a --- /dev/null +++ b/include/boost/fusion/sequence/view/repetitive_view/detail/begin_impl.hpp @@ -0,0 +1,49 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + 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_REPETITIVE_VIEW_BEGIN_IMPL_HPP_INCLUDED) +#define BOOST_FUSION_REPETITIVE_VIEW_BEGIN_IMPL_HPP_INCLUDED + +#include +#include + +namespace boost { namespace fusion +{ + struct repetitive_view_tag; + + template + struct repetitive_view_iterator; + + namespace extension + { + template + struct begin_impl; + + template<> + struct begin_impl + { + template + struct apply + { + typedef typename View::sequence_type sequence_type; + + typedef repetitive_view_iterator::type > type; + + static type call(View const& v) + { + return type(v.seq); + } + }; + }; + + } + +}} + +#endif + diff --git a/include/boost/fusion/sequence/view/repetitive_view/detail/deref_impl.hpp b/include/boost/fusion/sequence/view/repetitive_view/detail/deref_impl.hpp new file mode 100644 index 00000000..2c0caf80 --- /dev/null +++ b/include/boost/fusion/sequence/view/repetitive_view/detail/deref_impl.hpp @@ -0,0 +1,44 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + 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_REPETITIVE_VIEW_DEREF_IMPL_HPP_INCLUDED) +#define BOOST_FUSION_REPETITIVE_VIEW_DEREF_IMPL_HPP_INCLUDED + +#include + +namespace boost { namespace fusion +{ + struct repetitive_view_iterator_tag; + + namespace extension + { + template + struct deref_impl; + + template<> + struct deref_impl + { + template + struct apply + { + typedef typename + result_of::deref::type + type; + + static type call(Iterator const& i) + { + return *i.pos; + } + }; + }; + + } + +}} + +#endif + diff --git a/include/boost/fusion/sequence/view/repetitive_view/detail/end_impl.hpp b/include/boost/fusion/sequence/view/repetitive_view/detail/end_impl.hpp new file mode 100644 index 00000000..00ac0874 --- /dev/null +++ b/include/boost/fusion/sequence/view/repetitive_view/detail/end_impl.hpp @@ -0,0 +1,49 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + 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_REPETITIVE_VIEW_END_IMPL_HPP_INCLUDED) +#define BOOST_FUSION_REPETITIVE_VIEW_END_IMPL_HPP_INCLUDED + +#include +#include + +namespace boost { namespace fusion +{ + struct repetitive_view_tag; + + template + struct repetitive_view_iterator; + + namespace extension + { + template + struct end_impl; + + template<> + struct end_impl + { + template + struct apply + { + typedef typename View::sequence_type sequence_type; + + typedef repetitive_view_iterator::type > type; + + static type call(View const& v) + { + return type(v.seq,end(v.seq)); + } + }; + }; + + } + +}} + +#endif + diff --git a/include/boost/fusion/sequence/view/repetitive_view/detail/next_impl.hpp b/include/boost/fusion/sequence/view/repetitive_view/detail/next_impl.hpp new file mode 100644 index 00000000..b629cb01 --- /dev/null +++ b/include/boost/fusion/sequence/view/repetitive_view/detail/next_impl.hpp @@ -0,0 +1,90 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + 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_REPETITIVE_VIEW_NEXT_IMPL_HPP_INCLUDED) +#define BOOST_FUSION_REPETITIVE_VIEW_NEXT_IMPL_HPP_INCLUDED + +#include +#include + +namespace boost { namespace fusion +{ + struct repetitive_view_iterator_tag; + + template + struct repetitive_view_iterator; + + namespace extension + { + template + struct next_impl; + + template <> + struct next_impl + { + template::type>::value > + struct apply_nonempty // + { + // advanvce to next position + + typedef repetitive_view_iterator< + typename Iterator::sequence_type, + typename result_of::next::type + > + type; + + static type call(Iterator const& i) + { + return type(i.seq, next(i.pos)); + } + }; + template + struct apply_nonempty + { + // reset to beginning + + typedef repetitive_view_iterator< + typename Iterator::sequence_type, + typename Iterator::first_type + > + type; + + static type call(Iterator const& i) + { + return type(i.seq); + } + }; + + template ::value > + struct apply // + : apply_nonempty + { }; + + template + struct apply + { + // eps^n = eps + + typedef Iterator type; + + static type call(Iterator const& i) + { + return type(i); + } + }; + }; + } +}} + +#endif + diff --git a/include/boost/fusion/sequence/view/repetitive_view/detail/value_of_impl.hpp b/include/boost/fusion/sequence/view/repetitive_view/detail/value_of_impl.hpp new file mode 100644 index 00000000..bf5f2f06 --- /dev/null +++ b/include/boost/fusion/sequence/view/repetitive_view/detail/value_of_impl.hpp @@ -0,0 +1,34 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + 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_REPETITIVE_VIEW_VALUE_OF_IMPL_HPP_INCLUDED) +#define BOOST_FUSION_REPETITIVE_VIEW_VALUE_OF_IMPL_HPP_INCLUDED + +#include + +namespace boost { namespace fusion +{ + struct repetitive_view_iterator_tag; + + namespace extension + { + template + struct value_of_impl; + + template<> + struct value_of_impl + { + template + struct apply + : result_of::value_of + { }; + }; + } +}} + +#endif + diff --git a/include/boost/fusion/sequence/view/repetitive_view/repetitive_view.hpp b/include/boost/fusion/sequence/view/repetitive_view/repetitive_view.hpp new file mode 100644 index 00000000..2e06fd80 --- /dev/null +++ b/include/boost/fusion/sequence/view/repetitive_view/repetitive_view.hpp @@ -0,0 +1,48 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + 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_REPETITIVE_REPETITIVE_VIEW_VIEW_HPP_INCLUDED) +#define BOOST_FUSION_REPETITIVE_VIEW_REPETITIVE_VIEW_HPP_INCLUDED + +#include +#include + +#include +#include + +#include +#include + + +namespace boost { namespace fusion +{ + struct repetitive_view_tag; + struct fusion_sequence_tag; + + template struct repetitive_view + : sequence_base< repetitive_view > + { + typedef repetitive_view_tag fusion_tag; + typedef fusion_sequence_tag tag; // this gets picked up by MPL + typedef mpl::true_ is_view; + + typedef single_pass_traversal_tag category; + + typedef typename boost::remove_reference::type sequence_type; + typedef typename + mpl::if_, Sequence, sequence_type&>::type + stored_seq_type; + + repetitive_view(Sequence& seq) + : seq(seq) {} + + stored_seq_type seq; + }; + +}} + +#endif diff --git a/include/boost/fusion/sequence/view/repetitive_view/repetitive_view_fwd.hpp b/include/boost/fusion/sequence/view/repetitive_view/repetitive_view_fwd.hpp new file mode 100644 index 00000000..24e146c0 --- /dev/null +++ b/include/boost/fusion/sequence/view/repetitive_view/repetitive_view_fwd.hpp @@ -0,0 +1,19 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + 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_REPETITIVE_VIEW_FWD_HPP_INCLUDED) +#define BOOST_FUSION_REPETITIVE_VIEW_FWD_HPP_INCLUDED + +namespace boost { namespace fusion +{ + struct repetitive_view_tag; + + template struct repetitive_view; +}} + +#endif + diff --git a/include/boost/fusion/sequence/view/repetitive_view/repetitive_view_iterator.hpp b/include/boost/fusion/sequence/view/repetitive_view/repetitive_view_iterator.hpp new file mode 100644 index 00000000..6b2a9a5e --- /dev/null +++ b/include/boost/fusion/sequence/view/repetitive_view/repetitive_view_iterator.hpp @@ -0,0 +1,50 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + 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_REPETITIVE_VIEW_ITERATOR_HPP_INCLUDED) +#define BOOST_FUSION_REPETITIVE_VIEW_HPP_ITERATOR_INCLUDED + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost { namespace fusion +{ + struct repetitive_view_iterator_tag; + + template::type> + struct repetitive_view_iterator + : iterator_base< repetitive_view_iterator > + { + typedef repetitive_view_iterator_tag fusion_tag; + + typedef Sequence sequence_type; + typedef typename convert_iterator::type pos_type; + typedef typename convert_iterator::type>::type first_type; + typedef typename convert_iterator::type>::type end_type; + typedef single_pass_traversal_tag category; + + explicit repetitive_view_iterator(Sequence& seq) + : seq(seq), pos(begin(seq)) {} + + repetitive_view_iterator(Sequence& seq, pos_type const& pos) + : seq(seq), pos(pos) {} + + Sequence& seq; + pos_type pos; + + }; +}} + +#endif +