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

Clarify that marking certain member variables const can hinder performance

Aberta
#147 3 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Sem dados de linguagem
Estrelas
8.8k
Forks
902
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

Start by locating the 03-Style document and reviewing the quoted guidance about marking unchanged member variables const. Clarify the documented trade-off between const correctness and moving containers, including the private-field getter option described in the issue, then verify the rendered document.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
cpp
Domínio
documentation
Tipo de issue
Documentação
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
45/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.