我需要一个类型特征,如果给定的类型派生自任何东西,则为true,否则为false.
例如:
template<class T>
struct is_inherit
//... logic of inheritance detection
;
template<class T>
void AppLogic(){
if constexpr(is_inherit<T>::value) {
puts("T has base");
//...
} else {
puts("T doesn't have base");
//...
}
}
struct A {};
struct C {};
struct B: C {};
int main() {
AppLogic<A>(); // print: T doesn't have base
AppLogic<B>(); // print: T has base
}
Run Code Online (Sandbox Code Playgroud)
是否有可能以某种方式实现"is_inherit"特征结构?
为什么?
我正在为Windows x64开发一个手动堆栈框架构建器.根据https://docs.microsoft.com/en-us/cpp/build/return-values-cpp文档,如果是类型:
然后它的返回值在RAX寄存器中,否则该函数有一个我必须检测和处理的隐藏参数.
这曾经是C++ 03 POD的定义,但是在C++ 11中这改变了:
由于C++ 11标准中的定义已更改,因此我们不建议您使用 …