2010-02-01から1ヶ月間の記事一覧

内部クラス/無名ネームスペース/関数内クラスのダンプ

#include <iostream> namespace hoge { class X { public: void test(){ std::cout << "in hoge namespace X.test" << std::endl;} }; class XX { public: class YY { public: void test(){std::cout << "in hoge namespace XX::YY.test" << std::endl;} }; }; }; name</iostream>…

boost::optionalをつかうとmaybeっぽくできる。

失敗しそうな処理があっても連続的に表記できるってのは if文が連続しがちなCプログラミングに清涼剤を与えてくれるね。 #include <cmath> #include <iostream> #include <boost/optional.hpp> using namespace std; using namespace boost; // double かもしれない 型 typedef optional<double> maybe_dou</double></boost/optional.hpp></iostream></cmath>…

valgrindを使ってみる。

install簡単。 sudo apt-get install valgrind 使い方(メモリまわりのチェック) tool=$hoge でツールの選択。メモリチェッカーをつかって、 leak-check=fullで該当箇所がわかる。 valgrind --tool=memcheck --leak-check=full $command メモリの取り扱いが…

アクセサっぽいもの

#include <iostream> // 特定の型のsetter/getterをかえすmeta function template <class T,class Object> struct accessor_of{ typedef T ( Object::*getter )(); typedef T ( Object::*setter )( const T&); }; // コピーコンストラクタ/=演算子/()演算子を実装した一時オブジェクトをつく</class></iostream>…

Virtual Tableについて

/* Vtable for B1 B1::_ZTV2B1: 3u entries 0 (int (*)(...))0 8 (int (*)(...))(& _ZTI2B1) 16 B1::f1 Class B1 size=16 align=8 base size=16 base align=8 B1 (0x7ff8afb7ad90) 0 vptr=((& B1::_ZTV2B1) + 16u) */ class B1 { public: void f0(){} virtua…

RTTI

#include <iostream> #include <typeinfo> #include <cxxabi.h> using namespace std; class Base { public : virtual void Test(){} int a; }; class Sub : public Base { public : virtual void Test(){} int b; }; #define class_name( X ) demangle( typeid(X).name() ) std::string de</cxxabi.h></typeinfo></iostream>…