A small C++ header library providing miscellaneous utilities, compatible with C++17 and all later versions. The repository is hosted at Codeberg.
Sample programs will soon be available, to demonstrate library usage.
New reflection features coming to C++26 will make most likely use cases of member.hpp obsolete.
The macro defined in member.hpp allows types to be declared which can find a named member of a type or object, or in a sequence of types or objects.
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.
Here is a little example:
The value of foo_val will be the first of the following which is valid:
There are also ways to use your new member_foo accessor type to find and call a static or non-static method which accepts certain arguments, or to find a member type from a sequence of types.
In all cases a fallback default can be used. See member.hpp for a full explanation.
The typelist.hpp header defines a type_list template, which defines lists of types, and a number of templates for manipulating them.
List of types can be concatenated, and sliced. They can have some of their types filtered out, or converted into other types.
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.
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.
The features.hpp header is mainly there to support the other headers. In addition to a macro for each feature that may be needed by those headers, a static constexpr bool member of the Features class is defined.
Most of the features are simply the features that are indicated by __cpp_* macros, but some have to be guessed. 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.