Added OffsetOf header and function
Designed to replace the old offsetof macro Former-commit-id: faa45ebfd3c1f9cc817f6fccf5c94d2c1527349d
This commit is contained in:
parent
d9c38181a5
commit
b595f703da
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2014 Jérôme Leclercq
|
||||
// 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_OFFSETOF_HPP
|
||||
#define NAZARA_OFFSETOF_HPP
|
||||
|
||||
// Par "Jesse Good" de SO:
|
||||
// http://stackoverflow.com/questions/12811330/c-compile-time-offsetof-inside-a-template?answertab=votes#tab-top
|
||||
|
||||
template <typename T, typename M> T NzImplGetClassType(M T::*);
|
||||
template <typename T, typename M> M NzImplGetMemberType(M T::*);
|
||||
|
||||
template <typename T, typename R, R T::*M>
|
||||
constexpr std::size_t NzImplOffsetOf()
|
||||
{
|
||||
return reinterpret_cast<std::size_t>(&(((T*)0)->*M));
|
||||
}
|
||||
|
||||
#define NzOffsetOf(type, member) NzImplOffsetOf<decltype(NzImplGetClassType(&type::member)), decltype(NzImplGetMemberType(&type::member)), &type::member>()
|
||||
|
||||
#endif // NAZARA_OFFSETOF_HPP
|
||||
Loading…
Reference in New Issue