zoukankan      html  css  js  c++  java
  • 理解smart pointer之三:unique_ptr

    unique_ptr最先在boost中被定义,后来被C++标准委员会选中为C++11的feature之一。

    std::unique_ptr is a smart pointer that retains sole ownership of an object through a pointer and destroys that object when the unique_ptr goes out of scope. No two unique_ptr instances can manage the same object.

    The object is destroyed and its memory deallocated when either of the following happens:

    • unique_ptr managing the object is destroyed
    • unique_ptr managing the object is assigned another pointer via operator= or reset().

    The object is destroyed using a potentially user-supplied deleter by calling Deleter(ptr). The deleter calls the destructor of the object and dispenses the memory.

    A unique_ptr may also own no objects, in which case it is called empty.

    There are two versions of std::unique_ptr:

    1. Manages the lifetime of a single object (e.g. allocated with new)
    2. Manages the lifetime of a dynamically-allocated array of objects (e.g. allocated with new[])

    The class satisfies the requirements of MoveConstructible and MoveAssignable, but not the requirements of either CopyConstructible or CopyAssignable. [see C++11 Concepts]

  • 相关阅读:
    Jmeter之写入测试结果到Excel文件
    jmeter之BeanShell 断言
    jmeter-csv数据文件设置之线程共享模式
    LoadRunner生成随机位数的字符串
    linux命令操作
    LoadRunner函数
    vi常用操作
    LoadRunner常见问题
    面试题库
    jmeter持续集成化(二)---jenkins+ant+jmeter
  • 原文地址:https://www.cnblogs.com/whyandinside/p/3284623.html
Copyright © 2011-2022 走看看