Skip to content

Instantly share code, notes, and snippets.

@neov5
neov5 / endianint.hpp
Created October 26, 2024 20:26
endianness-maintaining integers in 100 lines of C++(20)
#include <cstdint>
#include <type_traits>
#include <bit>
using namespace std;
template <endian E, typename T, typename Enable = std::enable_if_t<std::is_integral_v<T>>> class endianint;
static_assert(endian::native == endian::little or endian::native == endian::big,
"Mixed endian machines are not supported");