blob: 2a33ad06c76f1d55e02ae20e29c7e25461dff363 [file] [log] [blame]
Mike Klein0554d492017-12-06 12:27:44 -05001/*
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
8#ifndef SkVptr_DEFINED
9#define SkVptr_DEFINED
10
11#include <string.h>
12#include <type_traits>
13
14// Experimentally, see if we can get at the vptr of objects with one.
15
16template <typename T>
17static inline void* SkVptr(const T& object) {
18 static_assert(std::has_virtual_destructor<T>::value, "");
19 void* vptr;
20 memcpy(&vptr, (const void*)&object, sizeof(vptr));
21 return vptr;
22}
23
24#endif//SkVptr_DEFINED