-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (61 loc) · 1.38 KB
/
main.cpp
File metadata and controls
76 lines (61 loc) · 1.38 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <dlfcn.h>
#include <string>
#include <iostream>
class DLloader
{
public:
DLloader(const std::string &path) : _handle(dlopen(path.c_str(), RTLD_GLOBAL | RTLD_NOW))
{
if (_handle == nullptr)
throw std::runtime_error("Woops");
}
~DLloader() { dlclose(_handle); }
template<typename T, typename ...Args>
T execute(const std::string &name, const Args &...args)
{
auto ret = dlsym(_handle, name.c_str());
auto func = (T(*)(const Args &...))ret;
return func(args...);
}
private:
void *_handle;
};
#include "Serializable.hpp"
struct Child : public Serializable<Child, Output>
{
Child() : Serializable(&Child::toto) {}
std::string toto = "biteuh";
};
struct MyOutput
{
template<typename Obj>
static void serializeMember(std::ostream &s, const Obj &member)
{
s << "Member:" << member << std::endl;
}
};
class Toto : public Serializable<Toto, MyOutput>
{
public:
Toto() : Serializable(&Toto::x, &Toto::y, &Toto::c),
x(42), y(84)
{}
public:
int x;
int y;
Child c;
};
#include "for_each.hpp"
int main()
{
/* Toto t;
std::cout << t << std::endl;
Toto t2 = t;
t2.x = 12;
std::cout << t2 << std::endl;*/
auto t = std::make_tuple("Toto", 42);
for_each(t, [](const auto ¶m)
{
std::cout << param << std::endl;
});
}