The GenericRAII class is a simple helper class to apply the C++ RAII idiom quickly. You set 2 functions, one which is called in the constructor and another function is called in the destructor which can be useful when handling resources.
More...
#include <iceoryx_hoofs/cxx/generic_raii.hpp>
|
| GenericRAII (const std::function< void()> &cleanupFunction) noexcept |
| constructor which creates GenericRAII that calls only the cleanupFunction on destruction More...
|
|
| GenericRAII (const function_ref< void()> &initFunction, const std::function< void()> &cleanupFunction) noexcept |
| constructor which calls initFunction and stores the cleanupFunction which will be called in the destructor More...
|
|
| ~GenericRAII () noexcept |
| calls m_cleanupFunction callable if it was set in the constructor
|
|
| GenericRAII (const GenericRAII &)=delete |
|
GenericRAII & | operator= (const GenericRAII &)=delete |
|
| GenericRAII (GenericRAII &&rhs) noexcept |
| move constructor which moves a generic raii object without calling the cleanupFunction
|
|
GenericRAII & | operator= (GenericRAII &&rhs) noexcept |
| move assignment which moves a generic raii object without calling the cleanupFunction
|
|
The GenericRAII class is a simple helper class to apply the C++ RAII idiom quickly. You set 2 functions, one which is called in the constructor and another function is called in the destructor which can be useful when handling resources.
void someFunc() {
auto raii{[](){ std::cout << "hello world\n"; },
[](){ std::cout << "goodbye\n"; }};
std::cout << "I am doing stuff\n";
}
◆ GenericRAII() [1/2]
iox::cxx::GenericRAII::GenericRAII |
( |
const std::function< void()> & |
cleanupFunction | ) |
|
|
explicitnoexcept |
constructor which creates GenericRAII that calls only the cleanupFunction on destruction
- Parameters
-
[in] | cleanupFunction | callable which will be called in the destructor |
◆ GenericRAII() [2/2]
iox::cxx::GenericRAII::GenericRAII |
( |
const function_ref< void()> & |
initFunction, |
|
|
const std::function< void()> & |
cleanupFunction |
|
) |
| |
|
noexcept |
constructor which calls initFunction and stores the cleanupFunction which will be called in the destructor
- Parameters
-
[in] | initFunction | callable which will be called in the constructor |
[in] | cleanupFunction | callable which will be called in the destructor |
The documentation for this class was generated from the following file: