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