- Notifications
You must be signed in to change notification settings - Fork12
Modern C++ generic header-only template library.
License
nyorain/nytl
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A lightweight and generic header-only template library for C++17.Includes various utility of all kind that i needed across multiple projects:
- Extremely lightweightvector andmatrix templates
- Simple utf conversion and utf8 parsing helpers:nytl/utf.hpp
- ACallback implementation for high-level and fast function callbacks.
- Also a more functionalRecursiveCallback
- Easily make virtual classes cloneable:nytl/clone.hpp
- Pseudo-RAII handling with scope guards:nytl/scope.hpp
- Lightweight and independent span template:nytl/span.hpp
- Combining c++ class enums into flags:nytl/flags.hpp
All headers were written as modular, independent and generic as possible. Mostutilities can be used indenpendently from each other. The only requireddependency is a compiler supporting full C++17 and its stl (this means no suppportfor msvc at the moment).All files are licensed under the Boost License.
Contributions to library, tests, documentation, examples as well asall suggestions and ideas are always appreciated.Just start a pull request or an issue ongithub.
There are multiple ways to use nytl. Either install all of its headers on your system and makesure the install path can be found by the compiler.If you need just a few header files (or even just a few functions), just copy those files intoyour project folder.It can also be used as meson subproject.
Remember that nytl requires a solid C++17 compiler, only recent versions of gcc and clangare tested.Below some basic code examples for (only a) few nytl features to give you an idea.
Callbacks mirror the signal/slot principle in modern c++ with many useful features.For the full documentation, seenytl/callback.hpp.If you want to modify (call/register/disconnect) the callback fromwithin a handler, seenytl/recursiveCallback.hpp.
// Example callbackauto onEvent = nytl::RecursiveCallback<void()> {};// Adds a callback listenerauto connection = onEvent.add([]{ std::cout <<"called\n"; });connection.disconnect();// unregisters the listeneronEvent = &foo;// sets foo as only listeneronEvent += []{};// same as onEvent.add// listener functions can also take an additional Connection argument that// allows them to unregister themself from within the listeneronEvent += [&](nytl::Connection selfConnection) {selfConnection.disconnect();// will unregister itself on first callonEvent += &bar;// one can also add new listeners from inside a listener};onEvent();// calls all registered listener functionsonEvent.call();// can also be done more explicit
ScopeGuards are another utility concept implemented by nytl. The mirror finally syntax fromother languages and allow safe RAII-like handling of non-RAII resources.For the full documentation, seenytl/scope.hpp.
// open a file descriptor we want to close later onauto fd = ::open("test.txt");// create a scope guard that will execute the passed functions as soon// as this scope is left, no matter in which way. Makes closing the fd// exception safe and also more maintainable since early returns can be// added without having to care about the fd.auto fdGuard = nytl::ScopeGuard([&]{ ::close(fd); })// there are also classes that only execute the passed functions if the// scope was left normally or due to an exceptionauto successGuard = nytl::SuccessGuard([&]{ std::cout <<"scope left normally\n"; });auto exceptionGuard = nytl::ExceptionGuard([&]{ std::cout <<"exception thrown\n"; });
About
Modern C++ generic header-only template library.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors2
Uh oh!
There was an error while loading.Please reload this page.