Fix std::is_trivially_copyable usage.

This commit is contained in:
levlam 2020-11-06 17:09:47 +03:00
parent da1f073e22
commit 7e82a54417
3 changed files with 15 additions and 8 deletions

View File

@ -8,6 +8,7 @@
#include "td/utils/common.h"
#include "td/utils/port/thread.h"
#include "td/utils/type_traits.h"
#include <atomic>
#include <cstring>
@ -21,7 +22,7 @@ class AtomicRead {
public:
void read(T &dest) const {
while (true) {
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable");
static_assert(TD_IS_TRIVIALLY_COPYABLE(T), "T must be trivially copyable");
auto version_before = version.load();
if (version_before % 2 == 0) {
std::memcpy(&dest, &value, sizeof(dest));

View File

@ -6,6 +6,8 @@
//
#pragma once
#include "td/utils/type_traits.h"
#include <cstring>
#include <type_traits>
@ -64,13 +66,6 @@ class ConstAs {
} // namespace detail
// no std::is_trivially_copyable in libstdc++ before 5.0
#if __GLIBCXX__
#define TD_IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
#else
#define TD_IS_TRIVIALLY_COPYABLE(T) ::std::is_trivially_copyable<T>::value
#endif
template <class ToT, class FromT,
std::enable_if_t<TD_IS_TRIVIALLY_COPYABLE(ToT) && TD_IS_TRIVIALLY_COPYABLE(FromT), int> = 0>
detail::As<ToT> as(FromT *from) {

View File

@ -6,6 +6,10 @@
//
#pragma once
#include "td/utils/int_types.h"
#include <type_traits>
namespace td {
template <class FunctionT>
@ -27,4 +31,11 @@ constexpr size_t member_function_argument_count() {
return member_function_class<FunctionT>::argument_count();
}
// no std::is_trivially_copyable in libstdc++ before 5.0
#if __GLIBCXX__
#define TD_IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
#else
#define TD_IS_TRIVIALLY_COPYABLE(T) ::std::is_trivially_copyable<T>::value
#endif
} // namespace td