一、第一种方式
1.安装
# sudo apt-get install libboost-dev
2.测试
#include<iostream>
#include<boost/bind.hpp>
using namespace std;
using namespace boost;
int fun(int x,int y){return x+y;}
int main(){
int m=1;int n=2;
cout<< "x + y = " << boost::bind(fun,_1,_2)(m,n)<<endl;
return 0;
}
二、第二种方式
1.安装依赖库
# sudo apt install mpi-default-dev libicu-devlibbz2-dev
2.下载boost源码
https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.7z
3.解压后安装
# sudo ./bootstrap.sh
# ./b2 //编译
# ./b2 headers //生成头文件
4.测试
# emacs test.cpp
#include<iostream>
#include<boost/bind.hpp>
using namespace std;
using namespace boost;
int fun(int x,int y){return x+y;}
int main(){
int m=1;int n=2;
cout<<boost::bind(fun,_1,_2)(m,n)<<endl;
return 0;
}
# g++ test.cpp
|