Skip to content

Commit 86e7cee

Browse files
committed
C++23 static operator : 経緯とパフォーマンス効果を記載 #1029
1 parent 7e3cbd4 commit 86e7cee

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lang/cpp23/static_operator.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
- `mutable`を同時に指定することはできない
1313
- `const`メンバ関数ではなくなる
1414

15+
これらを`static`として定義することで、演算子の呼び出しが高速化することを期待できる。
16+
1517

1618
##
1719
```cpp example
@@ -40,6 +42,13 @@ int main()
4042
1
4143
```
4244
45+
46+
## この機能が必要になった背景・経緯
47+
関数オブジェクトは関数ポインタに比べてインライン化しやすいため、パフォーマンスで有利である。しかし、関数オブジェクトがなんらかの理由でインライン化されない場合に、`this`ポインタを渡すための余分なレジスタを使わなければならない。
48+
49+
状態をもたない関数オブジェクトでは`this`ポインタの受け渡しは必要なく、無駄である。必要ないもののためにコストを支払わないという基本的な思想に反していたため、`this`ポインタの受け渡しをなくせる機能として、`static`指定の許可を導入した。
50+
51+
4352
## 関連項目
4453
- [C++11 ラムダ式](/lang/cpp11/lambda_expressions.md)
4554
- [`std::function::`推論補助](/reference/functional/function/op_deduction_guide.md)

0 commit comments

Comments
 (0)