/*============================================================================= Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2006 Dan Marsden Copyright (c) 2008 Stjepan Rajko 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_SEQUENCE_CLASS_LAZY_SEQUENCE_10022005_0602) #define FUSION_SEQUENCE_CLASS_LAZY_SEQUENCE_10022005_0602 #include #include #include #include #include #include #include namespace boost { namespace fusion { template struct lazy_sequence_iterator : fusion::iterator_facade, fusion::random_access_traversal_tag> { typedef mpl::int_ index; typedef Seq sequence_type; lazy_sequence_iterator(Seq& seq) : seq_(seq) {} Seq& seq_; template struct value_of; template struct value_of > : mpl::identity)>::type> {}; template struct deref; template struct deref > { typedef typename boost::result_of)>::type type; static type call(lazy_sequence_iterator const& iter) { return iter.seq_.generator(mpl::int_()); } }; template struct next { typedef lazy_sequence_iterator< typename It::sequence_type, It::index::value + 1> type; static type call(It const& it) { return type(it.seq_); } }; template struct prior { typedef lazy_sequence_iterator< typename It::sequence_type, It::index::value - 1> type; static type call(It const& it) { return type(it.seq_); } }; template struct distance { typedef typename mpl::minus::type type; static type call(It1 const& it1, It2 const& it2) { return type(); } }; template struct advance { typedef lazy_sequence_iterator< typename It::sequence_type, It::index::value + M::value> type; static type call(It const& it) { return type(it.seq_); } }; }; template struct lazy_sequence : fusion::sequence_facade, fusion::random_access_traversal_tag> { lazy_sequence() : generator() {} lazy_sequence(const Generator &generator) : generator(generator) {} template struct begin { typedef lazy_sequence_iterator< Sq, 0> type; static type call(Sq& sq) { return type(sq); } }; template struct end { typedef lazy_sequence_iterator< Sq, Size> type; static type call(Sq& sq) { return type(sq); } }; template struct size : mpl::int_ {}; template struct value_at { typedef typename boost::result_of::type type; }; template struct at { typedef typename boost::result_of::type type; static type call(Sq& sq) { return sq.generator(N()); } }; typedef Generator generator_type; generator_type generator; }; namespace result_of { template struct make_lazy_sequence { typedef lazy_sequence< typename mpl::if_< function_types::is_function, G *, G >::type, Size::value > type; }; } template typename result_of::make_lazy_sequence::type make_lazy_sequence(const G &g, Size size) { return typename result_of::make_lazy_sequence::type(g); } } } #endif