5.2 Smart Pointer(智能指针)

shared_ptr的aliasing构造函数,接受一个shared pointer和一个raw pointer。它允许你掌握一个事实:某对象拥有另一个对象。例如:

struct X
{
int a;
}; shared_ptr<X> px(new X);
shared_ptr<int> pi(px,&px->a);

weak_ptr是shared-ptr的帮手,用来共享但不拥有对象,它的use_count()返回的对象是被shared_ptr拥有的次数,而且weak_ptr可以为空->expired()结果是true;lock()会产出一个shared-ptr。

class unique_ptr继承auto_ptr(现已不被认可),可以release()(shared-ptr不可以release是因为可能有其他shared-ptr指向它对象)。

对array,unique_ptr提供偏特化版本,而不用定义自己的deleter。例如:

std::unique_ptr<std::string[]> up(new std::string[10]);

unique_ptr与shared_ptr的deleter接口不同,它必须指明deleter的类型作为第二个template实参。

5.3 数值的极值

书中的例子用到 cout << boolalpha;

boolalpha,函数名称,功能是把bool值显示为true或false。

 

The C++ Standard Library --- A Tutorial Reference 读书笔记的更多相关文章

  1. 《The Python Standard Library》——http模块阅读笔记1

    官方文档:https://docs.python.org/3.5/library/http.html 偷个懒,截图如下: 即,http客户端编程一般用urllib.request库(主要用于“在这复杂 ...

  2. 《The Python Standard Library》——http模块阅读笔记3

    http.cookies — HTTP state management http.cookies模块定义了一系列类来抽象cookies这个概念,一个HTTP状态管理机制.该模块支持string-on ...

  3. 《The Python Standard Library》——http模块阅读笔记2

    http.server是用来构建HTTP服务器(web服务器)的模块,定义了许多相关的类. 创建及运行服务器的代码一般为: def run(server_class=HTTPServer, handl ...

  4. [译]The Python Tutorial#11. Brief Tour of the Standard Library — Part II

    [译]The Python Tutorial#Brief Tour of the Standard Library - Part II 第二部分介绍更多满足专业编程需求的高级模块,这些模块在小型脚本中 ...

  5. [译]The Python Tutorial#10. Brief Tour of the Standard Library

    [译]The Python Tutorial#Brief Tour of the Standard Library 10.1 Operating System Interface os模块为与操作系统 ...

  6. Swift Standard Library Reference.pdf

    Swift Standard Library Reference.pdf 下载地址 http://download.csdn.net/detail/swifttrain/7446331 自己的Mark ...

  7. C++11新特性——The C++ standard library, 2nd Edition 笔记(一)

    前言 这是我阅读<The C++ standard library, 2nd Edition>所做读书笔记的第一篇.这个系列基本上会以一章一篇的节奏来写,少数以C++03为主的章节会和其它 ...

  8. Python Standard Library

    Python Standard Library "We'd like to pretend that 'Fredrik' is a role, but even hundreds of vo ...

  9. The Python Standard Library

    The Python Standard Library¶ While The Python Language Reference describes the exact syntax and sema ...

随机推荐

  1. 消息队列Rabbitmq

    1. 启动 rabbitmq-server & 2. 队列重置(清空队列.用户等) rabbitmqctl stop_apprabbitmqctl resetrabbitmqctl stop ...

  2. Alloc and release

    https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractic ...

  3. Java基础之一组有用的类——使用二叉树搜索算法搜索某个作者(TryBinarySearch)

    控制台程序. Arrays类中的binarySearch()静态方法使用二叉树搜索算法,在有序数组中查找包含给定值的元素.只有当数组的元素按升序方式排序时,该方法才是最有效的,否则就应在调用binar ...

  4. 利用JAVA计算TFIDF和Cosine相似度-学习版本

    写在前面的话,既然是学习版本,那么就不是一个好用的工程实现版本,整套代码全部使用List进行匹配效率可想而知. [原文转自]:http://computergodzilla.blogspot.com/ ...

  5. 一步一步学习Swift之(四)玩转UIWebView

    实现原理: 1.通过UIWebView的stringByEvaluatingJavaScriptFromString方法来触发脚本 2.通过自定义连接来触发oc代码 实现过程 @IBOutlet we ...

  6. Leetcode: Count Numbers with Unique Digits

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  7. Leetcode: Self Crossing

    You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to th ...

  8. SQL查询一个表的总记录数的方法

    一.简单查询语句 1. 查看表结构 SQL>DESC emp; 2. 查询所有列 SQL>SELECT * FROM emp; 3. 查询指定列 SQL>SELECT empmo, ...

  9. hdu1247(字典树+枚举)

    Hat's Words(hdu1247) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  10. [转] HashMap和HashSet的区别

    HashMap和HashSet的区别是Java面试中最常被问到的问题.如果没有涉及到Collection框架以及多线程的面试,可以说是不完整.而Collection框架的问题不涉及到HashSet和H ...