C++ Standard Library

本文详细介绍了C++标准库,包括C++98和C++11新增的语言特性,如非类型模板参数、自动类型推导、Lambda表达式等。同时,文章涵盖了C++中的命名空间、异常框架、Callable概念、Utilities模块以及Standard Template Library(STL)的各个组件,如容器、迭代器、算法等。重点讲解了不同类型的容器和迭代器的特点,以及STL如何通过迭代器将数据操作与容器分离。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C++ Standard Library

*注:内容主要是对参考1的学习记录,知识点与图片大都来源于该书,
部分知识点与图片来源于参考2。具体参考信息,见最下方参考。*

C++98中新支持的语言特性

  1. 非类型模板参数template<std::size_t N> class bitset;
  2. 模板类中的默认模板参数template<typename T, typename Allocator = std::allocator<T>> calss vector
  3. 关键字typename用来表示随后的标识符是一个类型。
  4. 支持类的成员函数是成员模板函数,然而该成员函数不能是虚函数。
  5. 支持嵌套类模板。
  6. 基本类型的显示初始化int x = int();,该特性可以确保模板代码中任意类型的值都有一个初始化的默认值。

C++11中新支持的语言特性

  1. 模板尖括号之间不再需要空格符了,vector<list<int>> // since c++11
  2. 关键字nullptr // since c++11
  3. 关键字auto // since c++11,自动类型推导,从变量的初始化器中推导出该变量的类型。
  4. c++11支持统一的初始化形式,使用大括号。注意的是,{}初始化不能进行类型缩小转换。例如int x{2.0}; // is wrong
  5. c++11支持初始化列表,如int std::vector<int> v{2, 3, 4, 65}; // initializer list。注意,如果一个类声明了
    显示构造函数,则不可使用初始化列表。
  6. c++11支持foreach循环。
  7. c++11支持移动语义和右值引用,简单的说就是值传递的过程中不用再copy了,而是直接使用该值。
namespace std {
    template<typename T, ...> 
    class set {
    public:
        ... insert(const T& x); // for lvalues, copies the value
        ... insert(T&& x);      // for rvalues, moves the value

    };
}
  1. 返回一个非静态的局部对象的右值引用时错误的。
  2. c++11支持原生字符串(raw string)和多字节/宽字节字符串(multibyte/wide-character string)。
    R"(\\n)"; // raw string, begin with R(", and end with )"。为了能够在原生字符串中使用)",需要使用
    分隔符。原生字符串的完整语法是R"delim(...)delim",其中delim是一个至多16个基本字符的字符序列,并且delim中
    不能有反斜杠backslash,空白符whitespaces,与括号parentheses。如:
R"nc(a\
    b\nc()"
    )nc";

//等价于
"a\\\n   b\\nnc()"\n     "

多字节/宽字节字符串字面值


                
C++ Standard Library Quick Reference by Peter Van Weert, Marc Gregoire 2016 | ISBN: 1484218752 | English | 206 pages PDF+EPUB This quick reference is a condensed reference guide to the essential data structures, algorithms, and functions provided by the C++ Standard Library. More specifically, this is a compact collection of essential classes and functions, used by C++ programmers on a daily basis. The C++ Standard Library Quick Reference features core classes for strings, I/O streams, and various generic containers, as well as a comprehensive set of algorithms to manipulate them. In recent years, the C++11 and C++14 standards have added even more efficient container classes, a new powerful regular expression library, and a portable multithreading library featuring threads, mutexes, condition variables, and atomic variables. Needless to say, it is hard to know and remember all the possibilities, details, and intricacies of this vast and growing library. This handy reference guide is therefore indispensable to any C++ programmer. It offers a condensed, well-structured summary of all essential aspects of the C++ Standard Library, including all aforementioned functionality. No page-long, repetitive examples or obscure, rarely used features. Instead, everything you need to know and watch out for in practice is outlined in a compact, to-the-point style, interspersed with well-chosen, clarifying examples. The book does not explain the C++ language or syntax, but is accessible to anyone with basic C++ knowledge. Even the most experienced C++ programmer though will learn a thing or two from it and find it a useful memory-aid. What You Will Learn • The essentials that the C++ Standard Library has to offer • How to use containers to efficiently store and retrieve your data • How to use algorithms to inspect and manipulate your data • How lambda expressions allow for elegant use of algorithms • What the standard string class provides and how to use it • What functionality the library provides for file and stream-based I/O • What smart pointers are and how to use them to prevent memory leaks • How to write safe and efficient multi-threaded code using the C++11 threading libraries
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值