config.hpp
Go to the documentation of this file.
1 // Copyright (C) 2020-2024 Jonathan Müller and lexy contributors
2 // SPDX-License-Identifier: BSL-1.0
3 
4 #ifndef LEXY_DETAIL_CONFIG_HPP_INCLUDED
5 #define LEXY_DETAIL_CONFIG_HPP_INCLUDED
6 
7 #include <cstddef>
8 #include <type_traits>
9 
10 #if defined(LEXY_USER_CONFIG_HEADER)
11 # include LEXY_USER_CONFIG_HEADER
12 #elif defined(__has_include)
13 # if __has_include(<lexy_user_config.hpp>)
14 # include <lexy_user_config.hpp>
15 # elif __has_include("lexy_user_config.hpp")
16 # include "lexy_user_config.hpp"
17 # endif
18 #endif
19 
20 #ifndef LEXY_HAS_UNICODE_DATABASE
21 # define LEXY_HAS_UNICODE_DATABASE 0
22 #endif
23 
24 #ifndef LEXY_EXPERIMENTAL
25 # define LEXY_EXPERIMENTAL 0
26 #endif
27 
28 //=== utility traits===//
29 #define LEXY_MOV(...) static_cast<std::remove_reference_t<decltype(__VA_ARGS__)>&&>(__VA_ARGS__)
30 #define LEXY_FWD(...) static_cast<decltype(__VA_ARGS__)>(__VA_ARGS__)
31 
32 #define LEXY_DECLVAL(...) lexy::_detail::declval<__VA_ARGS__>()
33 
34 #define LEXY_DECAY_DECLTYPE(...) std::decay_t<decltype(__VA_ARGS__)>
35 
38 #define LEXY_INSTANTIATION_NEWTYPE(Name, Templ, ...) \
39  struct Name : Templ<__VA_ARGS__> \
40  { \
41  using Templ<__VA_ARGS__>::Templ; \
42  }
43 
44 namespace lexy::_detail
45 {
46 template <typename... T>
47 constexpr bool error = false;
48 
49 template <typename T>
50 std::add_rvalue_reference_t<T> declval();
51 
52 template <typename T>
53 constexpr void swap(T& lhs, T& rhs)
54 {
55  T tmp = LEXY_MOV(lhs);
56  lhs = LEXY_MOV(rhs);
57  rhs = LEXY_MOV(tmp);
58 }
59 
60 template <typename T, typename U>
61 constexpr bool is_decayed_same = std::is_same_v<std::decay_t<T>, std::decay_t<U>>;
62 
63 template <typename T, typename Fallback>
64 using type_or = std::conditional_t<std::is_void_v<T>, Fallback, T>;
65 } // namespace lexy::_detail
66 
67 //=== NTTP ===//
68 #ifndef LEXY_HAS_NTTP
69 // See https://github.com/foonathan/lexy/issues/15.
70 # if __cpp_nontype_template_parameter_class >= 201806 || __cpp_nontype_template_args >= 201911
71 # define LEXY_HAS_NTTP 1
72 # else
73 # define LEXY_HAS_NTTP 0
74 # endif
75 #endif
76 
77 #if LEXY_HAS_NTTP
78 # define LEXY_NTTP_PARAM auto
79 #else
80 # define LEXY_NTTP_PARAM const auto&
81 #endif
82 
83 //=== consteval ===//
84 #ifndef LEXY_HAS_CONSTEVAL
85 # if defined(_MSC_VER) && !defined(__clang__)
86 // Currently can't handle returning strings from consteval, check back later.
87 # define LEXY_HAS_CONSTEVAL 0
88 # elif __cpp_consteval
89 # define LEXY_HAS_CONSTEVAL 1
90 # else
91 # define LEXY_HAS_CONSTEVAL 0
92 # endif
93 #endif
94 
95 #if LEXY_HAS_CONSTEVAL
96 # define LEXY_CONSTEVAL consteval
97 #else
98 # define LEXY_CONSTEVAL constexpr
99 #endif
100 
101 //=== constexpr ===//
102 #ifndef LEXY_HAS_CONSTEXPR_DTOR
103 # if __cpp_constexpr_dynamic_alloc
104 # define LEXY_HAS_CONSTEXPR_DTOR 1
105 # else
106 # define LEXY_HAS_CONSTEXPR_DTOR 0
107 # endif
108 #endif
109 
110 #if LEXY_HAS_CONSTEXPR_DTOR
111 # define LEXY_CONSTEXPR_DTOR constexpr
112 #else
113 # define LEXY_CONSTEXPR_DTOR
114 #endif
115 
116 //=== char8_t ===//
117 #ifndef LEXY_HAS_CHAR8_T
118 # if __cpp_char8_t
119 # define LEXY_HAS_CHAR8_T 1
120 # else
121 # define LEXY_HAS_CHAR8_T 0
122 # endif
123 #endif
124 
125 #if LEXY_HAS_CHAR8_T
126 
127 # define LEXY_CHAR_OF_u8 char8_t
128 # define LEXY_CHAR8_T char8_t
129 # define LEXY_CHAR8_STR(Str) u8##Str
130 
131 #else
132 
133 namespace lexy
134 {
135 using _char8_t = unsigned char;
136 } // namespace lexy
137 
138 # define LEXY_CHAR_OF_u8 char
139 # define LEXY_CHAR8_T ::lexy::_char8_t
140 # define LEXY_CHAR8_STR(Str) \
141  LEXY_NTTP_STRING(::lexy::_detail::type_string, u8##Str)::c_str<LEXY_CHAR8_T>
142 
143 #endif
144 
145 //=== endianness ===//
146 #ifndef LEXY_IS_LITTLE_ENDIAN
147 # if defined(__BYTE_ORDER__)
148 # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
149 # define LEXY_IS_LITTLE_ENDIAN 1
150 # elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
151 # define LEXY_IS_LITTLE_ENDIAN 0
152 # else
153 # error "unsupported byte order"
154 # endif
155 # elif defined(_MSC_VER)
156 # define LEXY_IS_LITTLE_ENDIAN 1
157 # else
158 # error "unknown endianness"
159 # endif
160 #endif
161 
162 //=== force inline ===//
163 #ifndef LEXY_FORCE_INLINE
164 # if defined(__has_cpp_attribute)
165 # if __has_cpp_attribute(gnu::always_inline)
166 # define LEXY_FORCE_INLINE [[gnu::always_inline]]
167 # endif
168 # endif
169 #
170 # ifndef LEXY_FORCE_INLINE
171 # define LEXY_FORCE_INLINE inline
172 # endif
173 #endif
174 
175 //=== empty_member ===//
176 #ifndef LEXY_EMPTY_MEMBER
177 
178 # if defined(__has_cpp_attribute)
179 # if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 11
180 // GCC <= 11 has buggy support, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101040
181 # define LEXY_HAS_EMPTY_MEMBER 0
182 # elif __has_cpp_attribute(no_unique_address)
183 # define LEXY_HAS_EMPTY_MEMBER 1
184 # endif
185 # endif
186 # ifndef LEXY_HAS_EMPTY_MEMBER
187 # define LEXY_HAS_EMPTY_MEMBER 0
188 # endif
189 
190 # if LEXY_HAS_EMPTY_MEMBER
191 # define LEXY_EMPTY_MEMBER [[no_unique_address]]
192 # else
193 # define LEXY_EMPTY_MEMBER
194 # endif
195 
196 #endif
197 
198 #endif // LEXY_DETAIL_CONFIG_HPP_INCLUDED
199 
LEXY_MOV
#define LEXY_MOV(...)
Definition: config.hpp:29
lexy::_detail::type_or
std::conditional_t< std::is_void_v< T >, Fallback, T > type_or
Definition: config.hpp:64
lexy
Definition: any_ref.hpp:12
lexy::error
Generic failure.
Definition: error.hpp:14
lexy::_detail::swap
constexpr void swap(T &lhs, T &rhs)
Definition: config.hpp:53
lexy::_detail::is_decayed_same
constexpr bool is_decayed_same
Definition: config.hpp:61
lexy::_detail
Definition: any_ref.hpp:12
lexy::_char8_t
unsigned char _char8_t
Definition: config.hpp:135
lexy::_detail::declval
std::add_rvalue_reference_t< T > declval()


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Nov 1 2024 02:20:50