P-Stadeライブラリの最新をSVNから持ってきてもらえれば使用できます。
GCC 4.5 with C++0xならこう書けます。
#define BOOST_RESULT_OF_USE_DECLTYPE #include <iostream> #include <string> #include <pstade/oven/zipped_with_index.hpp> #include <pstade/oven/algorithm.hpp> #include <boost/fusion/include/make_fused.hpp> #include <boost/fusion/include/boost_tuple.hpp> namespace oven = pstade::oven; namespace fusion = boost::fusion; int main() { const std::string s = "abc"; oven::for_each(s | oven::zipped_with_index, fusion::make_fused( [](char c, std::size_t i) { std::cout << c << "," << i << std::endl; } )); }
a,0 b,1 c,2
GCC 4.5未満、もしくはVC(10含む)の場合は、decltypeベースのresult_ofがないので、tieするかtupleのまま使用することになります。
#include <iostream> #include <string> #include <pstade/oven/zipped_with_index.hpp> #include <boost/foreach.hpp> namespace oven = pstade::oven; int main() { const std::string s = "abc"; typedef boost::tuple<char, std::size_t> tup; BOOST_FOREACH(tup t, s | oven::zipped_with_index) { std::cout << boost::get<0>(t) << "," << boost::get<1>(t) << std::endl; } }