Namespaces
Variants

Zero-overhead principle

From cppreference.net
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
constexpr (C++11)
consteval (C++20)
constinit (C++20)
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

zero-overhead principle は、次のように述べるC++の設計原則です:

  1. 使わないものに対してはコストを支払う必要がありません。
  2. 実際に使用するものは、手書きで適切に記述した場合と同等の効率性を発揮します。

一般的に、これはC++に機能を追加する際、プログラマーがその機能を使用せずに導入するであろう以上のオーバーヘッド(時間的または空間的)を課すような機能を追加すべきではないことを意味します。

言語においてゼロオーバーヘッド原則に従わない唯一の2つの機能は runtime type identification exceptions であり、これがほとんどのコンパイラがそれらを無効にするスイッチを含んでいる理由です。

外部リンク

1. C++の基礎 - Bjarne Stroustrup
2. C++例外と代替手法 - Bjarne Stroustrup
3. C++の断片化解消 - 例外 RTTI の利便性向上とコスト削減 - Herb Sutter
4. Bjarne Stroustrup: AIポッドキャストにおけるC++