MCPcopy Create free account
hub / github.com/andreasfertig/programming-with-cpp20 / ReverseBytes

Function ReverseBytes

10.03-byteSwap0/main.cpp:12–19  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10# include <utility>
11
12constexpr auto ReverseBytes(std::integral auto value)
13{
14 return [&]<size_t... I>(std::index_sequence<I...>) -> decltype(value) {
15 return (
16 (((value >> I * 8) & 0xff) << ((8 * sizeof(value)) - ((1 + I) * 8))) |
17 ...);
18 }(std::make_index_sequence<sizeof(value)>{});
19}
20
21constexpr auto ByteSwap(std::integral auto value)
22{

Callers 1

ByteSwapFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected