Skip to Content
C++程序设计语言(第4部分:标准库)(原书第4版)
book

C++程序设计语言(第4部分:标准库)(原书第4版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
6h 57m
Chinese
Pearson
Content preview from C++程序设计语言(第4部分:标准库)(原书第4版)

31.2 容器概览

一个容器保存着一个对象序列。本节概述容器类型并简要介绍它们的特性。容器上的操作将在31.3节中介绍。

容器可分类为:

·顺序容器提供对元素(半开)序列的访问。

·关联容器提供基于关键字的关联查询。

此外,标准库还提供了一些保存元素的对象类型,它们并未提供顺序容器或关联容器的全部功能:

·容器适配器提供对底层容器的特殊访问。

·拟容器保存元素序列,提供容器的大部分但非全部功能。

STL容器(顺序和关联容器)都是资源句柄,都定义了拷贝和移动操作(见3.3.1节)。所有容器操作都提供了基本保证(见13.2节),确保与基于异常的错误处理机制能正确协同工作。

模板参数A是一个分配器,容器用它来分配和释放内存(见13.6.1节和34.4节)。例如:

A的默认值是std::allocator<T>(见34.4.1节),此分配器用operator new()和operator delete()为元素分配和释放内存。

这些容器都定义在<vector>、<list>和<deque>中。顺序容器为元素连续分配内存(如vector)或将元素组织为链表(如forward_list),元素的类型是容器的成员value_type(就是上表中的T)。deque(发音“deck”)采用链表和连续存储的混合方式。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

算法精讲视频课程:24篇系列讲座

算法精讲视频课程:24篇系列讲座

罗伯特·塞奇威克, 凯文·韦恩(Kevin Wayne)
可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
C语言核心技术(原书第2版)

C语言核心技术(原书第2版)

Peter Prinz, Tony Crawford
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉

Publisher Resources

ISBN: 9787111544395