blob: db10786e214decd578c9baca5677790629613195 [file] [log] [blame]
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02001#pragma once
2
3#include <memory>
4#include <utility>
5
6namespace utils
7{
8
9class UniqueCall
10{
11 public:
12 struct Lock
13 {};
14
15 template <class Functor, class... Args>
16 void operator()(Functor&& functor, Args&&... args)
17 {
18 if (lock.expired())
19 {
20 auto l = std::make_shared<Lock>();
21 lock = l;
22 functor(std::move(l), std::forward<Args>(args)...);
23 }
24 }
25
26 private:
27 std::weak_ptr<Lock> lock;
28};
29
30} // namespace utils