FC++ cons

関数型でおなじみ(といっても Scheme くらいしか知らないけど)の cons でリスト作成

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

using namespace std;
using namespace boost::fcpp;

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

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

    return 0;
}


リストの先頭に要素追加

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

ls = cons(2, ls); // 2, 3, 1, 4


FC++ まとめ