boost--ref】的更多相关文章

boost::function to encapsulate function pointers. 1. function #include <boost/function.hpp> #include <iostream> #include <cstdlib> #include <cstring> int main() { boost::function<int(const char*)> f = std::atoi; std::cout <…
#include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <iostream> using namespace std; void dprint(int x,int y) { cout << x << " " <<y <<endl; } class Bind_test { public: void setData(int x,i…
boost 1.60.0 先上代码: #include <boost/thread.hpp> #include <iostream> void add(int &i) { std::cout<<"in add, befor ++i, i: "<<i<<std::endl; ++i; std::cout<<"in add, after ++i, i: "<<i<<s…
从官方给出的示例中对于 boost::asio::ip::tcp::acceptor 类的使用,是直接使用构造函数进行构造对象,这一种方法用来学习是一个不错的方式. 但是要用它来做项目却是不能够满足我们的需求的,可它有相应的接口,可以让我们更灵活的使用它来做我们的项目.我们可以把这个accptor 的使用拆分开来,就是分成几个步骤来做.这样我们就可以在我们的项目中,在多个函数里面对它进行一步一步的生成. 简单的用法: #include <iostream> #include <boost…
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple_io.hpp> #include <boost/tuple/tuple_comparison.hpp> #include <iostream> #include <string> void TestTuple1() { typedef boost::tuple<std::string, std::string> p…
曾几何时,Boost中有一个Socket库,但后来没有了下文,C++社区一直在翘首盼望一个标准网络库的出现,网络上开源的网络库也有不少,例如Apache Portable Runtime就是比较著名的一个,也有像ACE这样重量级的网络框架.去年,Boost将ASIO纳入了自己的体系,由于Boost的影响力,ASIO有机会成为标准网络库.作者Chris Kohlhoff以ASIO为样本向C++标准委员会提交了一个网络库建议书,里面提到:ASIO的覆盖范围: Networking using TC…
function是一个函数对象的“容器”,概念上像是c/c++中函数指针类型的泛化,是一种“智能函数指针”.它以对象的形式封装了原始的函数指针或函数对象,能够容纳任意符合函数签名的可调用对象. 因此,它可以被用于回调机制,暂时保管函数或函数对象,在之后需要的时机再调用,使回调机制拥有更多的弹性. 1.function的声明 比如使用function<int(doublea, double b)> func; 这就是声明了一个function对象,返回值为int,有两个参数都为double 2.…
代码段1: #include <boost/function.hpp> #include <iostream> float mul_ints(int x, int y) { return ((float)x) * y; } struct int_div { float operator()(int x, int y) const { return ((float)x)/y; }; }; int main() { boost::function<float (int x, in…
直接代码: 代码段1: #include <iostream> #include <string> #include <boost/bind/bind.hpp> class some_class { public: typedef void result_type; void print_string(const std::string& s) const { std::cout << s << '\n'; } }; void print…
第一部分源码为基础实践: /*Beyond the C++ Standard Library ( An Introduction to Boost )[CN].chm*/ /*bind的用法*/ #include <iostream> #include <algorithm> #include <functional> #include <vector> #include <boost/bind/bind.hpp> #include <bo…