fork(2) download
  1. #include <iostream>
  2.  
  3. class BaseA
  4. {
  5. int fa;
  6. };
  7.  
  8. class BaseB
  9. {
  10. int b;
  11. };
  12.  
  13. class Derived : public BaseA, public BaseB
  14. {
  15. int d;
  16. };
  17.  
  18. template <class Base, class Derived>
  19. struct is_sliced2 : public std::integral_constant<bool,
  20. ((void*)((Base*)((Derived*) 1))) != (void*)1>
  21. {};
  22.  
  23. template <class Base, class Derived>
  24. bool is_sliced(const Derived* der)
  25. {
  26. return (void*) der != (const Base*) der;
  27. }
  28.  
  29. int main()
  30. {
  31. Derived* derived = new Derived;
  32. BaseA* base_a = derived;
  33. BaseB* base_b = derived;
  34. //auto a = is_sliced<BaseA, Derived>(derived);
  35. //auto b = is_sliced<BaseB, Derived>(derived);
  36.  
  37. static_assert(!is_sliced2<BaseA, Derived>::value, "Should be not sliced");
  38. static_assert( is_sliced2<BaseB, Derived>::value, "Should be sliced");
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 3424KB
stdin
Standard input is empty
stdout
Standard output is empty