Fix std::is_trivially_copyable usage.
This commit is contained in:
parent
da1f073e22
commit
7e82a54417
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/port/thread.h"
|
#include "td/utils/port/thread.h"
|
||||||
|
#include "td/utils/type_traits.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -21,7 +22,7 @@ class AtomicRead {
|
||||||
public:
|
public:
|
||||||
void read(T &dest) const {
|
void read(T &dest) const {
|
||||||
while (true) {
|
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();
|
auto version_before = version.load();
|
||||||
if (version_before % 2 == 0) {
|
if (version_before % 2 == 0) {
|
||||||
std::memcpy(&dest, &value, sizeof(dest));
|
std::memcpy(&dest, &value, sizeof(dest));
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/utils/type_traits.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
@ -64,13 +66,6 @@ class ConstAs {
|
||||||
|
|
||||||
} // namespace detail
|
} // 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,
|
template <class ToT, class FromT,
|
||||||
std::enable_if_t<TD_IS_TRIVIALLY_COPYABLE(ToT) && TD_IS_TRIVIALLY_COPYABLE(FromT), int> = 0>
|
std::enable_if_t<TD_IS_TRIVIALLY_COPYABLE(ToT) && TD_IS_TRIVIALLY_COPYABLE(FromT), int> = 0>
|
||||||
detail::As<ToT> as(FromT *from) {
|
detail::As<ToT> as(FromT *from) {
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/utils/int_types.h"
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
template <class FunctionT>
|
template <class FunctionT>
|
||||||
|
@ -27,4 +31,11 @@ constexpr size_t member_function_argument_count() {
|
||||||
return member_function_class<FunctionT>::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
|
} // namespace td
|
||||||
|
|
Loading…
Reference in New Issue
Block a user