ugmisc 0.2-76
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
131
132#ifdef UGMISC_DOCS
133#error "UGMISC_DOCS must be defined for documenting, not compiling."
134#endif
135
136#ifdef UGMISC_DOCS
147#define UGMISC_PREDEFS_HEADER "quoted_header_name"
148#endif
149#ifdef UGMISC_PREDEFS_HEADER
150# include UGMISC_PREDEFS_HEADER
151#endif
152
153
154
155
156/*
157 * I don't want to remember the proper version number everywhere.
158 */
159
160#if __cplusplus >= 202002L
161# define UGMISC_CXX_20 __cplusplus
162#else
163# undef UGMISC_CXX_20
164#endif
165
166#if __cplusplus < 201703L
167# error "features.hpp doesn't bother to work with less than C++17."
168#endif
169
170#ifdef UGMISC_DOCS
179#define UGMISC_HAVE_VERSION
180#endif
181#ifdef __has_include
182# if __has_include(<version>)
183# include <version>
184# endif
185#elif defined(UGMISC_HAVE_VERSION)
186# include <version>
187#endif
188
189#ifdef __has_include
190# define UGMISC_HAS_INCLUDE_OR_IGNORE(...) __has_include(__VA_ARGS__)
191#else
192# define UGMISC_HAS_INCLUDE_OR_IGNORE(...)
193#endif
194
195
196
197
198#ifndef UGMISC_DOCS
199/*
200 * These exist for documentation purposes.
201 * See doc/default_Doxyfile.in: PREDEFINED.
202 *
203 * They allow the feature flags to be defined as true or false at compile time,
204 * but as "compiler and library dependent" in the documentation.
205 */
206#define UGMISC_FEATURE_TRUE true
207#define UGMISC_FEATURE_FALSE false
208#endif
209
210
211
212namespace ugmisc {
213
214
215
216
249
250struct Features {
251 /*
252 * Language features.
253 */
254
255#ifdef UGMISC_DOCS
266# define UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
273# define UGMISC_NO_CONSTEXPR_DESTRUCTORS
274#endif
289#if defined(UGMISC_HAVE_CONSTEXPR_DESTRUCTORS) && defined(UGMISC_NO_CONSTEXPR_DESTRUCTORS)
290# error "Predefines include HAVE_CONSTEXPR_DESTRUCTORS and NO_CONSTEXPR_DESCTRUCTORS."
291#endif
292#if !defined(UGMISC_HAVE_CONSTEXPR_DESTRUCTORS) && !defined(UGMISC_NO_CONSTEXPR_DESTRUCTORS)
293# ifdef UGMISC_CXX_20
294# define UGMISC_HAVE_CONSTEXPR_DESCTRUCTORS
295# else
296# undef UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
297# endif
298#endif
299#ifdef UGMISC_HAVE_CONSTEXPR_DESTRUCTORS
300 static constexpr bool constexpr_destructors = UGMISC_FEATURE_TRUE;
301#else
302 static constexpr bool constexpr_destructors = UGMISC_FEATURE_FALSE;
303#endif
304
305
306
307
308#ifdef UGMISC_DOCS
313# define UGMISC_HAVE_CONSTEVAL
314#endif
315#if __cpp_consteval
316# define UGMISC_HAVE_CONSTEVAL
317 static constexpr bool consteval_functions = UGMISC_FEATURE_TRUE;
318#else
319# undef UGMISC_HAVE_CONSTEVAL
324 static constexpr bool consteval_functions = UGMISC_FEATURE_FALSE;
325#endif
326
327
328
329
330#if UGMISC_DOCS
333# define UGMISC_HAVE_CONSTEVAL_IF
334#endif
339#if __cpp_consteval >= 202211L
340# define UGMISC_HAVE_CONSTEVAL_IF
341 static constexpr bool consteval_if = UGMISC_FEATURE_TRUE;
342#else
343# undef UGMISC_HAVE_CONSTEVAL_IF
344 static constexpr bool consteval_if = UGMISC_FEATURE_FALSE;
345#endif
346
347
348
349
350 /*
351 * Library features.
352 */
353
354
355
356
357#if UGMISC_DOCS
362# define UGMISC_HAVE_BIT_CAST
363#endif
370#if __cpp_lib_bit_cast
371# define UGMISC_HAVE_BIT_CAST
372 static constexpr bool bit_cast = UGMISC_FEATURE_TRUE;
373#else
374# undef UGMISC_HAVE_BIT_CAST
375 static constexpr bool bit_cast = UGMISC_FEATURE_FALSE;
376#endif
377
378
379
380
381#if UGMISC_DOCS
386#define UGMISC_HAVE_BITOPS
387#endif
388#if __cpp_lib_bitops
389# define UGMISC_HAVE_BITOPS
390 static constexpr bool bitops = UGMISC_FEATURE_TRUE;
391#else
392# undef UGMISC_HAVE_BITOPS
397 static constexpr bool bitops = UGMISC_FEATURE_FALSE;
398#endif
399
400
401
402
403#ifdef UGMISC_DOCS
408# define UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
409#endif
410#if __cpp_lib_constexpr_swap_algorithms
411# define UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
412 static constexpr bool constexpr_swap_algorithms = UGMISC_FEATURE_TRUE;
413#else
414# undef UGMISC_HAVE_CONSTEXPR_SWAP_ALGORITHMS
419 static constexpr bool constexpr_swap_algorithms = UGMISC_FEATURE_FALSE;
420#endif
421
422
423
424
425#ifdef UGMISC_DOCS
430# define UGMISC_HAVE_UNREACHABLE
431#endif
432#if __cpp_lib_unreachable
433# define UGMISC_HAVE_UNREACHABLE
434# define UGMISC_UNREACHABLE std::unreachable();
435 static constexpr bool unreachable = UGMISC_FEATURE_TRUE;
436#else
441 static constexpr bool unreachable = UGMISC_FEATURE_FALSE;
442# undef UGMISC_HAVE_UNREACHABLE
443#endif
444}; // struct Features
445
446
447} /* ::ugmisc */
448
449
450
451
452#ifdef UGMISC_HAVE_UNREACHABLE
453# define UGMISC_unreachable std::unreachable
454# include <utility>
455#else
456# define UGMISC_unreachable ::ugmisc::unreachable
457[[noreturn]] inline void unreachable() { }
458#endif
Definition features.hpp:250
static constexpr bool bit_cast
Definition features.hpp:375
static constexpr bool consteval_if
Definition features.hpp:344
static constexpr bool constexpr_destructors
Definition features.hpp:300
static constexpr bool bitops
Definition features.hpp:397
static constexpr bool unreachable
Definition features.hpp:441
static constexpr bool consteval_functions
Definition features.hpp:324
static constexpr bool constexpr_swap_algorithms
Definition features.hpp:419