From 43645b376488846794336aaa28c426e9c1eeb34b Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Fri, 25 Sep 2009 00:20:03 +0000 Subject: [PATCH] Fusion: added nview and friends [SVN r56376] --- include/boost/fusion/include/nview.hpp | 12 +++ include/boost/fusion/view/nview.hpp | 15 ++++ .../fusion/view/nview/detail/advance_impl.hpp | 49 ++++++++++++ .../fusion/view/nview/detail/at_impl.hpp | 45 +++++++++++ .../fusion/view/nview/detail/begin_impl.hpp | 49 ++++++++++++ .../fusion/view/nview/detail/deref_impl.hpp | 47 +++++++++++ .../view/nview/detail/distance_impl.hpp | 44 +++++++++++ .../fusion/view/nview/detail/end_impl.hpp | 51 ++++++++++++ .../view/nview/detail/equal_to_impl.hpp | 33 ++++++++ .../fusion/view/nview/detail/next_impl.hpp | 48 +++++++++++ .../fusion/view/nview/detail/nview_impl.hpp | 66 ++++++++++++++++ .../fusion/view/nview/detail/prior_impl.hpp | 48 +++++++++++ .../view/nview/detail/value_at_impl.hpp | 39 +++++++++ .../view/nview/detail/value_of_impl.hpp | 43 ++++++++++ include/boost/fusion/view/nview/nview.hpp | 79 +++++++++++++++++++ .../fusion/view/nview/nview_iterator.hpp | 53 +++++++++++++ 16 files changed, 721 insertions(+) create mode 100644 include/boost/fusion/include/nview.hpp create mode 100644 include/boost/fusion/view/nview.hpp create mode 100644 include/boost/fusion/view/nview/detail/advance_impl.hpp create mode 100644 include/boost/fusion/view/nview/detail/at_impl.hpp create mode 100644 include/boost/fusion/view/nview/detail/begin_impl.hpp create mode 100644 include/boost/fusion/view/nview/detail/deref_impl.hpp create mode 100644 include/boost/fusion/view/nview/detail/distance_impl.hpp create mode 100644 include/boost/fusion/view/nview/detail/end_impl.hpp create mode 100644 include/boost/fusion/view/nview/detail/equal_to_impl.hpp create mode 100644 include/boost/fusion/view/nview/detail/next_impl.hpp create mode 100644 include/boost/fusion/view/nview/detail/nview_impl.hpp create mode 100644 include/boost/fusion/view/nview/detail/prior_impl.hpp create mode 100644 include/boost/fusion/view/nview/detail/value_at_impl.hpp create mode 100644 include/boost/fusion/view/nview/detail/value_of_impl.hpp create mode 100644 include/boost/fusion/view/nview/nview.hpp create mode 100644 include/boost/fusion/view/nview/nview_iterator.hpp diff --git a/include/boost/fusion/include/nview.hpp b/include/boost/fusion/include/nview.hpp new file mode 100644 index 00000000..215329d0 --- /dev/null +++ b/include/boost/fusion/include/nview.hpp @@ -0,0 +1,12 @@ +/*============================================================================= + Copyright (c) 2001-2007 Joel de Guzman + + 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_INCLUDE_NVIEW) +#define FUSION_INCLUDE_NVIEW + +#include + +#endif diff --git a/include/boost/fusion/view/nview.hpp b/include/boost/fusion/view/nview.hpp new file mode 100644 index 00000000..92e2f26a --- /dev/null +++ b/include/boost/fusion/view/nview.hpp @@ -0,0 +1,15 @@ +/*============================================================================= + Copyright (c) 2001-2006 Joel de Guzman + Copyright (c) 2006 Dan Marsden + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_SEP_23_2009_1107PM) +#define FUSION_NVIEW_SEP_23_2009_1107PM + +#include +#include + +#endif diff --git a/include/boost/fusion/view/nview/detail/advance_impl.hpp b/include/boost/fusion/view/nview/detail/advance_impl.hpp new file mode 100644 index 00000000..391bebd8 --- /dev/null +++ b/include/boost/fusion/view/nview/detail/advance_impl.hpp @@ -0,0 +1,49 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_ADVANCE_IMPL_SEP_24_2009_0212PM) +#define BOOST_FUSION_NVIEW_ADVANCE_IMPL_SEP_24_2009_0212PM + +#include +#include + +namespace boost { namespace fusion +{ + struct nview_iterator_tag; + + template + struct nview_iterator; + + namespace extension + { + template + struct advance_impl; + + template<> + struct advance_impl + { + template + struct apply + { + typedef typename Iterator::first_type::iterator_type iterator_type; + typedef typename Iterator::sequence_type sequence_type; + + typedef nview_iterator::type> type; + + static type + call(Iterator const& i) + { + return type(i.seq); + } + }; + }; + } + +}} + +#endif diff --git a/include/boost/fusion/view/nview/detail/at_impl.hpp b/include/boost/fusion/view/nview/detail/at_impl.hpp new file mode 100644 index 00000000..f1f41642 --- /dev/null +++ b/include/boost/fusion/view/nview/detail/at_impl.hpp @@ -0,0 +1,45 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_AT_IMPL_SEP_24_2009_0225PM) +#define BOOST_FUSION_NVIEW_AT_IMPL_SEP_24_2009_0225PM + +#include + +namespace boost { namespace fusion +{ + struct nview_tag; + + namespace extension + { + template + struct at_impl; + + template<> + struct at_impl + { + template + struct apply + { + typedef typename Sequence::sequence_type sequence_type; + typedef typename Sequence::index_type index_type; + + typedef typename result_of::at::type index; + typedef typename result_of::at::type type; + + static type + call(Sequence& seq) + { + return fusion::at(seq.seq); + } + }; + }; + } + +}} + +#endif diff --git a/include/boost/fusion/view/nview/detail/begin_impl.hpp b/include/boost/fusion/view/nview/detail/begin_impl.hpp new file mode 100644 index 00000000..96afe5a8 --- /dev/null +++ b/include/boost/fusion/view/nview/detail/begin_impl.hpp @@ -0,0 +1,49 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_BEGIN_IMPL_SEP_23_2009_1036PM) +#define BOOST_FUSION_NVIEW_BEGIN_IMPL_SEP_23_2009_1036PM + +#include +#include + +namespace boost { namespace fusion +{ + struct nview_tag; + + template + struct nview_iterator; + + namespace extension + { + template + struct begin_impl; + + template<> + struct begin_impl + { + template + struct apply + { + typedef typename Sequence::sequence_type sequence_type; + typedef typename Sequence::index_type index_type; + + typedef nview_iterator::type> type; + + static type call(Sequence& v) + { + return type(v.seq); + } + }; + }; + } + +}} + +#endif + diff --git a/include/boost/fusion/view/nview/detail/deref_impl.hpp b/include/boost/fusion/view/nview/detail/deref_impl.hpp new file mode 100644 index 00000000..329e0842 --- /dev/null +++ b/include/boost/fusion/view/nview/detail/deref_impl.hpp @@ -0,0 +1,47 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_DEREF_IMPL_SEP_24_2009_0818AM) +#define BOOST_FUSION_NVIEW_DEREF_IMPL_SEP_24_2009_0818AM + +#include +#include + +namespace boost { namespace fusion +{ + struct nview_iterator_tag; + + namespace extension + { + template + struct deref_impl; + + template<> + struct deref_impl + { + template + struct apply + { + typedef typename Iterator::first_type first_type; + typedef typename Iterator::sequence_type sequence_type; + + typedef typename result_of::deref::type index; + typedef typename result_of::at::type type; + + static type call(Iterator const& i) + { + return at(i.seq); + } + }; + }; + + } + +}} + +#endif + diff --git a/include/boost/fusion/view/nview/detail/distance_impl.hpp b/include/boost/fusion/view/nview/detail/distance_impl.hpp new file mode 100644 index 00000000..9bc860c5 --- /dev/null +++ b/include/boost/fusion/view/nview/detail/distance_impl.hpp @@ -0,0 +1,44 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_DISTANCE_IMPL_SEP_23_2009_0328PM) +#define BOOST_FUSION_NVIEW_DISTANCE_IMPL_SEP_23_2009_0328PM + +#include + +namespace boost { namespace fusion +{ + struct nview_iterator_tag; + + namespace extension + { + template + struct distance_impl; + + template<> + struct distance_impl + { + template + struct apply + : result_of::distance + { + typedef typename result_of::distance< + typename First::first_type, typename Last::first_type + >::type type; + + static type + call(First const& first, Last const& last) + { + return type(); + } + }; + }; + } + +}} + +#endif diff --git a/include/boost/fusion/view/nview/detail/end_impl.hpp b/include/boost/fusion/view/nview/detail/end_impl.hpp new file mode 100644 index 00000000..d7e87391 --- /dev/null +++ b/include/boost/fusion/view/nview/detail/end_impl.hpp @@ -0,0 +1,51 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_END_IMPL_SEP_24_2009_0140PM) +#define BOOST_FUSION_NVIEW_END_IMPL_SEP_24_2009_0140PM + +#include +#include + +namespace boost { namespace fusion +{ + struct nview_tag; + + template + struct nview_iterator; + + namespace extension + { + template + struct end_impl; + + // Unary Version + template <> + struct end_impl + { + template + struct apply + { + typedef typename Sequence::sequence_type sequence_type; + typedef typename Sequence::index_type index_type; + + typedef nview_iterator::type> type; + + static type call(Sequence& v) + { + return type(v.seq); + } + }; + }; + } + +}} + +#endif + + diff --git a/include/boost/fusion/view/nview/detail/equal_to_impl.hpp b/include/boost/fusion/view/nview/detail/equal_to_impl.hpp new file mode 100644 index 00000000..517204b0 --- /dev/null +++ b/include/boost/fusion/view/nview/detail/equal_to_impl.hpp @@ -0,0 +1,33 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_ITERATOR_SEP_24_2009_0329PM) +#define BOOST_FUSION_NVIEW_ITERATOR_SEP_24_2009_0329PM + +#include + +namespace boost { namespace fusion +{ + struct nview_iterator_tag; + + namespace extension + { + template + struct equal_to_impl; + + template<> + struct equal_to_impl + { + template + struct apply + : result_of::equal_to + {}; + }; + } +}} + +#endif diff --git a/include/boost/fusion/view/nview/detail/next_impl.hpp b/include/boost/fusion/view/nview/detail/next_impl.hpp new file mode 100644 index 00000000..01cccf2b --- /dev/null +++ b/include/boost/fusion/view/nview/detail/next_impl.hpp @@ -0,0 +1,48 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_NEXT_IMPL_SEP_24_2009_0116PM) +#define BOOST_FUSION_NVIEW_NEXT_IMPL_SEP_24_2009_0116PM + +#include + +namespace boost { namespace fusion +{ + struct nview_iterator_tag; + + template + struct nview_iterator; + + namespace extension + { + template + struct next_impl; + + template <> + struct next_impl + { + template + struct apply + { + typedef typename Iterator::first_type::iterator_type first_type; + typedef typename Iterator::sequence_type sequence_type; + + typedef nview_iterator::type> type; + + static type + call(Iterator const& i) + { + return type(i.seq); + } + }; + }; + } + +}} + +#endif diff --git a/include/boost/fusion/view/nview/detail/nview_impl.hpp b/include/boost/fusion/view/nview/detail/nview_impl.hpp new file mode 100644 index 00000000..44263df2 --- /dev/null +++ b/include/boost/fusion/view/nview/detail/nview_impl.hpp @@ -0,0 +1,66 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_PP_IS_ITERATING + +#if !defined(BOOST_FUSION_NVIEW_IMPL_SEP_23_2009_1017PM) +#define BOOST_FUSION_NVIEW_IMPL_SEP_23_2009_1017PM + +#include +#include +#include +#include +#include +#include + +#define BOOST_PP_ITERATION_PARAMS_1 \ + (3, (1, FUSION_MAX_VECTOR_SIZE, \ + "boost/fusion/view/nview/detail/nview_impl.hpp")) \ + /**/ + +#include BOOST_PP_ITERATE() + +/////////////////////////////////////////////////////////////////////////////// +namespace boost { namespace fusion { namespace result_of +{ + template + struct as_nview + { + typedef mpl::vector_c< + int, BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, I) + > index_type; + + typedef nview type; + }; + +}}} + +#endif + +/////////////////////////////////////////////////////////////////////////////// +// Preprocessor vertical repetition code +/////////////////////////////////////////////////////////////////////////////// +#else // defined(BOOST_PP_IS_ITERATING) + +#define N BOOST_PP_ITERATION() + +namespace boost { namespace fusion +{ + template + inline nview > + as_nview(Sequence& s) + { + typedef mpl::vector_c index_type; + return nview(s); + } + +}} + +#undef N + +#endif diff --git a/include/boost/fusion/view/nview/detail/prior_impl.hpp b/include/boost/fusion/view/nview/detail/prior_impl.hpp new file mode 100644 index 00000000..079a9ca6 --- /dev/null +++ b/include/boost/fusion/view/nview/detail/prior_impl.hpp @@ -0,0 +1,48 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_PRIOR_IMPL_SEP_24_2009_0142PM) +#define BOOST_FUSION_NVIEW_PRIOR_IMPL_SEP_24_2009_0142PM + +#include + +namespace boost { namespace fusion +{ + struct nview_iterator_tag; + + template + struct nview_iterator; + + namespace extension + { + template + struct prior_impl; + + template <> + struct prior_impl + { + template + struct apply + { + typedef typename Iterator::first_type::iterator_type first_type; + typedef typename Iterator::sequence_type sequence_type; + + typedef nview_iterator::type> type; + + static type + call(Iterator const& i) + { + return type(i.seq); + } + }; + }; + } + +}} + +#endif diff --git a/include/boost/fusion/view/nview/detail/value_at_impl.hpp b/include/boost/fusion/view/nview/detail/value_at_impl.hpp new file mode 100644 index 00000000..145bb629 --- /dev/null +++ b/include/boost/fusion/view/nview/detail/value_at_impl.hpp @@ -0,0 +1,39 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_VALUE_AT_IMPL_SEP_24_2009_0234PM) +#define BOOST_FUSION_NVIEW_VALUE_AT_IMPL_SEP_24_2009_0234PM + +#include + +namespace boost { namespace fusion +{ + struct nview_tag; + + namespace extension + { + template + struct value_at_impl; + + template<> + struct value_at_impl + { + template + struct apply + { + typedef typename Sequence::sequence_type sequence_type; + typedef typename Sequence::index_type index_type; + + typedef typename result_of::at::type index; + typedef typename result_of::at::type type; + }; + }; + } + +}} + +#endif diff --git a/include/boost/fusion/view/nview/detail/value_of_impl.hpp b/include/boost/fusion/view/nview/detail/value_of_impl.hpp new file mode 100644 index 00000000..7af0b1fd --- /dev/null +++ b/include/boost/fusion/view/nview/detail/value_of_impl.hpp @@ -0,0 +1,43 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_VALUE_OF_PRIOR_IMPL_SEP_24_2009_0158PM) +#define BOOST_FUSION_VALUE_OF_PRIOR_IMPL_SEP_24_2009_0158PM + +#include +#include + +namespace boost { namespace fusion +{ + struct nview_iterator_tag; + + template + struct nview_iterator; + + namespace extension + { + template + struct value_of_impl; + + template <> + struct value_of_impl + { + template + struct apply + { + typedef typename Iterator::first_type first_type; + typedef typename Iterator::sequence_type sequence_type; + + typedef typename result_of::deref::type index; + typedef typename result_of::at::type type; + }; + }; + } + +}} + +#endif diff --git a/include/boost/fusion/view/nview/nview.hpp b/include/boost/fusion/view/nview/nview.hpp new file mode 100644 index 00000000..f3011834 --- /dev/null +++ b/include/boost/fusion/view/nview/nview.hpp @@ -0,0 +1,79 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_SEP_23_2009_0948PM) +#define BOOST_FUSION_NVIEW_SEP_23_2009_0948PM + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +namespace boost { namespace fusion +{ + namespace detail + { + struct addref + { + template + struct result; + + template + struct result : boost::add_reference {}; + + template + typename boost::result_of::type + operator()(T& x) const + { + return x; + } + }; + } + + struct nview_tag; + struct random_access_traversal_tag; + struct fusion_sequence_tag; + + template + struct nview + : sequence_base > + { + typedef nview_tag fusion_tag; + typedef fusion_sequence_tag tag; // this gets picked up by MPL + typedef random_access_traversal_tag category; + + typedef mpl::true_ is_view; + typedef Indicies index_type; + typedef typename mpl::size::type size; + + typedef transform_view transform_view_type; + typedef typename result_of::as_vector::type + sequence_type; + + explicit nview(Sequence& val) + : seq(as_vector(transform_view_type(val, detail::addref()))) + {} + + sequence_type seq; + }; + +}} + +// define the nview() generator functions +#include + +#endif + + diff --git a/include/boost/fusion/view/nview/nview_iterator.hpp b/include/boost/fusion/view/nview/nview_iterator.hpp new file mode 100644 index 00000000..12580749 --- /dev/null +++ b/include/boost/fusion/view/nview/nview_iterator.hpp @@ -0,0 +1,53 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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_NVIEW_ITERATOR_SEP_23_2009_0948PM) +#define BOOST_FUSION_NVIEW_ITERATOR_SEP_23_2009_0948PM + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost { namespace fusion +{ + struct nview_iterator_tag; + struct random_access_traversal_tag; + + template + struct nview_iterator + : iterator_base > + { + typedef nview_iterator_tag fusion_tag; + typedef random_access_traversal_tag category; + + typedef Sequence sequence_type; + typedef mpl_iterator first_type; + + explicit nview_iterator(Sequence& seq) + : seq(seq) {} + + Sequence& seq; + }; + +}} + +#endif + +