A quick note: you can use C++11 templates to detect struct fields by name and type, and statically branch on them. I first heard of this solution from breeze1990.
Say I want to detect if a struct has a field size of type int. Create two template instantiations of the same name, here HasStaticSize that defaults to false.
#include template struct HasStaticSize : std::false_type {}; template struct HasStaticSize< T, typename std::enable_if< std::is_same>::value, void>::type> : std::true_type {}; The latter is only resolved if T::size is declared as int, or more specifically, something that “decays” to int.
jeremykun.com
jeremykun.com
Create attached notes ...
