Make td::as safe.
GitOrigin-RevId: 84a76a434f88e09d9c74644aee139a96bb34239d
This commit is contained in:
parent
b275a77a84
commit
0fc836ce8f
@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
@ -60,12 +61,14 @@ class ConstAs {
|
|||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template <class ToT, class FromT>
|
template <class ToT, class FromT,
|
||||||
|
std::enable_if_t<std::is_trivially_copyable<ToT>::value && std::is_trivially_copyable<FromT>::value, int> = 0>
|
||||||
detail::As<ToT> as(FromT *from) {
|
detail::As<ToT> as(FromT *from) {
|
||||||
return detail::As<ToT>(from);
|
return detail::As<ToT>(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ToT, class FromT>
|
template <class ToT, class FromT,
|
||||||
|
std::enable_if_t<std::is_trivially_copyable<ToT>::value && std::is_trivially_copyable<FromT>::value, int> = 0>
|
||||||
const detail::ConstAs<ToT> as(const FromT *from) {
|
const detail::ConstAs<ToT> as(const FromT *from) {
|
||||||
return detail::ConstAs<ToT>(from);
|
return detail::ConstAs<ToT>(from);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user