たまに欲しくなるのでメモ。 #include #include #include #include using namespace boost; int main() { // 80%の確率で0, 20%の確率で1 arrayint, 10> probability = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1}; mt19937 gen(static_castunsigned long>(std::time(0)));... 続きを読む
スマートポインタのようなクラスを作成する場合、if文でヌルポインタかどうか判定できるようにするためにoperator boolをオーバーロードします。 template class T> class smart_ptr { T* p_; public: operator bool() const { return p_ != 0; } }; smart_ptri... 続きを読む
C++03だと依存名に対してtypenameを付けないといけないのでメタ関数書くとけっこう長くなってしまいます。 template class T> struct identity { typedef T type; // これはいいんだけど }; template class T> struct add_pointer { // メタ関数内でメタ関数呼... 続きを読む
公開します。翻訳がおかしいところがあったら教えてください。 N1385 The Forwarding Problem - Arguments.pdf 原文はこれです。 続きを読む
この記事には正式公開前のソフトウェアに関連する情報が掲載されています。 掲載内容はリリースがされ次第、変更する場合があります。 C++0x (シープラスプラス・ゼロエックス)は、プログラミング言語 C++ の次期標準として、2009年発行に向け策定中の改訂案... 続きを読む