UgMisc 0.2-110
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-2026 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#ifndef UGMISC_FEATURES_HPP
25#define UGMISC_FEATURES_HPP
26
134
135#ifdef UGMISC_DOCS
136#error "UGMISC_DOCS must be defined for documenting, not compiling."
137#endif
138
139#ifdef UGMISC_DOCS
150#define UGMISC_PREDEFS_HEADER "quoted_header_name"
151#endif
152#ifdef UGMISC_PREDEFS_HEADER
153# include UGMISC_PREDEFS_HEADER
154#endif
155
156
157
158
159/*
160 * I don't want to remember the proper version number everywhere.
161 */
162
163#if __cplusplus >= 202002L
164# define UGMISC_CXX_20 __cplusplus
165#else
166# undef UGMISC_CXX_20
167#endif
168
169#if __cplusplus < 201703L
170# error "features.hpp doesn't bother to work with less than C++17."
171#endif
172
173#ifdef UGMISC_DOCS
182#define UGMISC_HAVE_VERSION
183#endif
184#ifdef __has_include
185# if __has_include(<version>)
186# include <version>
187# endif
188#elif defined(UGMISC_HAVE_VERSION)
189# include <version>
190#endif
191
192#ifdef __has_include
193# define UGMISC_HAS_INCLUDE_OR_IGNORE(...) __has_include(__VA_ARGS__)
194#else
195# define UGMISC_HAS_INCLUDE_OR_IGNORE(...)
196#endif
197
198
199
200
201#ifndef UGMISC_DOCS
202/*
203 * These exist for documentation purposes.
204 * See doc/default_Doxyfile.in: PREDEFINED.
205 *
206 * They allow the feature flags to be defined as true or false at compile time,
207 * but as "compiler and library dependent" in the documentation.
208 */
209#define UGMISC_FEATURE_TRUE true
210#define UGMISC_FEATURE_FALSE false
211#endif
212
213
214
215namespace ugmisc {
216
217
218
219
252
253struct Features {
254 /*
255 * Language features.
256 */
257
258#ifdef UGMISC_DOCS
269# define UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
276# define UGMISC_NO_CONSTEXPR_DESTRUCTORS
277#endif
292#if defined(UGMISC_HAVE_CONSTEXPR_DESTRUCTORS) && defined(UGMISC_NO_CONSTEXPR_DESTRUCTORS)
293# error "Predefines include HAVE_CONSTEXPR_DESTRUCTORS and NO_CONSTEXPR_DESTRUCTORS."
294#endif
295#if !defined(UGMISC_HAVE_CONSTEXPR_DESTRUCTORS) && !defined(UGMISC_NO_CONSTEXPR_DESTRUCTORS)
296# ifdef UGMISC_CXX_20
297# define UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
298# else
299# undef UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
300# endif
301#endif
302#ifdef UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
303 static constexpr bool constexpr_destructors = UGMISC_FEATURE_TRUE;
304#else
305 static constexpr bool constexpr_destructors = UGMISC_FEATURE_FALSE;
306#endif
307
308
309
310
311#ifdef UGMISC_DOCS
316# define UGMISC_HAVE_CONCEPTS
317#endif
318#if __cpp_concepts
319# define UGMISC_HAVE_CONCEPTS
320 static constexpr bool concepts = UGMISC_FEATURE_TRUE;
321#else
322# undef UGMISC_HAVE_CONCEPTS
327 static constexpr bool concepts = UGMISC_FEATURE_FALSE;
328#endif
329
330
331
332
333#ifdef UGMISC_DOCS
338# define UGMISC_HAVE_CONDITIONAL_TRIVIALS
339#endif
340#if __cpp_concepts >= 202002L
341# define UGMISC_HAVE_CONDITIONAL_TRIVIALS
342 static constexpr bool conditional_trivials = UGMISC_FEATURE_TRUE;
343#else
344# undef UGMISC_HAVE_CONDITIONAL_TRIVIALS
349 static constexpr bool conditional_trivials = UGMISC_FEATURE_FALSE;
350#endif
351
352
353
354
355#ifdef UGMISC_DOCS
360# define UGMISC_HAVE_CONSTEVAL
361#endif
362#if __cpp_consteval
363# define UGMISC_HAVE_CONSTEVAL
364 static constexpr bool consteval_functions = UGMISC_FEATURE_TRUE;
365#else
366# undef UGMISC_HAVE_CONSTEVAL
371 static constexpr bool consteval_functions = UGMISC_FEATURE_FALSE;
372#endif
373
374
375
376
377#if UGMISC_DOCS
380# define UGMISC_HAVE_CONSTEVAL_IF
381#endif
386#if __cpp_consteval >= 202211L
387# define UGMISC_HAVE_CONSTEVAL_IF
388 static constexpr bool consteval_if = UGMISC_FEATURE_TRUE;
389#else
390# undef UGMISC_HAVE_CONSTEVAL_IF
391 static constexpr bool consteval_if = UGMISC_FEATURE_FALSE;
392#endif
393
394
395
396
397 /*
398 * Library features.
399 */
400
401
402
403
404#if UGMISC_DOCS
409# define UGMISC_HAVE_BIT_CAST
410#endif
417#if __cpp_lib_bit_cast
418# define UGMISC_HAVE_BIT_CAST
419 static constexpr bool bit_cast = UGMISC_FEATURE_TRUE;
420#else
421# undef UGMISC_HAVE_BIT_CAST
422 static constexpr bool bit_cast = UGMISC_FEATURE_FALSE;
423#endif
424
425
426
427
428#if UGMISC_DOCS
433#define UGMISC_HAVE_BITOPS
434#endif
435#if __cpp_lib_bitops
436# define UGMISC_HAVE_BITOPS
437 static constexpr bool bitops = UGMISC_FEATURE_TRUE;
438#else
439# undef UGMISC_HAVE_BITOPS
444 static constexpr bool bitops = UGMISC_FEATURE_FALSE;
445#endif
446
447
448
449
450#ifdef UGMISC_DOCS
455# define UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
456#endif
457#if __cpp_lib_constexpr_swap_algorithms
458# define UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
459 static constexpr bool constexpr_swap_algorithms = UGMISC_FEATURE_TRUE;
460#else
461# undef UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
466 static constexpr bool constexpr_swap_algorithms = UGMISC_FEATURE_FALSE;
467#endif
468
469
470
471
472#ifdef UGMISC_DOCS
477# define UGMISC_HAVE_UNREACHABLE
478#endif
479#if __cpp_lib_unreachable
480# define UGMISC_HAVE_UNREACHABLE
481 static constexpr bool unreachable = UGMISC_FEATURE_TRUE;
482#else
487 static constexpr bool unreachable = UGMISC_FEATURE_FALSE;
488# undef UGMISC_HAVE_UNREACHABLE
489#endif
490}; // struct Features
491
492
493} /* ::ugmisc */
494
495
496
497
498#ifdef UGMISC_HAVE_UNREACHABLE
499# define UGMISC_unreachable ::std::unreachable
500# include <utility>
501#else
502# define UGMISC_unreachable ::ugmisc::unreachable
503namespace ugmisc {
504[[noreturn]] inline void unreachable() { }
505}
506#endif
507
508
509
510
511/*
512 * This is defined when concepts are supported AND when building documentation.
513 * It is used where there are two declarations of a template and one uses
514 * concepts. We document the one with concepts.
515 */
516#ifdef UGMISC_HAVE_CONCEPTS
517# define UGMISC_USE_CONCEPT_DECLS
518#else
519# undef UGMISC_USE_CONCEPT_DECLS
520#endif
521
522#endif /* UGMISC_FEATURES_HPP */
Definition features.hpp:253
static constexpr bool bit_cast
Definition features.hpp:422
static constexpr bool consteval_if
Definition features.hpp:391
static constexpr bool conditional_trivials
Definition features.hpp:349
static constexpr bool constexpr_destructors
Definition features.hpp:303
static constexpr bool bitops
Definition features.hpp:444
static constexpr bool unreachable
Definition features.hpp:487
static constexpr bool consteval_functions
Definition features.hpp:371
static constexpr bool concepts
Definition features.hpp:327
static constexpr bool constexpr_swap_algorithms
Definition features.hpp:466