Zero-overhead principle
From cppreference.net
C++
C++ language
| General topics | ||||||||||||||||
| Flow control | ||||||||||||||||
| Conditional execution statements | ||||||||||||||||
| Iteration statements (loops) | ||||||||||||||||
|
||||||||||||||||
| Jump statements | ||||||||||||||||
| Functions | ||||||||||||||||
| Function declaration | ||||||||||||||||
| Lambda function expression | ||||||||||||||||
inline
specifier
|
||||||||||||||||
| Dynamic exception specifications ( until C++17* ) | ||||||||||||||||
noexcept
specifier
(C++11)
|
||||||||||||||||
| Exceptions | ||||||||||||||||
| Namespaces | ||||||||||||||||
| Types | ||||||||||||||||
| Specifiers | ||||||||||||||||
|
||||||||||||||||
| Storage duration specifiers | ||||||||||||||||
| Initialization | ||||||||||||||||
| Expressions | ||||||||||||||||
| Alternative representations | ||||||||||||||||
| Literals | ||||||||||||||||
| Boolean - Integer - Floating-point | ||||||||||||||||
| Character - String - nullptr (C++11) | ||||||||||||||||
| User-defined (C++11) | ||||||||||||||||
| Utilities | ||||||||||||||||
| Attributes (C++11) | ||||||||||||||||
| Types | ||||||||||||||||
typedef
declaration
|
||||||||||||||||
| Type alias declaration (C++11) | ||||||||||||||||
| Casts | ||||||||||||||||
| Memory allocation | ||||||||||||||||
| Classes | ||||||||||||||||
| Class-specific function properties | ||||||||||||||||
|
||||||||||||||||
| Special member functions | ||||||||||||||||
|
||||||||||||||||
| Templates | ||||||||||||||||
| Miscellaneous | ||||||||||||||||
零开销原则 是一项C++设计原则,其核心主张是:
- 不为未使用的功能付费。
- 所使用的功能与手动编写的代码具有同等效率。
通常来说,这意味着不应向C++添加任何会导致额外开销的特性,无论这种开销是时间还是空间上的,除非程序员在没有使用该特性时也会引入同等程度的开销。
语言中唯一不遵循零开销原则的两个特性是 运行时类型识别 和 异常处理 ,这也是大多数编译器提供关闭这些功能选项的原因。
外部链接
| 1. | C++基础原理 - Bjarne Stroustrup |
| 2. | C++异常处理与替代方案 - Bjarne Stroustrup |
| 3. | 消除C++碎片化 - 提升 异常处理 与 RTTI 的实用性与成本效益 - Herb Sutter |
| 4. | Bjarne Stroustrup:人工智能(AI)播客专访 |