serenity/AK/BitCast.h

24 lines
346 B
C
Raw Normal View History

2021-03-22 18:25:06 +00:00
/*
* Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
2021-03-22 18:25:06 +00:00
*/
#pragma once
namespace AK {
template<typename T, typename U>
inline T bit_cast(const U& a)
{
static_assert(sizeof(T) == sizeof(U));
T result;
__builtin_memcpy(&result, &a, sizeof(T));
return result;
}
}
using AK::bit_cast;