// // product_view.h // #ifndef _product_view_ #define _product_view_ #include #include #include #include #include #include namespace detail { using namespace boost::mpl; template struct state_with_overflow { typedef S state; typedef O overflow; }; template struct i3s_increment_inserter { template struct i3_ { typedef I3 i3; typedef O overflow; }; template struct incr_ { typedef typename next< typename at_c< I3, 1 >::type >::type next_; typedef bool_< boost::is_same< next_, typename at_c::type >::value > overflow_; typedef i3_< vector3< typename at_c::type, typename if_< overflow_, typename at_c::type, next_ >::type, typename at_c::type >, overflow_ > type; }; typedef front_inserter< typename clear::type > base_; typedef state_with_overflow< typename base_::state, true_ > state; struct operation { template struct apply { typedef typename if_< typename S::overflow, typename incr_::type, i3_ >::type next_; typedef state_with_overflow< typename base_::operation::template apply< typename S::state, typename next_::i3 >::type, typename next_::overflow > type; }; }; }; template< typename SWO > struct product_iterator { private: typedef typename SWO::state I3S; public: typedef forward_iterator_tag category; typedef typename transform1< I3S, deref< at< _1, int_<1> > > >::type type; typedef product_iterator< typename reverse_copy< I3S, i3s_increment_inserter >::type > next; }; template struct product_view { private: typedef typename transform1< S, vector3< begin<_1>, begin<_1>, end<_1> > >::type begin_impl; typedef typename fold< S, false_, or_< _1, boost::is_same< begin<_2>, end<_2> > // empty<_2> refuses to compile on MSVC 7.1 > >::type empty_result; public: typedef nested_begin_end_tag tag; typedef product_iterator< state_with_overflow< begin_impl, empty_result > > begin; typedef product_iterator< state_with_overflow< begin_impl, true_ > > end; }; } using detail::product_view; #endif