2009-01-09から1日間の記事一覧

簡単なキャッシュ

C++

#include <iostream> #include <string> #include <sstream> #include <map> #ifdef _WIN32 #define _WIN32_WINNT 0x0501 #endif #include <boost/asio.hpp> #include <boost/timer.hpp> using namespace std; template <class I, class O> class Cache { map<I, O> m_; O (*f_)(I x); public: Cache(O (*f)(I x)): f_(f) {…</i,></class></boost/timer.hpp></boost/asio.hpp></map></sstream></string></iostream>

30分経ってもboostのビルドが終わらない…

C++

もう寝るか…

関数の返値をパラメータとするテンプレート関数

C++

gcc 3.4だと出来ないと思ってたら出来た。 #include <iostream> #include <string> #include <boost/lexical_cast.hpp> using namespace std; using namespace boost; template <class I, class O> class Foo { O (*f_)(I x); public: Foo(O (*f)(I x)): f_(f) {} O operator ()(I x) { return f_(x); } }; int xstr2int(s</class></boost/lexical_cast.hpp></string></iostream>…

Ruby/DLでSEGV

落ちた。少なくともmswin32版はハンドルしてない…と。 __declspec(dllexport) void foo(); void foo() { *(char *)0 = 1; } require 'dl/import' module Foo extend DL::Importable dlload 'foo.dll' extern "void foo()" end Foo.foo ~$ ruby foo.rb (eval)…