Skip to content

Commit

Permalink
Avoid using std::is_trivial
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Nov 26, 2024
1 parent cdcd2f0 commit c9f2b2f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/momo/UserSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#endif

// Using `memcpy` for relocate
#define MOMO_IS_TRIVIALLY_RELOCATABLE(Object) (std::is_trivial<Object>::value)
#define MOMO_IS_TRIVIALLY_RELOCATABLE(Object) (std::is_trivially_copyable<Object>::value)

//#define MOMO_MEM_MANAGER_PTR_USEFUL_BIT_COUNT ((sizeof(void*) == 8) ? 48 : sizeof(void*) * 8)

Expand Down
5 changes: 3 additions & 2 deletions include/momo/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,15 @@ namespace internal
template<typename Object>
static void ToBuffer(Object object, void* buffer) noexcept
{
MOMO_STATIC_ASSERT(std::is_trivial<Object>::value);
MOMO_STATIC_ASSERT(std::is_trivially_copyable<Object>::value);
std::memcpy(buffer, &object, sizeof(Object));
}

template<typename ResObject>
static ResObject FromBuffer(const void* buffer) noexcept
{
MOMO_STATIC_ASSERT(std::is_trivial<ResObject>::value);
MOMO_STATIC_ASSERT(std::is_trivially_copyable<ResObject>::value
&& std::is_nothrow_default_constructible<ResObject>::value);
ResObject object{};
std::memcpy(&object, buffer, sizeof(ResObject));
return object;
Expand Down

0 comments on commit c9f2b2f

Please sign in to comment.