2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
28#ifndef IPADDRESS_ENDIAN_HPP
29#define IPADDRESS_ENDIAN_HPP
33#if (IPADDRESS_CPP_VERSION
>= 20
) && defined(__has_include
)
34# if __has_include(<bit>)
35# define IPADDRESS_HAS_STD_ENDIAN
36# ifndef IPADDRESS_MODULE
42#define IPADDRESS_LITTLE_ENDIAN 0
43#define IPADDRESS_BIG_ENDIAN 1
45#ifndef IPADDRESS_ENDIAN
48# if __BYTE_ORDER__
== __ORDER_LITTLE_ENDIAN__
50# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
51# define IPADDRESS_ENDIAN IPADDRESS_BIG_ENDIAN
53# error Unknown endianness detected. Needs to define IPADDRESS_ENDIAN
56# elif defined(__GLIBC__) && !defined(IPADDRESS_MODULE)
58# if (__BYTE_ORDER == __LITTLE_ENDIAN)
59# define IPADDRESS_ENDIAN IPADDRESS_LITTLE_ENDIAN
60# elif (__BYTE_ORDER == __BIG_ENDIAN)
61# define IPADDRESS_ENDIAN IPADDRESS_BIG_ENDIAN
63# error Unknown endianness detected. Needs to define IPADDRESS_ENDIAN
66# elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
67# define IPADDRESS_ENDIAN IPADDRESS_LITTLE_ENDIAN
68# elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
69# define IPADDRESS_ENDIAN IPADDRESS_BIG_ENDIAN
71# elif defined(__hppa) ||
73 defined(__powerpc__) ||
80# define IPADDRESS_ENDIAN IPADDRESS_BIG_ENDIAN
81# elif defined(__alpha__) ||
88 defined(__x86_64__) ||
95# define IPADDRESS_ENDIAN IPADDRESS_LITTLE_ENDIAN
96# elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
97# define IPADDRESS_ENDIAN IPADDRESS_LITTLE_ENDIAN
98# elif !defined(IPADDRESS_HAS_STD_ENDIAN)
99# error Unknown endianness detected. Needs to define IPADDRESS_ENDIAN
106
107
108
109
111#if defined(IPADDRESS_HAS_STD_ENDIAN)
112 return std::endian::native == std::endian::little;
113#elif defined(IPADDRESS_ENDIAN
)
114 return !IPADDRESS_ENDIAN;
116# error Unknown endianness detected. Needs to define IPADDRESS_ENDIAN
121
122
123
124
125
127 value = ((value << 8) & 0xFF00FF00) | ((value >> 8) & 0x00FF00FF);
128 value = (value << 16) | (value >> 16);
#define IPADDRESS_EXPORT
Definition config.hpp:42
#define IPADDRESS_NODISCARD
Definition config.hpp:98
#define IPADDRESS_FORCE_INLINE
Definition config.hpp:112
#define IPADDRESS_NAMESPACE
Definition config.hpp:38
#define IPADDRESS_NOEXCEPT
Definition config.hpp:89
#define IPADDRESS_LITTLE_ENDIAN
Definition endian.hpp:42
constexpr inline bool is_little_endian() noexcept
Checks if the system is little-endian.
Definition endian.hpp:110
constexpr inline uint32_t swap_bytes(uint32_t value) noexcept
Swaps the bytes of a 32-bit unsigned integer.
Definition endian.hpp:126