C++ でキャストをつくる
C++ (0x から?)には static_cast とかがある。これと似たようなことが時までできる。どっかの blog か本で自前の cast をつくるという方法が載っていた。
忘れがちなので自分用のメモ。
http://nekko1119.hatenablog.com/entry/2013/09/05/204331
単純にtemplate を使った関数を書けばよい。
template <class X>
X* ex_cast(half_cell &cxr) {
if (!cxr.is_pointer()) {
return 0;
}
if (!cxr.check_range<X>()) {
return 0;
}
return reinterpret_cast<X*>(cxr.value);
}これでおれおれ疑似ダイナミックキャストができる。