UgMisc 0.2-128
Miscellaneous C++ header library
Loading...
Searching...
No Matches
features.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: © 2025 Larry Chips <larry@larrychips.net>
3 * SPDX-Licence-Identifier: MIT
4 */
5#ifndef UGMISC_FEATURES_HPP
6#define UGMISC_FEATURES_HPP
7
115
116#ifdef UGMISC_DOCS
117#error "UGMISC_DOCS must be defined for documenting, not compiling."
118#endif
119
120#ifdef UGMISC_DOCS
131#define UGMISC_PREDEFS_HEADER "quoted_header_name"
132#endif
133#ifdef UGMISC_PREDEFS_HEADER
134# include UGMISC_PREDEFS_HEADER
135#endif
136
137
138
139
140/*
141 * I don't want to remember the proper version number everywhere.
142 */
143
144#if __cplusplus >= 202002L
145# define UGMISC_CXX_20 __cplusplus
146#else
147# undef UGMISC_CXX_20
148#endif
149
150#if __cplusplus < 201703L
151# error "features.hpp doesn't bother to work with less than C++17."
152#endif
153
154#ifdef UGMISC_DOCS
163#define UGMISC_HAVE_VERSION
164#endif
165#ifdef __has_include
166# if __has_include(<version>)
167# include <version>
168# endif
169#elif defined(UGMISC_HAVE_VERSION)
170# include <version>
171#endif
172
173#ifdef __has_include
174# define UGMISC_HAS_INCLUDE_OR_IGNORE(...) __has_include(__VA_ARGS__)
175#else
176# define UGMISC_HAS_INCLUDE_OR_IGNORE(...)
177#endif
178
179
180
181
182#ifndef UGMISC_DOCS
183/*
184 * These exist for documentation purposes.
185 * See doc/default_Doxyfile.in: PREDEFINED.
186 *
187 * They allow the feature flags to be defined as true or false at compile time,
188 * but as "compiler and library dependent" in the documentation.
189 */
190#define UGMISC_FEATURE_TRUE true
191#define UGMISC_FEATURE_FALSE false
192#endif
193
194
195
196namespace ugmisc {
197
198
199
200
233
234struct Features {
235 /*
236 * Language features.
237 */
238
239#ifdef UGMISC_DOCS
250# define UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
257# define UGMISC_NO_CONSTEXPR_DESTRUCTORS
258#endif
273#if defined(UGMISC_HAVE_CONSTEXPR_DESTRUCTORS) && defined(UGMISC_NO_CONSTEXPR_DESTRUCTORS)
274# error "Predefines include HAVE_CONSTEXPR_DESTRUCTORS and NO_CONSTEXPR_DESTRUCTORS."
275#endif
276#if !defined(UGMISC_HAVE_CONSTEXPR_DESTRUCTORS) && !defined(UGMISC_NO_CONSTEXPR_DESTRUCTORS)
277# ifdef UGMISC_CXX_20
278# define UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
279# else
280# undef UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
281# endif
282#endif
283#ifdef UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
284 static constexpr bool constexpr_destructors = UGMISC_FEATURE_TRUE;
285#else
286 static constexpr bool constexpr_destructors = UGMISC_FEATURE_FALSE;
287#endif
288
289
290
291
292#ifdef UGMISC_DOCS
297# define UGMISC_HAVE_CONCEPTS
298#endif
299#if __cpp_concepts
300# define UGMISC_HAVE_CONCEPTS
301 static constexpr bool concepts = UGMISC_FEATURE_TRUE;
302#else
303# undef UGMISC_HAVE_CONCEPTS
308 static constexpr bool concepts = UGMISC_FEATURE_FALSE;
309#endif
310
311
312
313
314#ifdef UGMISC_DOCS
319# define UGMISC_HAVE_CONDITIONAL_TRIVIALS
320#endif
321#if __cpp_concepts >= 202002L
322# define UGMISC_HAVE_CONDITIONAL_TRIVIALS
323 static constexpr bool conditional_trivials = UGMISC_FEATURE_TRUE;
324#else
325# undef UGMISC_HAVE_CONDITIONAL_TRIVIALS
330 static constexpr bool conditional_trivials = UGMISC_FEATURE_FALSE;
331#endif
332
333
334
335
336#ifdef UGMISC_DOCS
341# define UGMISC_HAVE_CONSTEVAL
342#endif
343#if __cpp_consteval
344# define UGMISC_HAVE_CONSTEVAL
345 static constexpr bool consteval_functions = UGMISC_FEATURE_TRUE;
346#else
347# undef UGMISC_HAVE_CONSTEVAL
352 static constexpr bool consteval_functions = UGMISC_FEATURE_FALSE;
353#endif
354
355
356
357
358#if UGMISC_DOCS
361# define UGMISC_HAVE_CONSTEVAL_IF
362#endif
367#if __cpp_consteval >= 202211L
368# define UGMISC_HAVE_CONSTEVAL_IF
369 static constexpr bool consteval_if = UGMISC_FEATURE_TRUE;
370#else
371# undef UGMISC_HAVE_CONSTEVAL_IF
372 static constexpr bool consteval_if = UGMISC_FEATURE_FALSE;
373#endif
374
375
376
377
378 /*
379 * Library features.
380 */
381
382
383
384
385#if UGMISC_DOCS
390# define UGMISC_HAVE_BIT_CAST
391#endif
398#if __cpp_lib_bit_cast
399# define UGMISC_HAVE_BIT_CAST
400 static constexpr bool bit_cast = UGMISC_FEATURE_TRUE;
401#else
402# undef UGMISC_HAVE_BIT_CAST
403 static constexpr bool bit_cast = UGMISC_FEATURE_FALSE;
404#endif
405
406
407
408
409#if UGMISC_DOCS
414#define UGMISC_HAVE_BITOPS
415#endif
416#if __cpp_lib_bitops
417# define UGMISC_HAVE_BITOPS
418 static constexpr bool bitops = UGMISC_FEATURE_TRUE;
419#else
420# undef UGMISC_HAVE_BITOPS
425 static constexpr bool bitops = UGMISC_FEATURE_FALSE;
426#endif
427
428
429
430
431#ifdef UGMISC_DOCS
436# define UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
437#endif
438#if __cpp_lib_constexpr_swap_algorithms
439# define UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
440 static constexpr bool constexpr_swap_algorithms = UGMISC_FEATURE_TRUE;
441#else
442# undef UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
447 static constexpr bool constexpr_swap_algorithms = UGMISC_FEATURE_FALSE;
448#endif
449
450
451
452
453#ifdef UGMISC_DOCS
458# define UGMISC_HAVE_UNREACHABLE
459#endif
460#if __cpp_lib_unreachable
461# define UGMISC_HAVE_UNREACHABLE
462 static constexpr bool unreachable = UGMISC_FEATURE_TRUE;
463#else
468 static constexpr bool unreachable = UGMISC_FEATURE_FALSE;
469# undef UGMISC_HAVE_UNREACHABLE
470#endif
471}; // struct Features
472
473
474} /* ::ugmisc */
475
476
477
478
479#ifdef UGMISC_HAVE_UNREACHABLE
480# define UGMISC_unreachable ::std::unreachable
481# include <utility>
482#else
483# define UGMISC_unreachable ::ugmisc::unreachable
484namespace ugmisc {
485[[noreturn]] inline void unreachable() { }
486}
487#endif
488
489
490
491
492/*
493 * This is defined when concepts are supported AND when building documentation.
494 * It is used where there are two declarations of a template and one uses
495 * concepts. We document the one with concepts.
496 */
497#ifdef UGMISC_HAVE_CONCEPTS
498# define UGMISC_USE_CONCEPT_DECLS
499#else
500# undef UGMISC_USE_CONCEPT_DECLS
501#endif
502
503#endif /* UGMISC_FEATURES_HPP */
Definition features.hpp:234
static constexpr bool bit_cast
Definition features.hpp:403
static constexpr bool consteval_if
Definition features.hpp:372
static constexpr bool conditional_trivials
Definition features.hpp:330
static constexpr bool constexpr_destructors
Definition features.hpp:284
static constexpr bool bitops
Definition features.hpp:425
static constexpr bool unreachable
Definition features.hpp:468
static constexpr bool consteval_functions
Definition features.hpp:352
static constexpr bool concepts
Definition features.hpp:308
static constexpr bool constexpr_swap_algorithms
Definition features.hpp:447