Various useful bits of c++
This is header only C++ library for doing useful things. Such as printing human
readable type names, converting string_view
s to numbers. See the Currently
available targets section for detail.
All files are in individual directories under include
.
Documentation can be found at the top of each file.
The easiest way to include libut
in your CMake
project is with
fetch_content
.
Simply add the following to your CMakeLists.txt
:
include(FetchContent)
# Set the directory to download dependencies to. Avoids putting them in $buildDir
set(FETCHCONTENT_BASE_DIR "${PROJECT_SOURCE_DIR}/_deps")
FetchContent_Declare(
libut
GIT_REPOSITORY https://github.com/dk949/libut/
GIT_TAG trunk # alternatively you can use a hash to pin exact venison to use
)
FetchContent_MakeAvailable(libut)
# assuming MY_TARGET is a valid target (executable or library)
target_link_libraries(MY_TARGET UT::target_name)
UT::ptr_containers
: containers for storing owning pointersUT::check
: type which prints when it is constructed/copied/moved/destructedUT::pair
: a betterstd::pair
implementationUT::add_noexcept
: add thenoexcept
specifier to a function typeUT::sv_to_num
: convertstd::string_view
to a numberUT::copy_traits
: copy cvref qualifiers from one type to anotherUT::realloc_unique_ptr
:realloc
functionality forstd::uniqur_ptr
UT::assert
: various assertion macrosUT::resource
: a more general version ofstd::unique_ptr
that operates on valuesUT::demangle
: convert types into human readable stringsUT::constexpr_hash
: a hashing function usable inconstexpr
contextUT::trim
: trim characters from start and end of astd::string_view
UT::pack_loops
: loop over variadic template parametersUT::static_string
: compile time known string usable as a template parameterUT::mt_queue
: thread safe FIFO queueUT::curry
: create a curried function out of a regular functionUT::defer
: a macro to defer execution until the scope endsUT::print
: macros for printing usingstd::format
in c++20
A special target UT::all
is also available, combining all of the above.
Test can be ran using Catch2
git clone https://github.com/Microsoft/vcpkg.git
./vcpkg/bootstrap-vcpkg.sh -disableMetrics
./vcpkg/vcpkg install catch2
cmake --preset local
cmake --build build
./build/tests/libut_tests
# or
ctest --output-on-failure --test-dir build/tests
NOTE: you can use the local
preset to build with
ninja, or default
to build with the default
generator (e.g. "Unix Makefiles" on Linux)
The files included as gists, the license is included in the file (usually at the
bottom). For all other files, see LICENSE
in the root of this repo.