Path: blob/main/contrib/llvm-project/libcxx/include/__bit/bit_cast.h
35260 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___BIT_BIT_CAST_H10#define _LIBCPP___BIT_BIT_CAST_H1112#include <__config>13#include <__type_traits/is_trivially_copyable.h>1415#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)16# pragma GCC system_header17#endif1819_LIBCPP_BEGIN_NAMESPACE_STD2021#ifndef _LIBCPP_CXX03_LANG2223template <class _ToType, class _FromType>24_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr _ToType __bit_cast(const _FromType& __from) noexcept {25return __builtin_bit_cast(_ToType, __from);26}2728#endif // _LIBCPP_CXX03_LANG2930#if _LIBCPP_STD_VER >= 203132template <class _ToType, class _FromType>33requires(sizeof(_ToType) == sizeof(_FromType) && is_trivially_copyable_v<_ToType> &&34is_trivially_copyable_v<_FromType>)35[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _ToType bit_cast(const _FromType& __from) noexcept {36return __builtin_bit_cast(_ToType, __from);37}3839#endif // _LIBCPP_STD_VER >= 204041_LIBCPP_END_NAMESPACE_STD4243#endif // _LIBCPP___BIT_BIT_CAST_H444546