TemplateUtils.h 871 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include <stdint.h>
  3. namespace il2cpp
  4. {
  5. namespace utils
  6. {
  7. namespace TemplateUtils
  8. {
  9. template<typename T, typename U>
  10. struct IsSame
  11. {
  12. static const bool value = false;
  13. };
  14. template<typename T>
  15. struct IsSame<T, T>
  16. {
  17. static const bool value = true;
  18. };
  19. template<typename B, typename D>
  20. struct IsBaseOf
  21. {
  22. private:
  23. template<typename BT, typename DT>
  24. struct Converter
  25. {
  26. operator BT*() const;
  27. operator DT*();
  28. };
  29. typedef int16_t Derived;
  30. typedef int8_t NotDerived;
  31. template<typename T>
  32. static Derived IsDerived(D*, T);
  33. static NotDerived IsDerived(B*, int);
  34. public:
  35. static const bool value = IsSame<B, D>::value || sizeof(IsDerived(Converter<B, D>(), int())) == sizeof(Derived);
  36. };
  37. }
  38. }
  39. }