JNGL
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
 
 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); };
// ...
}
Finally(std::function< void()> functionToCall)
functionToCall will be moved into the member with the same name
T fclose(T... args)
T fopen(T... args)

Definition at line 22 of file Finally.hpp.


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