UgMisc
A miscellaneous header-only C++ library, compatible with C++17 and later standards.
Even though the headers work with C++17, they will use C++20 concepts if they are available, so that compiler error messages will be clearer.
The repository is currently hosted at codeberg.org.
Contents
Overview
Utilities provided include:
-
Manipulate lists of types. Concatenate, take strided subarrays, apply metafunctions to each type, etc.
-
Find integers which can encode a set of values, according to flags indicating how signed or unsigned types should be selected. Can easily work with custom integer classes, and supports the standard ones (uint8_t, int16_t, etc) out of the box.
-
Search through a list of types or objects for a named member. Works for typedefs and for static and non-static data members and methods, including overloaded methods.
#include <ugmisc/member.hpp> UGMISC_DECL_MEMBER_ACCESS(Foo, foo); // Declares Foo. // Foo is a type that searches for members named "foo". using F = ugmisc::static_member_caller<Foo, X, Y, Z>; F::call(args...); // Error if X, Y, and Z don't have a static method called "foo". // Instances of F are callable. F f; f.call(args...); // Same as F::call(args...). f(args...); // Same as F::call(args...). // Default value: // The following two expressions are equivalent. F::fallback( func )(args...); f.fallback( func )(args...);
In the fallback example above, the first valid expression is evaluated:
-
X::foo(args...) -
std::invoke(X::foo, args...) -
Y::foo(args...) -
std::invoke(Y::foo, args...) -
Z::foo(args...) -
std::invoke(Z::foo, args...) -
func(args...) -
std::invoke(func, args...) -
func()
-
-
C++20 style bit operations, like count left zeros, are supported in C++17, using bit mask operations.
Calls to the bit op functions will forward to the standard library functions if they exist, and fall back to using bitwise ANDs otherwise. The fallback function works with anything that acts enough like a radix-2 unsigned integer and has a std::numeric_limits specialisation.