7並べ 〜その4〜 トランプデータの生成


すでにぐだぐだになりつつある気がするけどまだがんばるお。
そんな訳でトランプのデータの生成を行ないます。
使うのは、昨日作った combination です。
こいつを使用して、絵柄と数字の組み合わせを列挙していきます。
( 0w0) ウェーイ

#include <iostream>
#include <string>
#include <vector>

#include <pstade/oven/matrix.hpp>
#include <pstade/oven/concatenated.hpp>
#include <pstade/oven/cycled.hpp>
#include <pstade/oven/distance.hpp>
#include <pstade/oven/zipped.hpp>
#include <pstade/oven/any_range.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>

#include <pstade/oven/counting.hpp>
#include <pstade/oven/copied.hpp>
#include <pstade/oven/io.hpp>

#include <boost/array.hpp>

#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_io.hpp>

#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/range/algorithm/for_each.hpp>


template<
    typename T1,
    typename T2
>
pstade::oven::any_range<
    boost::tuple<
        typename boost::range_value<T1>::type,
        typename boost::range_value<T2>::type
    >,
    boost::forward_traversal_tag
>
combination(const T1& range1, T2& range2){
    namespace oven = pstade::oven;
    namespace lambda = boost::lambda;
    
    return boost::make_tuple(
        range1|oven::rows(range1|oven::distance, 1)
                |oven::transformed(
                    lambda::bind(oven::make_cycled, lambda::_1, range2|oven::distance
                ))
                |oven::concatenated,
        range2|oven::cycled(range1|oven::distance)
    )|oven::zipped;
}


int
main(){
    namespace oven = pstade::oven;
    namespace lambda = boost::lambda;

    boost::array<std::string, 4>    suits = {"spade", "heart", "diamond", "club"};
    boost::array<int, 13>    numbers = oven::counting(1, 14)|oven::copied;
    
    std::cout << (suits|oven::identities) << std::endl;
    std::cout << (numbers|oven::identities) << std::endl;

    boost::for_each( combination(suits, numbers),
        [](boost::tuple<std::string, int> t){
        std::cout << t << std::endl;
    });

    return 0;
}


[出力]

{spade,heart,diamond,club}
{1,2,3,4,5,6,7,8,9,10,11,12,13}
(spade 1)
(spade 2)
(spade 3)
(spade 4)
(spade 5)
(spade 6)
(spade 7)
(spade 8)
(spade 9)
(spade 10)
(spade 11)
(spade 12)
(spade 13)
(heart 1)
(heart 2)
(heart 3)
(heart 4)
(heart 5)
(heart 6)
(heart 7)
(heart 8)
(heart 9)
(heart 10)
(heart 11)
(heart 12)
(heart 13)
(diamond 1)
(diamond 2)
(diamond 3)
(diamond 4)
(diamond 5)
(diamond 6)
(diamond 7)
(diamond 8)
(diamond 9)
(diamond 10)
(diamond 11)
(diamond 12)
(diamond 13)
(club 1)
(club 2)
(club 3)
(club 4)
(club 5)
(club 6)
(club 7)
(club 8)
(club 9)
(club 10)
(club 11)
(club 12)
(club 13)


[boost/pstade]
ver 1.44.0 / ver 1.04.3
[関連]
http://d.hatena.ne.jp/osyo-manga/20101013/1286949620