ug_misc 0.1
Miscellaneous C++ header library
Loading...
Searching...
No Matches
features.hpp
Go to the documentation of this file.
1/*
2 * SPDX-Licence-Identifier: MIT
3 *
4 * Copyright 2025 Larry Chips
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the “Software”), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#pragma once
25
71
142
143#ifdef UGMISC_DOCS
144#error "UGMISC_DOCS must be defined for documenting, not compiling."
145#endif
146
147#ifdef UGMISC_DOCS
158#define UGMISC_PREDEFS_HEADER "quoted_header_name"
159#endif
160#ifdef UGMISC_PREDEFS_HEADER
161# include UGMISC_PREDEFS_HEADER
162#endif
163
164
165
166
167/*
168 * I don't want to remember the proper version number everywhere.
169 */
170
171#if __cplusplus >= 202002L
172# define UGMISC_CXX_20 __cplusplus
173#else
174# undef UGMISC_CXX_20
175#endif
176
177#if __cplusplus < 201703L
178# error "features.hpp doesn't bother to work with less than C++17."
179#endif
180
181#ifdef UGMISC_DOCS
190#define UGMISC_HAVE_VERSION
191#endif
192#ifdef __has_include
193# if __has_include(<version>)
194# include <version>
195# endif
196#elif defined(UGMISC_HAVE_VERSION)
197# include <version>
198#endif
199
200#ifdef __has_include
201# define UGMISC_HAS_INCLUDE_OR_IGNORE(...) __has_include(__VA_ARGS__)
202#else
203# define UGMISC_HAS_INCLUDE_OR_IGNORE(...)
204#endif
205
206
207
208
209#ifndef UGMISC_FEATURE_TRUE
210/*
211 * These exist for documentation purposes.
212 * See doc/default_Doxyfile.in: PREDEFINED.
213 *
214 * They allow the feature flags to be defined as true or false at compile time,
215 * but as "compiler and library dependent" in the documentation.
216 */
217#define UGMISC_FEATURE_TRUE true
218#define UGMISC_FEATURE_FALSE false
219#endif
220
221
222
223namespace ugmisc {
224
225
226
227
260
261struct Features {
262 /*
263 * Language features.
264 */
265
266#ifdef UGMISC_DOCS
277# define UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
284# define UGMISC_NO_CONSTEXPR_DESTRUCTORS
285#endif
300#if defined(UGMISC_HAVE_CONSTEXPR_DESTRUCTORS) && defined(UGMISC_NO_CONSTEXPR_DESTRUCTORS)
301# error "Predefines include HAVE_CONSTEXPR_DESTRUCTORS and NO_CONSTEXPR_DESCTRUCTORS."
302#endif
303#if !defined(UGMISC_HAVE_CONSTEXPR_DESTRUCTORS) && !defined(UGMISC_NO_CONSTEXPR_DESTRUCTORS)
304# ifdef UGMISC_CXX_20
305# define UGMISC_HAVE_CONSTEXPR_DESCTRUCTORS
306# else
307# undef UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
308# endif
309#endif
310#ifdef UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
311 static constexpr bool constexpr_destructors = UGMISC_FEATURE_TRUE;
312#else
313 static constexpr bool constexpr_destructors = UGMISC_FEATURE_FALSE;
314#endif
315
316
317
318
319#ifdef UGMISC_DOCS
324# define UGMISC_HAVE_CONSTEVAL
325#endif
326#if __cpp_consteval
327# define UGMISC_HAVE_CONSTEVAL
328 static constexpr bool consteval_functions = UGMISC_FEATURE_TRUE;
329#else
330# undef UGMISC_HAVE_CONSTEVAL
335 static constexpr bool consteval_functions = UGMISC_FEATURE_FALSE;
336#endif
337
338
339
340
341#if UGMISC_DOCS
344# define UGMISC_HAVE_CONSTEVAL_IF
345#endif
350#if __cpp_consteval >= 202211L
351# define UGMISC_HAVE_CONSTEVAL_IF
352 static constexpr bool consteval_if = UGMISC_FEATURE_TRUE;
353#else
354# undef UGMISC_HAVE_CONSTEVAL_IF
355 static constexpr bool consteval_if = UGMISC_FEATURE_FALSE;
356#endif
357
358
359
360
361 /*
362 * Library features.
363 */
364
365
366
367
368#if UGMISC_DOCS
373# define UGMISC_HAVE_BIT_CAST
374#endif
381#if __cpp_lib_bit_cast
382# define UGMISC_HAVE_BIT_CAST
383 static constexpr bool bit_cast = UGMISC_FEATURE_TRUE;
384#else
385# undef UGMISC_HAVE_BIT_CAST
386 static constexpr bool bit_cast = UGMISC_FEATURE_FALSE;
387#endif
388
389
390
391
392#if UGMISC_DOCS
397#define UGMISC_HAVE_BITOPS
398#endif
399#if __cpp_lib_bitops
400# define UGMISC_HAVE_BITOPS
401 static constexpr bool bitops = UGMISC_FEATURE_TRUE;
402#else
403# undef UGMISC_HAVE_BITOPS
408 static constexpr bool bitops = UGMISC_FEATURE_FALSE;
409#endif
410
411
412
413
414#ifdef UGMISC_DOCS
419# define UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
420#endif
421#if __cpp_lib_constexpr_swap_algorithms
422# define UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
423 static constexpr bool constexpr_swap_algorithms = UGMISC_FEATURE_TRUE;
424#else
425# undef UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
430 static constexpr bool constexpr_swap_algorithms = UGMISC_FEATURE_FALSE;
431#endif
432}; // struct Features
433
434
435
436
437} /* ::ugmisc */
Definition features.hpp:261
static constexpr bool bit_cast
Definition features.hpp:386
static constexpr bool consteval_if
Definition features.hpp:355
static constexpr bool constexpr_destructors
Definition features.hpp:311
static constexpr bool bitops
Definition features.hpp:408
static constexpr bool consteval_functions
Definition features.hpp:335
static constexpr bool constexpr_swap_algorithms
Definition features.hpp:430