FC++ map

リストの全要素に対する操作を行う

#include <iostream>
#include <iterator>
#include <algorithm>
#include <boost/fcpp/prelude.hpp>

using namespace std;
using namespace boost::fcpp;

int main()
{
    list<int> ls = list_with<>()(3, 1, 4);

    ls = map(inc, ls); // 全要素を+1

    copy(ls.begin(), ls.end(), ostream_iterator<int>(cout, ","));
        // 4,2,5

    return 0;
}
ls = map(plus(2), ls); // 全要素を+2


無限リストに対してもできます

list<int> ls = enum_from(1); // 1, 2, 3, 4, 5, ...
ls = map(inc, ls); // 2, 3, 4, 5, 6, ...


FC++ まとめ