-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhellomodule.cpp
More file actions
61 lines (50 loc) · 974 Bytes
/
hellomodule.cpp
File metadata and controls
61 lines (50 loc) · 974 Bytes
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
#include <iostream>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/list.hpp>
#include <boost/python/extract.hpp>
#include "utils.h"
#include <string>
using namespace std;
void say_hello(string name)
{
cout<<"Hello "<<name<<" !\n";
}
template<class T,class U>
const T &add(const U& a,const U& b)
{
return a+b;
}
void print_list(PYTHON_LIST &L)
{
VECTOR_OF_INTS V;
V = list_to_vector(L);
for(size_t i=0; i<V.size();i++)
cout<<V[i]<<" ";
cout<<endl;
cout<<add(2,3)<<endl;
}
VECTOR_OF_INTS _bsort(VECTOR_OF_INTS &V)
{
auto n = V.size();
for(size_t i=0;i<n;i++)
for(size_t j=0;j<n;j++)
if(V[i]<V[j])
swap(V[i],V[j]);
return V;
}
PYTHON_LIST bsort(PYTHON_LIST &L)
{
VECTOR_OF_INTS V;
V = list_to_vector(L);
V = _bsort(V);
L = vector_to_list(V);
return L;
}
using namespace boost::python;
BOOST_PYTHON_MODULE(hello)
{
def("say_hello",say_hello);
def("print_list",print_list);
def("bsort",bsort);
}