Oven/Egg総合スレ part1
■ このスレッドは過去ログ倉庫に格納されています
0012デフォルトの名無しさん
2009/01/08(木) 01:40:05この例では、cat関数にてtupleではなくstringを作ってもらうようにして、fizzbuzzを作ってみた。
#include <iostream>
#include <string>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <pstade/oven/zipped_with.hpp>
#include <pstade/oven/counting.hpp>
#include <pstade/oven/cycled.hpp>
#include <pstade/oven/taken.hpp>
std::string cat(unsigned i, std::string const& f, std::string const& b) {
if (f.empty() && b.empty())
return boost::lexical_cast<std::string>(i);
else
return f + b;
}
int main() {
using namespace pstade::oven;
std::string const fizz[] = {"", "", "fizz"};
std::string const buzz[] = {"", "", "", "", "buzz"};
BOOST_FOREACH(std::string const& s,
boost::make_tuple(
counting(1u, max_count),
fizz | cycled, //"", "", "fizz", "", "", "fizz", ...のように無限に繰り返すレンジが作られる。
buzz | cycled)
| zipped_with(cat) | taken(20))
{
std::cout << s << std::endl;
}
}
このfizzbuzzは作者mb2さんのブログ記事を参考にして作った(なぜか全体のコードが見れなかったけど)。
http://d.hatena.ne.jp/mb2sync/20070514#p1
■ このスレッドは過去ログ倉庫に格納されています