template<class T>
struct is_class_or_union
{
struct twochar { char _[2]; };
template <class U>
static char is_class_or_union_tester(void(U::*)(void));
template <class U>
static twochar is_class_or_union_tester(...);
static const bool value = sizeof(is_class_or_union_tester<T>(0)) == sizeof(char);
};
上記のコードはmeta_utils.hpp
、boost ライブラリからのものです。
is_class_or_union_tester
メンバー関数へのポインターをstatic
返し、取得する関数のようです(voidを返し、何も受け入れません)。char
関数本体はなく、どこにも定義されていないようです。それがどのように機能するのかわかりません。何より、機能の目的がわかりません。- 次のコードの概念がわかりません:
static const bool value = sizeof(is_class_or_union_tester<T>(0)) == sizeof(char);
What is thesizeof
operator applied to? 彼らはここで何を見つけようとしていますか?