ipaddress 1.1.0
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1/**
2 * @file config.hpp
3 * @brief Defines macros for library configuration
4 * @author Vladimir Shaleev
5 * @copyright MIT License
6 *
7 * This header file contains a collection of preprocessor macros that are essential
8 * for configuring the library to work across various platforms and compilers.
9 * It also ensures compatibility with different versions of the C++ language standard.
10 * The macros facilitate feature detection and conditional compilation, which are
11 * crucial for maintaining cross-platform and cross-compiler support.
12 *
13 * Overall, `config.hpp` serves as the backbone for the library's adaptability and
14 * robustness in varied development environments.
15 */
16
17#ifndef IPADDRESS_CONFIG_HPP
18#define IPADDRESS_CONFIG_HPP
19
20#ifndef IPADDRESS_MODULE
21# include <cstdint>
22# include <cstddef>
23# include <array>
24# include <tuple>
25# include <cmath>
26# include <cassert>
27# include <sstream>
28# include <iomanip>
29# include <cstring>
30# include <numeric>
31# include <iterator>
32# include <algorithm>
33# include <stdexcept>
34# include <type_traits>
35#endif
36
37#ifndef IPADDRESS_NAMESPACE
38# define IPADDRESS_NAMESPACE ipaddress
39#endif
40
41#ifndef IPADDRESS_MODULE
42# define IPADDRESS_EXPORT
43#else
44# define IPADDRESS_EXPORT export
45#endif
46
47#if defined(_MSVC_LANG)
48# define IPADDRESS_CPLUSPLUS _MSVC_LANG
49#else
50# define IPADDRESS_CPLUSPLUS __cplusplus
51#endif
52
53#if 201703L < IPADDRESS_CPLUSPLUS
54# define IPADDRESS_CPP_VERSION 20
55#elif 201402L < IPADDRESS_CPLUSPLUS
56# define IPADDRESS_CPP_VERSION 17
57#elif 201103L < IPADDRESS_CPLUSPLUS
58# define IPADDRESS_CPP_VERSION 14
59#elif 199711L < IPADDRESS_CPLUSPLUS
60# define IPADDRESS_CPP_VERSION 11
61#else
62# error ipaddress needs at least C++ standard version 11
63#endif
64
65#ifdef __cpp_constexpr
66# if __cpp_constexpr >= 201304L
67# define IPADDRESS_CONSTEXPR constexpr
68# else
69# define IPADDRESS_CONSTEXPR
70# endif
71# if __cpp_constexpr >= 201603L
72# define IPADDRESS_CONSTEXPR_17 constexpr
73# else
74# define IPADDRESS_CONSTEXPR_17
75# endif
76#else
77# error ipaddress needs at least C++ standard version 11
78#endif
79
80#if defined(__cpp_consteval) && __cpp_consteval >= 201811L
81# define IPADDRESS_CONSTEVAL consteval
82#else
83# define IPADDRESS_CONSTEVAL IPADDRESS_CONSTEXPR
84#endif
85
86#if defined(_MSC_VER) && (_MSC_VER <= 1800)
87# define IPADDRESS_NOEXCEPT
88#else
89# define IPADDRESS_NOEXCEPT noexcept
90# ifdef IPADDRESS_NO_EXCEPTIONS
91# define IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS noexcept
92# else
93# define IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS
94# endif
95#endif
96
97#if (IPADDRESS_CPP_VERSION >= 17) && !defined(IPADDRESS_NO_NODISCARD)
98# define IPADDRESS_NODISCARD [[nodiscard]]
99# ifdef IPADDRESS_NO_EXCEPTIONS
100# define IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS [[nodiscard]]
101# else
102# define IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS
103# endif
104#else
105# define IPADDRESS_NODISCARD
106# define IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS
107#endif
108
109#ifdef _MSC_VER
110# define IPADDRESS_FORCE_INLINE __forceinline
111#else
112# define IPADDRESS_FORCE_INLINE inline __attribute__((always_inline))
113#endif
114
115#if !defined(IPADDRESS_NO_SPACESHIP_OPERATOR) && defined(__has_include)
116# if (__cpp_lib_three_way_comparison >= 201907L) && __has_include(<compare>)
117# define IPADDRESS_HAS_SPACESHIP_OPERATOR
118# ifndef IPADDRESS_MODULE
119# include <compare>
120# endif
121# endif
122#endif
123
124#if defined(__cpp_nontype_template_parameter_class)
125# define IPADDRESS_NONTYPE_TEMPLATE_PARAMETER
126#elif defined(__cpp_nontype_template_args)
127# if __cpp_nontype_template_args >= 201911L
128# define IPADDRESS_NONTYPE_TEMPLATE_PARAMETER
129# elif __cpp_nontype_template_args >= 201411L && IPADDRESS_CPP_VERSION >= 20
130# if defined(__apple_build_version__)
131# if defined(__clang_major__) && __clang_major__ >= 13
132# define IPADDRESS_NONTYPE_TEMPLATE_PARAMETER
133# endif
134# elif defined(__clang_major__) && __clang_major__ >= 12
135# define IPADDRESS_NONTYPE_TEMPLATE_PARAMETER
136# endif
137# endif
138#endif
139
140#if __cpp_lib_is_constant_evaluated >= 201811L
141# define IPADDRESS_IS_CONST_EVALUATED(x) std::is_constant_evaluated()
142#elif __GNUC__ >= 9
143# define IPADDRESS_IS_CONST_EVALUATED(x) __builtin_is_constant_evaluated()
144#elif __GNUC__ >= 6
145# define IPADDRESS_IS_CONST_EVALUATED(x) __builtin_constant_p(x)
146#else
147# define IPADDRESS_IS_CONST_EVALUATED(x) false
148#endif
149
150#if IPADDRESS_CPP_VERSION >= 17 && !defined(IPADDRESS_MODULE)
151# include <string_view>
152#endif
153
154#if defined(IPADDRESS_NO_IPV6_SCOPE)
155# undef IPADDRESS_IPV6_SCOPE_MAX_LENGTH
156# define IPADDRESS_IPV6_SCOPE_MAX_LENGTH 0
157#elif defined(IPADDRESS_IPV6_SCOPE_MAX_LENGTH)
158# if IPADDRESS_IPV6_SCOPE_MAX_LENGTH < 0
159# undef IPADDRESS_IPV6_SCOPE_MAX_LENGTH
160# define IPADDRESS_IPV6_SCOPE_MAX_LENGTH 0
161# elif IPADDRESS_IPV6_SCOPE_MAX_LENGTH > 64
162# undef IPADDRESS_IPV6_SCOPE_MAX_LENGTH
163# define IPADDRESS_IPV6_SCOPE_MAX_LENGTH 64
164# endif
165#else
166# define IPADDRESS_IPV6_SCOPE_MAX_LENGTH 16
167#endif
168
169#endif // IPADDRESS_CONFIG_HPP
#define IPADDRESS_CPLUSPLUS
Definition config.hpp:50