diff options
author | eeight <eeight@yandex-team.ru> | 2022-02-10 16:46:18 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:18 +0300 |
commit | 475c0a46f28166e83fd263badc7546377cddcabe (patch) | |
tree | 39c5a49b8aaad78fe390b6f1f2886bdbda40f3e7 /util/generic/cast.h | |
parent | a6e0145a095c7bb3770d6e07aee301de5c73f96e (diff) | |
download | ydb-475c0a46f28166e83fd263badc7546377cddcabe.tar.gz |
Restoring authorship annotation for <eeight@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/cast.h')
-rw-r--r-- | util/generic/cast.h | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/util/generic/cast.h b/util/generic/cast.h index 0d4a41f385..10278b6b62 100644 --- a/util/generic/cast.h +++ b/util/generic/cast.h @@ -5,7 +5,7 @@ #include <util/system/compat.h> #include <util/system/type_name.h> -#include <util/system/unaligned_mem.h> +#include <util/system/unaligned_mem.h> #include <util/system/yassert.h> #include <cstdlib> @@ -158,19 +158,19 @@ template <typename T> constexpr std::underlying_type_t<T> ToUnderlying(const T enum_) noexcept { return static_cast<std::underlying_type_t<T>>(enum_); } - -// std::bit_cast from c++20 -template <class TTarget, class TSource> -TTarget BitCast(const TSource& source) { - static_assert(sizeof(TSource) == sizeof(TTarget), "Size mismatch"); - static_assert(std::is_trivially_copyable<TSource>::value, "TSource is not trivially copyable"); - static_assert(std::is_trivial<TTarget>::value, "TTarget is not trivial"); - - // Support volatile qualifiers. - // ReadUnaligned does not work with volatile pointers, so cast away - // volatileness beforehand. - using TNonvolatileSource = std::remove_volatile_t<TSource>; - using TNonvolatileTarget = std::remove_volatile_t<TTarget>; - - return ReadUnaligned<TNonvolatileTarget>(&const_cast<const TNonvolatileSource&>(source)); -} + +// std::bit_cast from c++20 +template <class TTarget, class TSource> +TTarget BitCast(const TSource& source) { + static_assert(sizeof(TSource) == sizeof(TTarget), "Size mismatch"); + static_assert(std::is_trivially_copyable<TSource>::value, "TSource is not trivially copyable"); + static_assert(std::is_trivial<TTarget>::value, "TTarget is not trivial"); + + // Support volatile qualifiers. + // ReadUnaligned does not work with volatile pointers, so cast away + // volatileness beforehand. + using TNonvolatileSource = std::remove_volatile_t<TSource>; + using TNonvolatileTarget = std::remove_volatile_t<TTarget>; + + return ReadUnaligned<TNonvolatileTarget>(&const_cast<const TNonvolatileSource&>(source)); +} |