-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cc
More file actions
48 lines (36 loc) · 1.1 KB
/
test.cc
File metadata and controls
48 lines (36 loc) · 1.1 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
#include <functional>
#include <memory>
#include <typeinfo>
#include <iostream>
#include <stdio.h>
#include <ffi.h>
#include "src/c-callable-closure.hh"
double my_fputs(std::string const & str, double d)
{
puts(str.c_str());
return d;
}
int g;
int & get_g(int x, int y) {
(void) x, (void) y;
return g;
}
int main()
{
std::function<double (std::string const &, double)> my_fputs_wrapper = my_fputs;
ffi_function::CCallableClosure<double (std::string const &, double)>
bound_puts(my_fputs_wrapper);
std::cout << bound_puts.get_func_ptr()("Hello world!", 17.5) << "\n";
std::function<int & (int, int)> return_ref_test = get_g;
ffi_function::CCallableClosure<int & (int, int)>
return_ref_test2(return_ref_test);
std::cout << &(return_ref_test2.get_func_ptr()(1,1)) << "\n";
std::cout << &g << "\n";
auto l = [](int x, int y, int z) { return x*y*z; };
std::function<int (int, int, int)> times = l;
ffi_function::CCallableClosure<int (int, int, int)> times2 = times;
int (*c_ptr)(int, int, int);
c_ptr = times2.get_func_ptr();
std::cout << c_ptr(4,5,7) << "\n";
return 0;
}