ug_misc 0.1
Miscellaneous C++ header library
Loading...
Searching...
No Matches
ug_misc
Author
Larry Chips

A small C++ header library providing miscellaneous utilities. This documentation was generated from the source, and may contain much of that source, which is MIT licenced.

The repository is hosted at Codeberg.

Why

This is mostly stuff that Larry finds useful to have around.

Although it is a lot of hoop-jumping template shenanigans and metaprogramming wankery, its existence is justified, in Larry's opinion, by its ability to keep most of the nonsense within its own headers and not where the templates they provide are actually used.

Luxuries Provided by ugmisc

Feature Tests

The features.hpp header makes the language and library feature tests needed in the other headers more convenient. In addition to a macro for each feature that may be needed, a static constexpr bool member of the Features class is also defined.

The header should just work, but to make sure, you can do some configure-time tests using a build system, an example of which is described here.

Named Type Member Detection

The macros defined in member.hpp allow templates to be declared that can find the first of a sequence of types that contain a member with a certain name, and use that named type or forward arguments to that named static method.

Useful for implementing traits class templates, like the standard library's allocator_traits, which reflect their type parameters' member types or methods if they happen to have them.

Bit Ops

The bitops.hpp header provides C++17 equivalents of the C++20 bit counting functions.

If those functions are available from the standard library, the functions here just forward their arguments to them. Otherwise they use masking operations to home in on the result.

Integer Type Finder

The int_finder.hpp header allows a suitable integer type to be found based on the minimum number of bits required, or an exact number, or a value that needs encoding.

Support for the standard types such as uint16_t is built in, but the user can easily add support for extra builtin types, or their own classes which act like ints. The support works if the integer radix is 2, but the number of digits doesn't have to be a power of 2 (or power of 2 minus 1 for signed ints), as long as the type supports ordinary bitwise operations and has a specialisation of std::numeric_limits.