2008-12-18から1日間の記事一覧

boost::bind萌え〜

C++

思わず顔がにやけてしまった。 #include <iostream> #include <string> #include <boost/bind.hpp> #include <boost/function.hpp> using namespace std; int add(int a, int b) { return a + b; } int main() { boost::function<int (int)> f = boost::bind(add, 5, _1); cout << f(1) << endl; cout << f(2) << endl; return </int></boost/function.hpp></boost/bind.hpp></string></iostream>…

boost:クロージャを作る

C++

萌え。 #include <iostream> #include <string> #include <boost/bind.hpp> #include <boost/function.hpp> #include <boost/shared_ptr.hpp> using namespace std; int count(boost::shared_ptr<int> n) { (*n)++; return *n; } int main() { boost::shared_ptr<int> n(new int(0)); boost::function<int (void)> f = boost::…</int></int></int></boost/shared_ptr.hpp></boost/function.hpp></boost/bind.hpp></string></iostream>