UgMisc 0.3
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
119
120#ifdef UGMISC_DOCS
121#error "UGMISC_DOCS must be defined for documenting, not compiling."
122#endif
123
124#ifdef UGMISC_DOCS
135#define UGMISC_PREDEFS_HEADER "quoted_header_name"
136#endif
137#ifdef UGMISC_PREDEFS_HEADER
138# include UGMISC_PREDEFS_HEADER
139#endif
140
141
142
143
144/*
145 * I don't want to remember the proper version number everywhere.
146 */
147
148#if __cplusplus >= 202002L
149# define UGMISC_CXX_20 __cplusplus
150#else
151# undef UGMISC_CXX_20
152#endif
153
154#if __cplusplus < 201703L
155# error "features.hpp doesn't bother to work with less than C++17."
156#endif
157
158#ifdef UGMISC_DOCS
167#define UGMISC_HAVE_VERSION
168#endif
169#ifdef __has_include
170# if __has_include(<version>)
171# include <version>
172# endif
173#elif defined(UGMISC_HAVE_VERSION)
174# include <version>
175#endif
176
177#ifdef __has_include
178# define UGMISC_HAS_INCLUDE_OR_IGNORE(...) __has_include(__VA_ARGS__)
179#else
180# define UGMISC_HAS_INCLUDE_OR_IGNORE(...)
181#endif
182
183
184
185
186#ifndef UGMISC_DOCS
187/*
188 * These exist for documentation purposes.
189 * See doc/default_Doxyfile.in: PREDEFINED.
190 *
191 * They allow the feature flags to be defined as true or false at compile time,
192 * but as "compiler and library dependent" in the documentation.
193 */
194#define UGMISC_FEATURE_TRUE true
195#define UGMISC_FEATURE_FALSE false
196#endif
197
198
199
200namespace ugmisc {
201
202
203
204
237
238struct Features {
239 /*
240 * Language features.
241 */
242
243#ifdef UGMISC_DOCS
254# define UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
261# define UGMISC_NO_CONSTEXPR_DESTRUCTORS
262#endif
277#if defined(UGMISC_HAVE_CONSTEXPR_DESTRUCTORS) && defined(UGMISC_NO_CONSTEXPR_DESTRUCTORS)
278# error "Predefines include HAVE_CONSTEXPR_DESTRUCTORS and NO_CONSTEXPR_DESTRUCTORS."
279#endif
280#if !defined(UGMISC_HAVE_CONSTEXPR_DESTRUCTORS) && !defined(UGMISC_NO_CONSTEXPR_DESTRUCTORS)
281# ifdef UGMISC_CXX_20
282# define UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
283# else
284# undef UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
285# endif
286#endif
287#ifdef UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
288 static constexpr bool constexpr_destructors = UGMISC_FEATURE_TRUE;
289#else
290 static constexpr bool constexpr_destructors = UGMISC_FEATURE_FALSE;
291#endif
292
293
294
295
296#ifdef UGMISC_DOCS
301# define UGMISC_HAVE_CONCEPTS
302#endif
303#if __cpp_concepts
304# define UGMISC_HAVE_CONCEPTS
305 static constexpr bool concepts = UGMISC_FEATURE_TRUE;
306#else
307# undef UGMISC_HAVE_CONCEPTS
312 static constexpr bool concepts = UGMISC_FEATURE_FALSE;
313#endif
314
315
316
317
318#ifdef UGMISC_DOCS
323# define UGMISC_HAVE_CONDITIONAL_TRIVIALS
324#endif
325#if __cpp_concepts >= 202002L
326# define UGMISC_HAVE_CONDITIONAL_TRIVIALS
327 static constexpr bool conditional_trivials = UGMISC_FEATURE_TRUE;
328#else
329# undef UGMISC_HAVE_CONDITIONAL_TRIVIALS
334 static constexpr bool conditional_trivials = UGMISC_FEATURE_FALSE;
335#endif
336
337
338
339
340#ifdef UGMISC_DOCS
345# define UGMISC_HAVE_CONSTEVAL
346#endif
347#if __cpp_consteval
348# define UGMISC_HAVE_CONSTEVAL
349 static constexpr bool consteval_functions = UGMISC_FEATURE_TRUE;
350#else
351# undef UGMISC_HAVE_CONSTEVAL
356 static constexpr bool consteval_functions = UGMISC_FEATURE_FALSE;
357#endif
358
359
360
361
362#if UGMISC_DOCS
365# define UGMISC_HAVE_CONSTEVAL_IF
366#endif
371#if __cpp_consteval >= 202211L
372# define UGMISC_HAVE_CONSTEVAL_IF
373 static constexpr bool consteval_if = UGMISC_FEATURE_TRUE;
374#else
375# undef UGMISC_HAVE_CONSTEVAL_IF
376 static constexpr bool consteval_if = UGMISC_FEATURE_FALSE;
377#endif
378
379
380
381
382 /*
383 * Library features.
384 */
385
386
387
388
389#if UGMISC_DOCS
394# define UGMISC_HAVE_BIT_CAST
395#endif
402#if __cpp_lib_bit_cast
403# define UGMISC_HAVE_BIT_CAST
404 static constexpr bool bit_cast = UGMISC_FEATURE_TRUE;
405#else
406# undef UGMISC_HAVE_BIT_CAST
407 static constexpr bool bit_cast = UGMISC_FEATURE_FALSE;
408#endif
409
410
411
412
413#if UGMISC_DOCS
418#define UGMISC_HAVE_BITOPS
419#endif
420#if __cpp_lib_bitops
421# define UGMISC_HAVE_BITOPS
422 static constexpr bool bitops = UGMISC_FEATURE_TRUE;
423#else
424# undef UGMISC_HAVE_BITOPS
429 static constexpr bool bitops = UGMISC_FEATURE_FALSE;
430#endif
431
432
433
434
435#ifdef UGMISC_DOCS
440# define UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
441#endif
442#if __cpp_lib_constexpr_swap_algorithms
443# define UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
444 static constexpr bool constexpr_swap_algorithms = UGMISC_FEATURE_TRUE;
445#else
446# undef UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
451 static constexpr bool constexpr_swap_algorithms = UGMISC_FEATURE_FALSE;
452#endif
453
454
455
456
457#ifdef UGMISC_DOCS
462# define UGMISC_HAVE_UNREACHABLE
463#endif
464#if __cpp_lib_unreachable
465# define UGMISC_HAVE_UNREACHABLE
466 static constexpr bool unreachable = UGMISC_FEATURE_TRUE;
467#else
472 static constexpr bool unreachable = UGMISC_FEATURE_FALSE;
473# undef UGMISC_HAVE_UNREACHABLE
474#endif
475}; // struct Features
476
477
478} /* ::ugmisc */
479
480
481
482
483#ifdef UGMISC_HAVE_UNREACHABLE
484# define UGMISC_unreachable ::std::unreachable
485# include <utility>
486#else
487# define UGMISC_unreachable ::ugmisc::unreachable
488namespace ugmisc {
489[[noreturn]] inline void unreachable() { }
490}
491#endif
492
493
494
495
496/*
497 * This is defined when concepts are supported AND when building documentation.
498 * It is used where there are two declarations of a template and one uses
499 * concepts. We document the one with concepts.
500 */
501#ifdef UGMISC_HAVE_CONCEPTS
502# define UGMISC_USE_CONCEPT_DECLS
503#else
504# undef UGMISC_USE_CONCEPT_DECLS
505#endif
506
507#endif /* UGMISC_FEATURES_HPP */
static constexpr bool bit_cast
Definition features.hpp:407
static constexpr bool consteval_if
Definition features.hpp:376
static constexpr bool conditional_trivials
Definition features.hpp:334
static constexpr bool constexpr_destructors
Definition features.hpp:288
static constexpr bool bitops
Definition features.hpp:429
static constexpr bool unreachable
Definition features.hpp:472
static constexpr bool consteval_functions
Definition features.hpp:356
static constexpr bool concepts
Definition features.hpp:312
static constexpr bool constexpr_swap_algorithms
Definition features.hpp:451