Utilities
Utilities header only library
OnEnd.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef UTILS_ON_END_H
7 #define UTILS_ON_END_H
8 #include <functional>
9 
10 namespace utils
11 {
35  class OnEnd
36  {
37  public:
39  using Callback = std::function<void()>;
40 
42  explicit OnEnd(Callback F)
43  : F_(F)
44  {
45  }
46 
49  {
50  F_();
51  }
52 
53  // No copying permitted.
54  OnEnd(const OnEnd &) = delete;
55  OnEnd &operator=(const OnEnd &) = delete;
56  OnEnd(OnEnd &&) = delete;
57  OnEnd &operator=(OnEnd &&) = delete;
58 
59  private:
60  Callback F_;
61  };
62 }
63 #endif /* !UTILS_ON_END_H */
Helper class that performs an action when it is destroyed.
Definition: OnEnd.h:35
std::function< void()> Callback
Callback is a void function taking 0 arguments.
Definition: OnEnd.h:39
General namespace for utilities.
Definition: BulletConversions.h:9
OnEnd(Callback F)
Constructor sets Callback.
Definition: OnEnd.h:42
~OnEnd()
Destructor calls Callback.
Definition: OnEnd.h:48