Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Modern C++ generic header-only template library.

License

NotificationsYou must be signed in to change notification settings

nyorain/nytl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

459 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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:

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.

Contributing

Contributions to library, tests, documentation, examples as well asall suggestions and ideas are always appreciated.Just start a pull request or an issue ongithub.

Using nytl

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.

nytl::Callback and nytl::RecursiveCallback

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

nytl::ScopeGuard

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

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2026 Movatter.jp