Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
TClosure.h
Go to the documentation of this file.
1#pragma once
2#include <functional>
3
4namespace sf
5{
6
12template<typename Result, typename... Args>
14{
15 public:
19 typedef std::function<Result(Args...)> func_type;
20
24 TClosure() = default;
25
29 TClosure(const TClosure& c);
30
34 explicit TClosure(const func_type& fn);
35
40
63 template<typename ClassType, typename MethodType, typename... BoundArgs>
64 TClosure& assign(ClassType* cls, MethodType mtd, BoundArgs... args);
65
70
75
80
86 Result operator()(Args... args) const;
87
91 [[nodiscard]] bool isAssigned() const;
92
96 explicit operator bool() const;
97
98 protected:
104 Result call(Args... args) const;
105
106 private:
110 func_type _func{nullptr};
111};
112
113}// namespace sf
114
115// Include all inlined functions and template implementations.
116#include <misc/gen/TClosure.hpp>
Encapsulates the std::function() template.
Definition TClosure.h:14
std::function< Result(Args...)> func_type
Function type of the lambda or function.
Definition TClosure.h:19
Result call(Args... args) const
Makes the call to the member function.
TClosure & operator=(const func_type &f)
Closure assignment operator.
TClosure(const TClosure &c)
Copy constructor.
TClosure(const func_type &fn)
Function assignment constructor.
bool isAssigned() const
Checks if the closure is valid for calling.
TClosure & operator=(const TClosure &c)
Closure assignment operator.
Result operator()(Args... args) const
Make the call to the member function.
TClosure & assign(const func_type &fn)
Function assignment method for static function.
TClosure()=default
Default constructor.
TClosure & unassign()
Releases the bind function.
TClosure & assign(ClassType *cls, MethodType mtd, BoundArgs... args)
Binds a non-static class member function to this instance.
Definition Application.h:10