mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 13:30:31 +00:00
27 lines
460 B
C++
27 lines
460 B
C++
/*
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
namespace AK {
|
|
|
|
template<typename T, typename U>
|
|
[[nodiscard]] constexpr inline T bit_cast(const U& a)
|
|
{
|
|
#if (__has_builtin(__builtin_bit_cast))
|
|
return __builtin_bit_cast(T, a);
|
|
#else
|
|
static_assert(sizeof(T) == sizeof(U));
|
|
|
|
T result;
|
|
__builtin_memcpy(&result, &a, sizeof(T));
|
|
return result;
|
|
#endif
|
|
}
|
|
|
|
}
|
|
|
|
using AK::bit_cast;
|