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

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

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

39.2 类locale

类local及其相关特性都在<locale>中。

如果一个给定名字的locale或facet所指向的locale并不存在,则用此名访问locale的操作会抛出一个runtime_error。

locale的命名机制有些奇怪。当你用一个locale和一个facet创建一个新locale时,若结果locale有名字,则此名是由具体C++实现定义的。通常,这个名字包含贡献了最多facet的locale的名字。对于无名locale,name()返回"*"。

我们可以将一个locale看作一个map<id,facet*>的接口,即,它允许我们用一个locale::id查找对应的locale::facet派生类对象。locale的实际实现是这一思想的一种高效变体,其内存布局可能像下面这样:

上图中的collate<char>和numpunct<char>都是标准库facet(见39.4节),所有facet都派生自locale::facet。

locale可以自由、高效地拷贝。因此,locale几乎必然实现为一个特例化map<id,facet*>的句柄,这构成了实现的主体。locale中的facet必须能快速访问,因此,特例化的map<id,facet*>必须进行类似数组的快速访问优化。我们可以用use_facet<Facet>(loc)语法访问locale中的facet;见39.3.1节。 ...

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.
Start your free trial

You might also like

Java并发编程实战

Java并发编程实战

Brian Goetz, Tim Peierls
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt

Publisher Resources

ISBN: 9787111544395