// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_CORE_OFFSETOF_HPP #define NAZARA_CORE_OFFSETOF_HPP // By "Jesse Good" from SO: // http://stackoverflow.com/questions/12811330/c-compile-time-offsetof-inside-a-template?answertab=votes#tab-top namespace Nz { namespace Detail { template T GetClassType(M T::*); template M GetMemberType(M T::*); template constexpr std::size_t OffsetOf() { return reinterpret_cast(&((static_cast(0))->*M)); } } } #define NazaraOffsetOf(type, member) Nz::Detail::OffsetOf() #endif // NAZARA_CORE_OFFSETOF_HPP