-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5a58c7
commit e27496c
Showing
7 changed files
with
503 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include "cista/offset_t.h" | ||
|
||
namespace cista { | ||
|
||
template <typename T, typename Member> | ||
cista::offset_t member_offset(T const* t, Member const* m) { | ||
static_assert(std::is_trivially_copyable_v<T>); | ||
return (reinterpret_cast<std::uint8_t const*>(m) - | ||
reinterpret_cast<std::uint8_t const*>(t)); | ||
} | ||
|
||
template <typename T, typename Member> | ||
offset_t member_offset(T const* t, Member T::*m) { | ||
static_assert(std::is_trivially_copyable_v<T>); | ||
return (reinterpret_cast<std::uint8_t const*>(&(t->*m)) - | ||
reinterpret_cast<std::uint8_t const*>(t)); | ||
} | ||
|
||
} // namespace cista | ||
|
||
#ifndef cista_member_offset | ||
#define cista_member_offset(Type, Member) \ | ||
([]() { \ | ||
if constexpr (std::is_standard_layout_v<Type>) { \ | ||
return static_cast<::cista::offset_t>(offsetof(Type, Member)); \ | ||
} else { \ | ||
return ::cista::member_offset(static_cast<Type*>(nullptr), \ | ||
&Type::Member); \ | ||
} \ | ||
}()) | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.