qxLib
destruction_callback.h
Go to the documentation of this file.
1 /**
2 
3  @file destruction_callback.h
4  @author Khrapov
5  @date 12.12.2021
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 #pragma once
10 
12 
13 namespace qx
14 {
15 
16 /**
17 
18  @class destruction_callback
19  @brief Class for RAII: functor passed in constructor will be called in destructor
20  @author Khrapov
21  @date 12.12.2021
22 
23 **/
24 class [[nodiscard]] destruction_callback
25 {
26 public:
27  using destroyer = std::function<void()>;
28 
29 public:
32 
33  destruction_callback() noexcept = default;
34 
35  /**
36  @brief destruction_callback object constructor
37  @param _destroyer - functor that will be called when object will be destroyed
38  **/
39  destruction_callback(destroyer _destroyer) : m_Destroyer(std::move(_destroyer))
40  {
41  }
42 
44  {
45  if (m_Destroyer)
46  m_Destroyer();
47  }
48 
49 private:
50  destroyer m_Destroyer;
51 };
52 
53 } // namespace qx
Class for RAII: functor passed in constructor will be called in destructor.
destruction_callback(destroyer _destroyer)
destruction_callback object constructor
#define QX_NONCOPYABLE(className)
Define class as non copyable.
#define QX_MOVABLE(className)
Define class as default movable.