- 浏览: 784865 次
- 性别:
- 来自: 深圳
-
文章分类
- 全部博客 (1045)
- 数据结构 (36)
- UML与设计模式 (42)
- c++ (87)
- rust (36)
- Qt (41)
- boost模板元编程 (43)
- Linux (77)
- 汇编 (4)
- 其它 (2)
- 烹饪 (3)
- unix c / socket (73)
- 软件工程 (4)
- shell (53)
- Python (37)
- c++ primer 5th(c++11) (22)
- 数据库/MySQL (27)
- 数据存储 (4)
- lisp (7)
- git (4)
- Utility (3)
- CDN与DNS (54)
- Http (53)
- php (7)
- nginx/lua/openresty (41)
- redis (11)
- TCP/IP (16)
- 互联网 (6)
- kernel (2)
- go (34)
- 区块链 (43)
- 比特股 (13)
- 以太坊 (23)
- 比特币 (23)
- 密码学 (10)
- EOS (53)
- DAG (1)
- docker (1)
- filecoin (7)
- solidity (65)
- ipfs (8)
- 零知识证明 (1)
- openzeppelin (3)
- java (1)
- defi (7)
- Ton (0)
最新评论
reference_wrapper是一个引用类型的包装器
reference_wrapper就像是被包装对象的一个别名,但它只有在使用T的语境下才能够执行隐性转换,其他情况下则需要调用类型转换函数或get()函数才能真正被包装对象。
template<class T> class reference_wrapper { public: typedef T type; #if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1300 ) explicit reference_wrapper(T& t): t_(&t) {} #else explicit reference_wrapper(T& t): t_(boost::addressof(t)) {} #endif operator T& () const { return *t_; } T& get() const { return *t_; } T* get_pointer() const { return t_; } private: T* t_; };
reference_wrapper就像是被包装对象的一个别名,但它只有在使用T的语境下才能够执行隐性转换,其他情况下则需要调用类型转换函数或get()函数才能真正被包装对象。
#include<boost/ref.hpp> #include<assert.h> #include<iostream> using namespace std; using namespace boost; int main() { int x=10; reference_wrapper<int> rw(x); assert(x==rw); (int &)rw=100; reference_wrapper<int> rw2(rw); assert(rw2.get()==100); cout << rw2.get() << endl; string str; reference_wrapper<string> rws(str); *rws.get_pointer() = "test reference_wrapper"; cout << rws.get().size() << endl; } 100 22
发表评论
-
multi_index_container
2018-08-11 13:04 472根据不同的类中不同的字段排序 #include < ... -
program_options读命令行和配置文件
2018-07-27 11:30 889#include <boost/program_opti ... -
centos下boost安装
2014-03-27 09:28 1090./booststarp.sh //这里的一些错误不用管 ... -
GC的改良
2013-10-17 22:05 593分代回收:对分配不久,诞生时间较短的“年龄”对象进行重点扫描, ... -
GC与引用记数
2013-10-16 21:57 714根(Root)就是判断对象是否可被引用的起始点。至于哪里才是根 ... -
boost 信号槽
2011-06-08 23:43 2347#include<boost/signals2.hp ... -
boost bind
2011-06-07 15:28 1707bind并不是一个单独的类或函数,而是非常庞大的家族,依据绑定 ... -
元编程
2011-06-02 22:46 951元编程的最大特点在于:某些用户自定义的计算可以在程序翻译期进行 ... -
参数化虚拟性
2011-06-02 22:17 881#include<iostream> usi ... -
boost any与variant
2011-05-31 15:55 2453any:是一种只能容纳一个元素的容器,但这个元素可以是任意类型 ... -
traits
2011-05-30 16:43 813#include<iostream> usi ... -
动静多态
2011-05-30 15:40 1092由于继承||虚函数在运行期进程处理,这种多态叫动多态。 模板允 ... -
局部特化
2011-05-29 16:27 1051局部特化并不会引入一个新的模板,它只对原来模板(基本模板)进行 ... -
类模板与模板类
2011-05-29 16:08 7211.类模板:该类是一个模板,他代表的是:整个类家族的参数化描述 ... -
boost tuple
2011-05-27 15:03 1103tuple(元组):定义了一个有固定数目元素的容器,其中的每个 ... -
boost array
2011-05-27 00:06 947array本质上是一个对静态数组的包装,没有构造函数,不能指定 ... -
单元测试
2011-05-23 22:00 910test库提供了一个最小化的测试套件minimal test. ... -
boost StaticAssert
2011-05-23 21:42 958static_assert库把断言的诊断时刻由运行期提前到编译 ... -
boost正则表达式
2011-05-17 23:10 2820xpressive是boost的正则表达式库,它比boost. ... -
为什么模板要写在.h里面
2011-05-13 18:02 1130//test.h template<typena ...
相关推荐
template<typename _Tp> class reference_wrapper : public _Reference_wrapper_base<typename remove_cv<_Tp>::type> { _Tp* _M_data; public: typedef _Tp type; reference_wrapper(_Tp& __indata) noexcept :...
在Boost库中,可能存在一种实现对象引用的机制,如`boost::reference_wrapper`,它可以封装一个对象的引用,并提供类似指针的操作。 描述中提到的“一个简单的对象引用的设计。没有用到stl”,意味着这个压缩包可能...
- **整型外覆器和操作**:定义一个整型包装类`int_wrapper`,并为其提供加法运算符重载。 - **序列与迭代器**:利用模板元编程创建一个动态数组类`dynamic_array`,支持随机访问迭代器。 - **算法**:编写一个元算法...
C ++纸莎草纸-有关现代C ++的C ++注释 该存储库包含有关moodern C ++,系统编程以及为C和C ++构建系统的注释和示例。 HTML版本-包含来自此资源库的所有注释,已编译为html:
As you can see you get a very noticeable performance boost with the new Intel Core iX processors. Comparing B+tree and MGIndex For a measure of relative performance of a b+tree, Red/Black tree and ...