Index: boost/fusion/view/single_view/single_view.hpp =================================================================== --- boost/fusion/view/single_view/single_view.hpp (revision 72924) +++ boost/fusion/view/single_view/single_view.hpp (working copy) @@ -1,18 +1,22 @@ /*============================================================================= Copyright (c) 2001-2006 Joel de Guzman + 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_SINGLE_VIEW_05052005_0335) -#define FUSION_SINGLE_VIEW_05052005_0335 +#if !defined(BOOST_FUSION_SINGLE_VIEW_05052005_0335) +#define BOOST_FUSION_SINGLE_VIEW_05052005_0335 #include #include #include #include +#include #include #include +#include +#include #include #include #include @@ -25,7 +29,7 @@ namespace boost { namespace fusion { struct single_view_tag; - struct forward_traversal_tag; + struct random_access_traversal_tag; struct fusion_sequence_tag; template @@ -33,7 +37,7 @@ { typedef single_view_tag fusion_tag; typedef fusion_sequence_tag tag; // this gets picked up by MPL - typedef forward_traversal_tag category; + typedef random_access_traversal_tag category; typedef mpl::true_ is_view; typedef mpl::int_<1> size; typedef T value_type; Index: boost/fusion/view/single_view/detail/equal_to_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/equal_to_impl.hpp (revision 0) +++ boost/fusion/view/single_view/detail/equal_to_impl.hpp (revision 0) @@ -0,0 +1,39 @@ +/*============================================================================= + 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_SINGLE_VIEW_ITERATOR_JUL_07_2011_1348PM) +#define BOOST_FUSION_SINGLE_VIEW_ITERATOR_JUL_07_2011_1348PM + +#include +#include +#include +#include + +namespace boost { namespace fusion +{ + struct single_view_iterator_tag; + + namespace extension + { + template + struct equal_to_impl; + + template<> + struct equal_to_impl + { + template + struct apply + : mpl::equal_to + { + BOOST_MPL_ASSERT((is_same::type, + typename add_const::type>)); + }; + }; + } +}} + +#endif Index: boost/fusion/view/single_view/detail/distance_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/distance_impl.hpp (revision 0) +++ boost/fusion/view/single_view/detail/distance_impl.hpp (revision 0) @@ -0,0 +1,43 @@ +/*============================================================================= + 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_SINGLE_VIEW_DISTANCE_IMPL_JUL_07_2011_1348PM) +#define BOOST_FUSION_SINGLE_VIEW_DISTANCE_IMPL_JUL_07_2011_1348PM + +#include + +namespace boost { namespace fusion +{ + struct single_view_iterator_tag; + + namespace extension + { + template + struct distance_impl; + + template<> + struct distance_impl + { + template + struct apply + : mpl::minus + { + typedef typename mpl::minus::type type; + + static type + call(First const& /*first*/, Last const& /*last*/) + { + return type(); + } + }; + }; + } + +}} + +#endif Index: boost/fusion/view/single_view/detail/size_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/size_impl.hpp (revision 0) +++ boost/fusion/view/single_view/detail/size_impl.hpp (revision 0) @@ -0,0 +1,33 @@ +/*============================================================================= + 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_SINGLE_VIEW_SIZE_IMPL_JUL_07_2011_1348PM) +#define FUSION_SINGLE_VIEW_SIZE_IMPL_JUL_07_2011_1348PM + +namespace boost { namespace fusion +{ + struct single_view_tag; + + namespace extension + { + template + struct size_impl; + + template <> + struct size_impl + { + template + struct apply + { + typedef mpl::int_<1> type; + }; + }; + } +}} + +#endif + + Index: boost/fusion/view/single_view/detail/prior_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/prior_impl.hpp (revision 0) +++ boost/fusion/view/single_view/detail/prior_impl.hpp (revision 0) @@ -0,0 +1,46 @@ +/*============================================================================= + 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_SINGLE_VIEW_PRIOR_IMPL_JUL_07_2011_1348PM) +#define BOOST_FUSION_SINGLE_VIEW_PRIOR_IMPL_JUL_07_2011_1348PM + +#include + +namespace boost { namespace fusion +{ + struct single_view_iterator_tag; + + template + struct single_view_iterator; + + namespace extension + { + template + struct prior_impl; + + template <> + struct prior_impl + { + template + struct apply + { + typedef single_view_iterator< + typename Iterator::single_view_type, + typename mpl::prior::type> + type; + + static type + call(Iterator const& i) + { + return type(i.view); + } + }; + }; + } + +}} + +#endif Index: boost/fusion/view/single_view/detail/next_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/next_impl.hpp (revision 72924) +++ boost/fusion/view/single_view/detail/next_impl.hpp (working copy) @@ -1,20 +1,20 @@ /*============================================================================= Copyright (c) 2001-2006 Joel de Guzman + 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_NEXT_IMPL_05052005_0331) -#define FUSION_NEXT_IMPL_05052005_0331 +#if !defined(BOOST_FUSION_SINGLE_VIEW_NEXT_IMPL_05052005_0331) +#define BOOST_FUSION_SINGLE_VIEW_NEXT_IMPL_05052005_0331 +#include + namespace boost { namespace fusion { struct single_view_iterator_tag; - template - struct single_view_iterator_end; - - template + template struct single_view_iterator; namespace extension @@ -28,14 +28,15 @@ template struct apply { - typedef single_view_iterator_end< - typename Iterator::single_view_type> + typedef single_view_iterator< + typename Iterator::single_view_type, + typename mpl::next::type> type; static type - call(Iterator) + call(Iterator const& i) { - return type(); + return type(i.view); } }; }; Index: boost/fusion/view/single_view/detail/value_of_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/value_of_impl.hpp (revision 72924) +++ boost/fusion/view/single_view/detail/value_of_impl.hpp (working copy) @@ -1,12 +1,17 @@ /*============================================================================= Copyright (c) 2001-2006 Joel de Guzman + 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_VALUE_IMPL_05052005_0324) -#define FUSION_VALUE_IMPL_05052005_0324 +#if !defined(BOOST_FUSION_SINGLE_VIEW_VALUE_OF_IMPL_05052005_0324) +#define BOOST_FUSION_SINGLE_VIEW_VALUE_OF_IMPL_05052005_0324 +#include +#include +#include + namespace boost { namespace fusion { struct single_view_iterator_tag; @@ -22,8 +27,8 @@ template struct apply { - typedef typename Iterator::single_view_type single_view_type; - typedef typename single_view_type::value_type type; + BOOST_MPL_ASSERT((mpl::equal_to >)); + typedef typename Iterator::value_type type; }; }; } Index: boost/fusion/view/single_view/detail/value_at_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/value_at_impl.hpp (revision 0) +++ boost/fusion/view/single_view/detail/value_at_impl.hpp (revision 0) @@ -0,0 +1,39 @@ +/*============================================================================= + 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_SINGLE_VIEW_VALUE_AT_IMPL_JUL_07_2011_1348PM) +#define BOOST_FUSION_SINGLE_VIEW_VALUE_AT_IMPL_JUL_07_2011_1348PM + +#include +#include +#include +#include + +namespace boost { namespace fusion +{ + struct single_view_tag; + + namespace extension + { + template + struct value_at_impl; + + template<> + struct value_at_impl + { + template + struct apply + { + BOOST_MPL_ASSERT((mpl::equal_to >)); + typedef typename Sequence::value_type type; + }; + }; + } + +}} + +#endif Index: boost/fusion/view/single_view/detail/advance_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/advance_impl.hpp (revision 0) +++ boost/fusion/view/single_view/detail/advance_impl.hpp (revision 0) @@ -0,0 +1,47 @@ +/*============================================================================= + 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_SINGLE_VIEW_ADVANCE_IMPL_JUL_07_2011_1348PM) +#define BOOST_FUSION_SINGLE_VIEW_ADVANCE_IMPL_JUL_07_2011_1348PM + +#include + +namespace boost { namespace fusion +{ + struct single_view_iterator_tag; + + template + struct single_view_iterator; + + namespace extension + { + template + struct advance_impl; + + template<> + struct advance_impl + { + template + struct apply + { + typedef single_view_iterator< + typename Iterator::single_view_type, + typename mpl::plus::type> + type; + + static type + call(Iterator const& i) + { + return type(i.view); + } + }; + }; + } + +}} + +#endif Index: boost/fusion/view/single_view/detail/begin_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/begin_impl.hpp (revision 72924) +++ boost/fusion/view/single_view/detail/begin_impl.hpp (working copy) @@ -1,17 +1,20 @@ /*============================================================================= Copyright (c) 2001-2006 Joel de Guzman + 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_BEGIN_IMPL_05052005_0305) -#define FUSION_BEGIN_IMPL_05052005_0305 +#if !defined(BOOST_FUSION_SINGLE_VIEW_BEGIN_IMPL_05052005_0305) +#define BOOST_FUSION_SINGLE_VIEW_BEGIN_IMPL_05052005_0305 +#include + namespace boost { namespace fusion { struct single_view_tag; - template + template struct single_view_iterator; namespace extension @@ -25,12 +28,12 @@ template struct apply { - typedef single_view_iterator type; + typedef single_view_iterator > type; static type - call(Sequence& s) + call(Sequence& seq) { - return type(s); + return type(seq); } }; }; Index: boost/fusion/view/single_view/detail/at_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/at_impl.hpp (revision 0) +++ boost/fusion/view/single_view/detail/at_impl.hpp (revision 0) @@ -0,0 +1,44 @@ +/*============================================================================= + 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_SINGLE_VIEW_AT_IMPL_JUL_07_2011_1348PM) +#define BOOST_FUSION_SINGLE_VIEW_AT_IMPL_JUL_07_2011_1348PM + +#include +#include +#include + +namespace boost { namespace fusion +{ + struct single_view_tag; + + namespace extension + { + template + struct at_impl; + + template<> + struct at_impl + { + template + struct apply + { + BOOST_MPL_ASSERT((mpl::equal_to >)); + typedef typename Sequence::value_type type; + + static type + call(Sequence& seq) + { + return seq.val; + } + }; + }; + } + +}} + +#endif Index: boost/fusion/view/single_view/detail/deref_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/deref_impl.hpp (revision 72924) +++ boost/fusion/view/single_view/detail/deref_impl.hpp (working copy) @@ -1,15 +1,16 @@ /*============================================================================= Copyright (c) 2001-2006 Joel de Guzman + 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_DEREF_IMPL_05052005_0258) -#define FUSION_DEREF_IMPL_05052005_0258 +#if !defined(BOOST_FUSION_SINGLE_VIEW_DEREF_IMPL_05052005_0258) +#define BOOST_FUSION_SINGLE_VIEW_DEREF_IMPL_05052005_0258 -#include -#include -#include +#include +#include +#include namespace boost { namespace fusion { @@ -26,12 +27,13 @@ template struct apply { + BOOST_MPL_ASSERT((mpl::equal_to >)); typedef typename Iterator::value_type type; static type call(Iterator const& i) { - return i.val; + return i.view.val; } }; }; Index: boost/fusion/view/single_view/detail/end_impl.hpp =================================================================== --- boost/fusion/view/single_view/detail/end_impl.hpp (revision 72924) +++ boost/fusion/view/single_view/detail/end_impl.hpp (working copy) @@ -1,18 +1,21 @@ /*============================================================================= Copyright (c) 2001-2006 Joel de Guzman + 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_END_IMPL_05052005_0332) -#define FUSION_END_IMPL_05052005_0332 +#if !defined(BOOST_FUSION_SINGLE_VIEW_END_IMPL_05052005_0332) +#define BOOST_FUSION_SINGLE_VIEW_END_IMPL_05052005_0332 +#include + namespace boost { namespace fusion { struct single_view_tag; - template - struct single_view_iterator_end; + template + struct single_view_iterator; namespace extension { @@ -25,12 +28,12 @@ template struct apply { - typedef single_view_iterator_end type; + typedef single_view_iterator > type; static type - call(Sequence&) + call(Sequence& seq) { - return type(); + return type(seq); } }; }; Index: boost/fusion/view/single_view/single_view_iterator.hpp =================================================================== --- boost/fusion/view/single_view/single_view_iterator.hpp (revision 72924) +++ boost/fusion/view/single_view/single_view_iterator.hpp (working copy) @@ -1,16 +1,21 @@ /*============================================================================= Copyright (c) 2001-2006 Joel de Guzman + 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_SINGLE_VIEW_ITERATOR_05052005_0340) -#define FUSION_SINGLE_VIEW_ITERATOR_05052005_0340 +#if !defined(BOOST_FUSION_SINGLE_VIEW_ITERATOR_05052005_0340) +#define BOOST_FUSION_SINGLE_VIEW_ITERATOR_05052005_0340 #include #include #include #include +#include +#include +#include +#include #include #include @@ -22,29 +27,25 @@ namespace boost { namespace fusion { struct single_view_iterator_tag; - struct forward_traversal_tag; + struct random_access_traversal_tag; - template - struct single_view_iterator_end - : iterator_base > - { - typedef single_view_iterator_tag fusion_tag; - typedef forward_traversal_tag category; - }; - - template + template struct single_view_iterator - : iterator_base > + : iterator_base > { typedef single_view_iterator_tag fusion_tag; - typedef forward_traversal_tag category; + typedef random_access_traversal_tag category; typedef typename SingleView::value_type value_type; + typedef Pos position; typedef SingleView single_view_type; - explicit single_view_iterator(single_view_type const& view) - : val(view.val) {} + explicit single_view_iterator(single_view_type& in_view) + : view(in_view) {} - value_type val; + SingleView& view; + + private: + single_view_iterator& operator=(single_view_iterator const&); }; }} Index: libs/fusion/doc/iterator.qbk =================================================================== --- libs/fusion/doc/iterator.qbk (revision 72924) +++ libs/fusion/doc/iterator.qbk (working copy) @@ -160,6 +160,7 @@ * __std_pair__ iterator * __boost_array__ iterator * __vector__ iterator +* __single_view__ iterator * __iterator_range__ (where adapted sequence is a __bidirectional_sequence__) * __transform_view__ (where adapted sequence is a __bidirectional_sequence__) * __reverse_view__ @@ -206,6 +207,7 @@ * __vector__ iterator * __std_pair__ iterator * __boost_array__ iterator +* __single_view__ iterator * __iterator_range__ iterator (where adapted sequence is a __random_access_sequence__) * __transform_view__ iterator (where adapted sequence is a __random_access_sequence__) * __reverse_view__ iterator (where adapted sequence is a __random_access_sequence__) Index: libs/fusion/doc/sequence.qbk =================================================================== --- libs/fusion/doc/sequence.qbk (revision 72924) +++ libs/fusion/doc/sequence.qbk (working copy) @@ -189,6 +189,7 @@ * __boost_array__ * __vector__ * __reverse_view__ +* __single_view__ * __iterator_range__ (where adapted sequence is a Bidirectional Sequence) * __transform_view__ (where adapted sequence is a Bidirectional Sequence) * __zip_view__ (where adapted sequences are models of Bidirectional Sequence) @@ -264,6 +265,7 @@ * __boost_array__ * __vector__ * __reverse_view__ +* __single_view__ * __iterator_range__ (where adapted sequence is a Random Access Sequence) * __transform_view__ (where adapted sequence is a Random Access Sequence) * __zip_view__ (where adapted sequences are models of Random Access Sequence) Index: libs/fusion/doc/view.qbk =================================================================== --- libs/fusion/doc/view.qbk (revision 72924) +++ libs/fusion/doc/view.qbk (working copy) @@ -43,7 +43,7 @@ [heading Model of] -* __forward_sequence__ +* __random_access_sequence__ [variablelist Notation [[`S`] [A `single_view` type]] @@ -54,7 +54,7 @@ [heading Expression Semantics] Semantics of an expression is defined only where it differs from, or is not -defined in __forward_sequence__. +defined in __random_access_sequence__. [table [[Expression] [Semantics]] Index: libs/fusion/test/sequence/single_view.cpp =================================================================== --- libs/fusion/test/sequence/single_view.cpp (revision 72924) +++ libs/fusion/test/sequence/single_view.cpp (working copy) @@ -1,5 +1,6 @@ /*============================================================================= Copyright (c) 2001-2006 Joel de Guzman + 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) @@ -7,8 +8,22 @@ #include #include #include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include struct X {}; @@ -40,7 +55,28 @@ #endif std::cout << view1 << std::endl; BOOST_TEST(*begin(view1) == 3); + BOOST_TEST(at >(view1) == 3); BOOST_TEST(view1.val == 3); + BOOST_TEST(3 == front(view1)); + BOOST_TEST(3 == back(view1)); + BOOST_TEST(!empty(view1)); + BOOST_TEST(next(begin(view1)) == end(view1)); + BOOST_TEST(prior(end(view1)) == begin(view1)); + BOOST_TEST(!(next(begin(view1)) != end(view1))); + BOOST_TEST(!(prior(end(view1)) != begin(view1))); + BOOST_TEST(1 == distance(begin(view1), end(view1))); + BOOST_TEST(0 == distance(end(view1), end(view1))); + BOOST_TEST(0 == distance(begin(view1), begin(view1))); + BOOST_TEST(end(view1) == advance >(begin(view1))); + BOOST_TEST(begin(view1) == advance >(begin(view1))); + BOOST_TEST(end(view1) == advance >(end(view1))); + BOOST_TEST(begin(view1) == advance >(end(view1))); + BOOST_TEST(end(view1) == advance_c<1>(begin(view1))); + BOOST_TEST(begin(view1) == advance_c<0>(begin(view1))); + BOOST_TEST(end(view1) == advance_c<0>(end(view1))); + BOOST_TEST(begin(view1) == advance_c<-1>(end(view1))); + BOOST_TEST(1 == size(view1)); + BOOST_MPL_ASSERT((boost::is_same, boost::mpl::int_<0> >::type>)); single_view view2; std::cout << view2 << std::endl;