-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinds.cpp
41 lines (33 loc) · 843 Bytes
/
binds.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
/*
Unify functions with arguments
and store in a vector
https://ideone.com/0G2u7i
*/
#include <iostream>
#include <vector>
#include <functional>
static void fn1(int x, int y)
{
std::cout << x << " " << y << std::endl;
}
static void fn2(int x, int *y, double z)
{
std::cout << x << " " << *y << " " << z << std::endl;
}
static void fn3(const char* x, bool y)
{
std::cout << x << " " << std::boolalpha << y << std::endl;
}
int main()
{
std::vector<std::function<void()>> binds;
int i = 20;
binds.push_back(std::bind(&fn1, 1, 2));
binds.push_back(std::bind(&fn1, 3, 4));
binds.push_back(std::bind(&fn2, 1, &i, 3.99999));
binds.push_back(std::bind(&fn2, 3, &i, 0.8971233921));
binds.push_back(std::bind(&fn3, "test1", true));
binds.push_back(std::bind(&fn3, "test2", false));
for (auto const &fn : binds) fn();
return 0;
}