cpp-best-practices / cpp-best-practices/cppbestpractices

Clarify that marking certain member variables const can hinder performance

未關閉
#147 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
沒有語言資料
星號
8.8k
分支
902
PR 合併指標
30 天內沒有已合併 PR

描述

In the 03-Style document, I read the following sentence:

> If the member variable is not expected to change after the initialization, then mark it const.

However, we know that if, for example, we mark a container as `const`, we prevent it from being moved, possibly hindering performance. Marking fields as `const` is useful to enforce invariants; however, it "interferes" with performance. If both const correctness and performance are important, one could leave the field non-const, make it private and define a field getter.

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

首先定位 03-Style 文件,並檢視其中引用的關於將未變更的成員變數標記為 const 的指引。釐清文件所述的 const 正確性與移動容器之間的取捨,包括 issue 中描述的 private 欄位 getter 選項,然後驗證轉譯後的文件。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
cpp
領域
documentation
Issue 類型
文件
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。