Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Update Needed, No Longer Always True Since C++23] F.19: For “forward” parameters, pass by TP&& and only std::forward the parameter

Aperta
#2,277 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@hsutter ci sta già lavorando.

Dal 6/8/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

Consider the following code:

#include <string>

auto f1(auto&& v) {
    return v;
}

auto f2(auto&& v) {
    return std::forward<decltype(v)>(v);
}

int main() {
    return f1(std::string("hello")).size() + f2(std::string("hello")).size();
}

clang will generate the same assembly code for f1 and f2. However,

  • As per the C++ core guidelines, f2 is recommended;
  • As per p0527r1, f1 is enough since C++23.
  • It's possible that f2 has an extra function call than f1. We should not depend on the compiler to optimize that out; even if it almost always does.

Should we still always std::forward a universal reference argument? or the C++ core guidelines should be updated?

Cited from https://stackoverflow.com/questions/79657383/should-we-still-always-stdforward-a-universal-reference-argument-even-if-unnec

Lingua principale
CSS
Stelle
45.4k
Fork
5.6k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di isocpp/CppCoreGuidelines

Tutte le issue di isocpp/CppCoreGuidelines

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.