JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Finally Class Reference

Helper class which calls a function when being destroyed. More...

#include <jngl/Finally.hpp>

Public Member Functions

 Finally (std::function< void()> functionToCall)
 functionToCall will be moved into the member with the same name More...
 
 Finally (Finally &&) noexcept
 The moved-from Finally object will no longer call the function.
 
Finallyoperator= (Finally &&) noexcept
 The moved-from Finally object will no longer call the function.
 
 Finally (const Finally &)=delete
 
Finallyoperator= (const Finally &)=delete
 
 ~Finally ()
 Calls the function which has been passed into the constructor.
 

Detailed Description

Helper class which calls a function when being destroyed.

Useful when using C interfaces without the need to write a wrapper class. For example:

void foo() {
FILE* f = fopen("foo.txt", "r");
Finally _([f]() { fclose(f); };
// ...
}
Helper class which calls a function when being destroyed.
Definition: Finally.hpp:22

Definition at line 22 of file Finally.hpp.

Constructor & Destructor Documentation

◆ Finally()

Finally ( std::function< void()>  functionToCall)
explicit

functionToCall will be moved into the member with the same name

You can pass nullptr to do nothing.


The documentation for this class was generated from the following file: