function object研究之十二 reference_wrapper
来源:互联网 发布:playingwithshiro软件 编辑:程序博客网 时间:2024/05/16 11:15
reference_wrapper模板:(ref.hpp文件中)
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_;};
有了前面分析addressof的基础,理解此模板很简单。
功能就是:
1.保存T& t 的地址到内部指针成员T* t_中。
2.提供get方法获取T&
3.提供get_pointer获取T*
再看看相关的几个模板函数:
template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t){ return reference_wrapper<T>(t);}template<class T> inline reference_wrapper<T const> BOOST_REF_CONST cref(T const & t){ return reference_wrapper<T const>(t);}
第一个将t包装成reference_wrapper<T>
第二个将t包装成reference_wrapper<T const>
- function object研究之十二 reference_wrapper
- function object研究之二
- function object研究之三
- function object研究之四
- function object研究之五
- function object研究之六 bind example
- function object研究之九 visit_each
- function object研究之八 add_value_*
- function object研究之七 is_placeholder
- function object研究之十 storageN
- function object研究之十一 addressof
- function object研究之十三 result_traits
- function object研究之十四 unwrap
- function object研究之十五 list1分析
- function object研究之十六 listN分析
- function object研究之十七 list_av_N
- function object研究之十八 bind_t
- function object研究之十九 bind
- Codeforces Round #153 (Div. 2)
- 隐藏标题栏 hide title
- 计算机科学的出版物(会议,期刊)特点
- 解包和打包rom
- 杨辉三角
- function object研究之十二 reference_wrapper
- 论文类型Journal、magazin、transaction、letter等的区别
- VC++ ADO 连接Access
- 进程创建
- 如何查看进程的实际的内存占用
- CRAMFS制作方法
- 基于立宇泰 ARMSYS2440—linux 嵌入式开发环境 ubuntu 配置
- [sicily online]1077. Cash Machine
- Linux通过源代码安装软件的方法介绍