enumerate Rangeアダプタがすっきりした
前々回、こんなのを作ったけど、any_rangeを使ったりしてなんだか汚い感じでしたし、
counting rangeのDifferenceかなんかの型がmsvcでwarning:4244を出したりして微妙だったので改良を。
#ifndef HWM_ENUMERATE_HPP_ #define HWM_ENUMERATE_HPP_ #include <pstade/result_of.hpp> #include <pstade/oven/counting.hpp> #include <pstade/oven/distance.hpp> #include <pstade/oven/pack.hpp> #include <pstade/oven/zipped.hpp> #include <pstade/oven/zipped_with.hpp> namespace hwm { namespace enumerate_detail { using namespace pstade; using namespace pstade::oven; struct little { typedef unsigned long incrementable_t; typedef result_of<T_counting(incrementable_t, incrementable_t)>::type counting_range_t; template< class Myself, class Range, class BinaryFun = void> struct apply { typedef typename result_of< T_pack( typename iter_range_of<counting_range_t>::type, typename iter_range_of<Range>::type ) >::type range_tuple_t; typedef typename result_of< X_make_zipped_with<>(range_tuple_t, BinaryFun&) >::type type; }; template< class Result, class Range, class BinaryFun > Result call(Range &r, BinaryFun &f) const { return pack(counting((incrementable_t)0, (incrementable_t)(r|distance)), r)|zipped_with(f); } template< class Myself, class Range > struct apply<Myself, Range> { typedef typename result_of< T_pack( typename iter_range_of<counting_range_t>::type, typename iter_range_of<Range>::type ) >::type range_tuple_t; typedef typename result_of< T_make_zipped(range_tuple_t) >::type type; }; template<class Result, class Range> Result call(Range &r) const { return pack(counting((incrementable_t)0, (incrementable_t)(r|distance)), r)|zipped; } }; } //namespace enumerate_detail PSTADE_OVEN_LITTLE_TO_ADAPTOR(enumerate, (enumerate_detail::little)) } //namespace hwm #endif //HWM_ENUMERATE_HPP_
pstade::result_ofでアダプタを適用したRangeの型が取れるので綺麗にかけました。
実はiter_range_ofが何のために必要か、とか諸々よくわかっていないのですが。。。
とにかくOvenの設計綺麗だなー