ipaddress 1.2.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 <set>
24# include <map>
25# include <array>
26# include <tuple>
27# include <cmath>
28# include <vector>
29# include <cassert>
30# include <sstream>
31# include <iomanip>
32# include <cstring>
33# include <numeric>
34# include <iterator>
35# include <algorithm>
36# include <stdexcept>
37# include <type_traits>
38#endif
39
40#ifndef IPADDRESS_NAMESPACE
41# define IPADDRESS_NAMESPACE ipaddress
42#endif
43
44#ifndef IPADDRESS_MODULE
45# define IPADDRESS_EXPORT
46#else
47# define IPADDRESS_EXPORT export
48#endif
49
50#if defined(_MSVC_LANG)
51# define IPADDRESS_CPLUSPLUS _MSVC_LANG
52#else
53# define IPADDRESS_CPLUSPLUS __cplusplus
54#endif
55
56#if 201703L < IPADDRESS_CPLUSPLUS
57# define IPADDRESS_CPP_VERSION 20
58#elif 201402L < IPADDRESS_CPLUSPLUS
59# define IPADDRESS_CPP_VERSION 17
60#elif 201103L < IPADDRESS_CPLUSPLUS
61# define IPADDRESS_CPP_VERSION 14
62#elif 199711L < IPADDRESS_CPLUSPLUS
63# define IPADDRESS_CPP_VERSION 11
64#else
65# error ipaddress needs at least C++ standard version 11
66#endif
67
68#ifdef __cpp_constexpr
69# if __cpp_constexpr >= 201304L
70# define IPADDRESS_CONSTEXPR constexpr
71# else
72# define IPADDRESS_CONSTEXPR
73# endif
74# if __cpp_constexpr >= 201603L
75# define IPADDRESS_CONSTEXPR_17 constexpr
76# else
77# define IPADDRESS_CONSTEXPR_17
78# endif
79#else
80# error ipaddress needs at least C++ standard version 11
81#endif
82
83#if defined(__cpp_consteval) && __cpp_consteval >= 201811L
84# define IPADDRESS_CONSTEVAL consteval
85#else
86# define IPADDRESS_CONSTEVAL IPADDRESS_CONSTEXPR
87#endif
88
89#if defined(_MSC_VER) && (_MSC_VER <= 1800)
90# define IPADDRESS_NOEXCEPT
91#else
92# define IPADDRESS_NOEXCEPT noexcept
93# ifdef IPADDRESS_NO_EXCEPTIONS
94# define IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS noexcept
95# else
96# define IPADDRESS_NOEXCEPT_WHEN_NO_EXCEPTIONS
97# endif
98#endif
99
100#if (IPADDRESS_CPP_VERSION >= 17) && !defined(IPADDRESS_NO_NODISCARD)
101# define IPADDRESS_NODISCARD [[nodiscard]]
102# ifdef IPADDRESS_NO_EXCEPTIONS
103# define IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS [[nodiscard]]
104# else
105# define IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS
106# endif
107#else
108# define IPADDRESS_NODISCARD
109# define IPADDRESS_NODISCARD_WHEN_NO_EXCEPTIONS
110#endif
111
112#ifdef _MSC_VER
113# define IPADDRESS_FORCE_INLINE __forceinline
114#else
115# define IPADDRESS_FORCE_INLINE inline __attribute__((always_inline))
116#endif
117
118#if !defined(IPADDRESS_NO_SPACESHIP_OPERATOR) && defined(__has_include)
119# if (__cpp_lib_three_way_comparison >= 201907L) && __has_include(<compare>)
120# define IPADDRESS_HAS_SPACESHIP_OPERATOR
121# ifndef IPADDRESS_MODULE
122# include <compare>
123# endif
124# endif
125#endif
126
127#if defined(__cpp_nontype_template_parameter_class)
128# define IPADDRESS_NONTYPE_TEMPLATE_PARAMETER
129#elif defined(__cpp_nontype_template_args)
130# if __cpp_nontype_template_args >= 201911L
131# define IPADDRESS_NONTYPE_TEMPLATE_PARAMETER
132# elif __cpp_nontype_template_args >= 201411L && IPADDRESS_CPP_VERSION >= 20
133# if defined(__apple_build_version__)
134# if defined(__clang_major__) && __clang_major__ >= 13
135# define IPADDRESS_NONTYPE_TEMPLATE_PARAMETER
136# endif
137# elif defined(__clang_major__) && __clang_major__ >= 12
138# define IPADDRESS_NONTYPE_TEMPLATE_PARAMETER
139# endif
140# endif
141#endif
142
143#if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
144# define IPADDRESS_IS_CONST_EVALUATED(x) std::is_constant_evaluated()
145#elif (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 9) ||
146 (defined(__clang__) && !defined(__apple_build_version__) && __clang_major__ >= 9) ||
147 (defined(__clang__) && defined(__apple_build_version__) && __clang_major__ >= 11) ||
148 (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1910) ||
149 (defined(_MSC_VER) && _MSC_VER >= 1925)
150# define IPADDRESS_IS_CONST_EVALUATED(x) __builtin_is_constant_evaluated()
151#elif defined(__GNUC__) || defined(__clang__)
152# define IPADDRESS_IS_CONST_EVALUATED(x) __builtin_constant_p(x)
153#else
154# define IPADDRESS_IS_CONST_EVALUATED(x) false
155#endif
156
157#if IPADDRESS_CPP_VERSION >= 17 && !defined(IPADDRESS_MODULE)
158# include <string_view>
159#endif
160
161#if defined(IPADDRESS_NO_IPV6_SCOPE)
162# undef IPADDRESS_IPV6_SCOPE_MAX_LENGTH
163# define IPADDRESS_IPV6_SCOPE_MAX_LENGTH 0
164#elif defined(IPADDRESS_IPV6_SCOPE_MAX_LENGTH)
165# if IPADDRESS_IPV6_SCOPE_MAX_LENGTH < 0
166# undef IPADDRESS_IPV6_SCOPE_MAX_LENGTH
167# define IPADDRESS_IPV6_SCOPE_MAX_LENGTH 0
168# elif IPADDRESS_IPV6_SCOPE_MAX_LENGTH > 64
169# undef IPADDRESS_IPV6_SCOPE_MAX_LENGTH
170# define IPADDRESS_IPV6_SCOPE_MAX_LENGTH 64
171# endif
172#else
173# define IPADDRESS_IPV6_SCOPE_MAX_LENGTH 16
174#endif
175
176#endif // IPADDRESS_CONFIG_HPP
#define IPADDRESS_CPLUSPLUS
Definition config.hpp:53