#include <iostream>
class BaseA
{
int fa;
};
class BaseB
{
int b;
};
class Derived : public BaseA, public BaseB
{
int d;
};
template <class Base, class Derived>
struct is_sliced2 : public std::integral_constant<bool,
((void*)((Base*)((Derived*) 1))) != (void*)1>
{};
template <class Base, class Derived>
bool is_sliced(const Derived* der)
{
return (void*) der != (const Base*) der;
}
int main()
{
Derived* derived = new Derived;
BaseA* base_a = derived;
BaseB* base_b = derived;
//auto a = is_sliced<BaseA, Derived>(derived);
//auto b = is_sliced<BaseB, Derived>(derived);
static_assert(!is_sliced2<BaseA, Derived>::value, "Should be not sliced");
static_assert( is_sliced2<BaseB, Derived>::value, "Should be sliced");
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgQmFzZUEKewoJaW50IGZhOwp9OwoKY2xhc3MgQmFzZUIKewoJaW50IGI7Cn07CgpjbGFzcyBEZXJpdmVkIDogcHVibGljIEJhc2VBLCBwdWJsaWMgQmFzZUIKewoJaW50IGQ7Cn07Cgp0ZW1wbGF0ZSA8Y2xhc3MgQmFzZSwgY2xhc3MgRGVyaXZlZD4Kc3RydWN0IGlzX3NsaWNlZDIgOiBwdWJsaWMgc3RkOjppbnRlZ3JhbF9jb25zdGFudDxib29sLCAKCSgodm9pZCopKChCYXNlKikoKERlcml2ZWQqKSAxKSkpICE9ICh2b2lkKikxPiAKe307Cgp0ZW1wbGF0ZSA8Y2xhc3MgQmFzZSwgY2xhc3MgRGVyaXZlZD4KYm9vbCBpc19zbGljZWQoY29uc3QgRGVyaXZlZCogZGVyKQp7CglyZXR1cm4gKHZvaWQqKSBkZXIgIT0gKGNvbnN0IEJhc2UqKSBkZXI7Cn0KCmludCBtYWluKCkKewoJRGVyaXZlZCogZGVyaXZlZCA9IG5ldyBEZXJpdmVkOwoJQmFzZUEqIGJhc2VfYSA9IGRlcml2ZWQ7CglCYXNlQiogYmFzZV9iID0gZGVyaXZlZDsKCS8vYXV0byBhID0gaXNfc2xpY2VkPEJhc2VBLCBEZXJpdmVkPihkZXJpdmVkKTsKCS8vYXV0byBiID0gaXNfc2xpY2VkPEJhc2VCLCBEZXJpdmVkPihkZXJpdmVkKTsKCglzdGF0aWNfYXNzZXJ0KCFpc19zbGljZWQyPEJhc2VBLCBEZXJpdmVkPjo6dmFsdWUsICJTaG91bGQgYmUgbm90IHNsaWNlZCIpOwoJc3RhdGljX2Fzc2VydCggaXNfc2xpY2VkMjxCYXNlQiwgRGVyaXZlZD46OnZhbHVlLCAiU2hvdWxkIGJlIHNsaWNlZCIpOwoJcmV0dXJuIDA7Cn0K