C++

C++0x と遊ぶときのちょっとした

GCC 4.5.1 で結構色々と実際に使えるようになってきたこともあって,C++0x 向けにちょっとだけ Vim の設定を足した.まず static_assert, decltype をハイライトするように ~/.vim/after/syntax/cpp.vim に syntax keyword cppOperator static_assert declty…

variadic templates なクラス

C++

std::tuple を見ながら徐々に tuple を実装して variadic templates なクラスの書き方を知ろう的な. tuple が tuple を継承し,更にそれが tuple を継承し… というようなかんじで,それぞれが T1, T2, T3, ... な値を保持するように実装する. はじめのいっ…

vector, copy, construct, reference

C++

メモ http://ideone.com/XaKQV

関数内で関数を定義する

C++

つまりはクロージャが欲しい. C言語の場合は GCC 拡張でこれを実現できる. http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html #include <stdio.h> int main(void) { int x = 0; void f(void) { x++; } f(); printf("%d\n", x); return 0; } C++ の場合は C+</stdio.h>…

C++ にも on が欲しい

C++

Haskell には Data.Function に on という関数が用意されている. http://haskell.org/ghc/docs/latest/html/libraries/base-4.2.0.0/Data-Function.html#v:on 関数 f, g から \x y -> f (g x) (g y) という関数を作る関数だ. これが地味に便利な場面があり…