24 #ifndef ABSL_BASE_CASTS_H_ 25 #define ABSL_BASE_CASTS_H_ 29 #include <type_traits> 38 namespace internal_casts {
40 template <
class Dest,
class Source>
42 : std::integral_constant<
44 sizeof(Dest) == sizeof(Source) &&
45 type_traits_internal::is_trivially_copyable<Source>::value &&
46 type_traits_internal::is_trivially_copyable<Dest>::value &&
47 std::is_default_constructible<Dest>::value> {};
100 template <
typename To>
151 typename Dest,
typename Source,
156 memcpy(static_cast<void*>(std::addressof(dest)),
157 static_cast<const void*>(std::addressof(source)),
sizeof(dest));
165 typename Dest,
typename Source,
166 typename std::enable_if<
169 "absl::bit_cast type requirements were violated. Update the types being " 170 "used such that they are the same size and are both TriviallyCopyable.")
171 inline Dest
bit_cast(const Source& source) {
172 static_assert(
sizeof(Dest) ==
sizeof(Source),
173 "Source and destination types should have equal sizes.");
176 memcpy(&dest, &source,
sizeof(dest));
182 #endif // ABSL_BASE_CASTS_H_
Dest bit_cast(const Source &source)
constexpr To implicit_cast(typename absl::internal::identity_t< To > to)
ABSL_DEPRECATED("absl::bit_cast type requirements were violated. Update the types being ""used such that they are the same size and are both TriviallyCopyable.") inline Dest bit_cast(const Source &source)
typename identity< T >::type identity_t