rabbitfoot530's diary

読んだ本と、プログラムに関することのメモです。好きな言語は、C++, Python, Golang, TypeScript。数学・物理・学習理論も好きです。

2012-03-01から1ヶ月間の記事一覧

boost::unordered_mapコンパイルエラー

デバッグプリント用にdefineでpを宣言してたら、unordered_mapの#includeのところでエラーがでた。 /usr/include/boost/unordered/detail/allocator_helpers.hpp: In member function ‘boost::unordered_detail::allocator_array_constructor<Allocator>::pointer boost</allocator>…

_SC_OPEN_MAX: 最大ファイル数

c c++

1プロセス中の最大オープンファイル数 #include <sys/resource.h> int main() { Print::p(sysconf(_SC_OPEN_MAX)); }</sys/resource.h>

structからclassへ書き換え

c++ c

Cのソースにある、structをクラスへ書き換える。 関数ポインタ使ってると、下記のようにすればいい。 typedef int (*handler_t)(int fd, void* arg); typedef int (*destructor_t)(void* arg); typedef struct context { void* arg; handler_t handler; dest…

libevent使用時のコンパイルエラー

c c++

libeventを使ったコードをコンパイルするときに下記のエラーがでました。 error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory ただ単にリンクがたりてないだけ。/usr/local/libにファイ…

boost::function

要は、関数ポインタね♪ #include <boost/function.hpp> int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int main() { boost::function<int (int, int)> f = add; Print::p(f(1, 2)); f = sub; Print::p(f(1, 2)); }</int></boost/function.hpp>

templateのヘッダ

C++

tepmlateを書くときは、ヘッダに実装も書かないといけない。けど、宣言が書いてあるヘッダに、実装が書いてあるヘッダを別ファイルとしてincludeすれば、実装と宣言を分けることができる。inc_header.hpp #include "imp_header.hpp" template <typename T> void(T m); te</typename>…