ev-abseil-unique-ptr-zone-003¶
| 字段 | 值 |
|---|---|
| 项目 | abseil/abseil-cpp |
| 固定 commit | 2065f4ded055 |
| 路径 | absl/time/internal/cctz/src/time_zone_impl.h |
| 行段 | L80-L90 |
| 特性 | std::unique_ptr |
| 许可证 | Apache-2.0 |
| 代码来源 | 项目源码 |
| 级别 | manual |
| 审核 | zyuhao7 @ 2026-10-30 |
| 测试代码 | 否 |
| 发现方式 | manual |
用法¶
用 unique_ptr 成员独占时区实现,并在外层类型上禁用复制
为什么典型¶
实现对象只被一个 Impl 拥有,析构顺序由成员自动保证;禁用复制后所有权无法被意外分裂。
摘录¶
private:
Impl();
explicit Impl(const std::string& name);
Impl(const Impl&) = delete;
Impl& operator=(const Impl&) = delete;
static const Impl* UTCImpl();
const std::string name_;
std::unique_ptr<TimeZoneIf> zone_;
};
备注¶
生产路径;时区实现由接口指针持有,Impl 复制被显式删除,所有权随 Impl 析构释放。