-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoke.cpp
57 lines (44 loc) · 1.07 KB
/
Invoke.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* \file main.cpp
* \brief std::invoke
*
* \todo
*
* Invoke a Callable object with parameters. Examples of Callable objects are std::function or
* std::bind where an object can be called similarly to a regular function.
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
template <typename Callable>
class Proxy
{
public:
Proxy(Callable c): c(c)
{
}
template <class... Args>
decltype(auto) operator()(Args&&... args)
{
// ...
return std::invoke(c, std::forward<Args>(args)...);
}
private:
Callable c;
};
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
auto add = [](int x, int y)
{
return x + y;
};
Proxy<decltype(add)> p {add};
p(1, 2); // == 3
// std::cout << STD_TRACE_VAR("") << std::endl;
return EXIT_SUCCESS;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
#endif