Iros
 
Loading...
Searching...
No Matches
byteswap.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/meta/language.h"
4#include "di/meta/util.h"
6
7namespace di::bit {
8namespace detail {
10 template<concepts::IntegralOrEnum T>
12 constexpr auto operator()(T value) const -> T {
13 if constexpr (concepts::Enum<T>) {
14 return T((*this)(util::to_underlying(value)));
15 } else {
16 if constexpr (sizeof(T) == 1) {
17 return value;
18 } else if constexpr (sizeof(T) == 2) {
19 return __builtin_bswap16(value);
20 } else if constexpr (sizeof(T) == 4) {
21 return __builtin_bswap32(value);
22 } else if constexpr (sizeof(T) == 8) {
23 return __builtin_bswap64(value);
24 }
25#ifdef DI_HAVE_128_BIT_INTEGERS
26 else if constexpr (sizeof(T) == 16) {
27 return __builtin_bswap128(value);
28 }
29#endif
30 else {
31 static_assert(concepts::AlwaysFalse<T>);
32 }
33 }
34 }
35 };
36}
37
38constexpr inline auto byteswap = detail::ByteswapFunction {};
39}
40
41namespace di {
42using bit::byteswap;
43}
This concept is used with static_assert() to cause the static assert to fail only when the template h...
Definition core.h:98
Definition language.h:259
Definition bit_proxy_reference.h:5
Definition bit_proxy_reference.h:5
constexpr auto byteswap
Definition byteswap.h:38
constexpr auto to_underlying
Definition to_underlying.h:15
Definition zstring_parser.h:9
Definition byteswap.h:9