You can check if an element is defined in the base class by specifying its type as a pointer to a member:
static_assert(std::is_same<decltype(&U::name), std::string (U::*)()>::value, "name must be defined directly in U");
This means that at compile time you must have access to all types of descendants that interest you.
source share