SkVptr.h 551 B

123456789101112131415161718192021222324
  1. /*
  2. * Copyright 2017 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkVptr_DEFINED
  8. #define SkVptr_DEFINED
  9. #include <string.h>
  10. #include <type_traits>
  11. // Experimentally, see if we can get at the vptr of objects with one.
  12. template <typename T>
  13. static inline void* SkVptr(const T& object) {
  14. static_assert(std::has_virtual_destructor<T>::value, "");
  15. void* vptr;
  16. memcpy(&vptr, (const void*)&object, sizeof(vptr));
  17. return vptr;
  18. }
  19. #endif//SkVptr_DEFINED