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