使用boost.python实现python调用c++代码
编写c++代码后,编译成动态链接库,然后python可以直接调用
参考http://www.boost.org/doc/libs/1_61_0/libs/python/doc/html/index.html
代码中实现了python参数,到c++参数的转化,可以把一个python的可迭代对象转化成c++中的list map vector等
就像python基础教程上写的,python开发中最完美的就是关键代码用c++,这样兼具性能和开发效率!!
下面是c++代码:
#include <vector>
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/python.hpp>
using namespace std;
bool align(string a, string b) {
vector<int> left;
vector<int> right;
string spChar(",\t ");
vector<string> splitResult;
boost::split(splitResult, a, boost::is_any_of(spChar));
BOOST_FOREACH(std::string& s, splitResult) {
boost::trim(s);
left.push_back(boost::le