mini-llvm 0.1.0
Loading...
Searching...
No Matches
BitCast.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <bit>
6#include <concepts>
7#include <cstdlib>
8
9namespace mini_llvm::ops {
10
11template <typename To>
12struct BitCast {
13 template <typename From>
14 To operator()(From) const noexcept {
15 abort();
16 }
17
18 template <typename From>
19 requires (!std::same_as<From, bool> && sizeof(To) == sizeof(From))
20 To operator()(From x) const noexcept {
21 return std::bit_cast<To>(x);
22 }
23};
24
25template <>
26struct BitCast<bool> {
27 template <typename From>
28 bool operator()(From) const noexcept {
29 abort();
30 }
31
32 bool operator()(bool x) const noexcept {
33 return x;
34 }
35};
36
37} // namespace mini_llvm::ops
Definition Add.h:9
bool operator()(bool x) const noexcept
Definition BitCast.h:32
bool operator()(From) const noexcept
Definition BitCast.h:28
Definition BitCast.h:12
To operator()(From) const noexcept
Definition BitCast.h:14