Take Parameters Properly
23. Take parameters properly Effective use of C++ is x a raw memory address START HERE use a raw pointer is x an invocable try in this order: std::invocable<Args...> auto&& x return_t(*)(Args...) std::invocable<...> auto&& x std::function&& return_t(Args...)> x does x need to be perfectly forwarded take by universal reference if x is a range if x is a readonly string take std::string does x need to be a contiguous array take std::span can x be an arbitrary range take std::ranges::... does x need to be a specific container take the container take iterator pair if x can be null take std::optional of x if needing ownership of x take std::string if x is moved from take by value reference if x is copied take by value if x is modified take by value if x is cheap to copy take by value otherwise take by const value reference
На изображении показана юмористическая блок-схема «Take parameters properly» об эффективном использовании C++. Она перечисляет множество вариантов передачи параметров в C++: указатель, универсальная ссылка, std::optional, std::span, контейнер или передача по значению. Шутка в том, что выбор правильного способа передачи параметра превращён в чрезмерно сложное дерево решений.
C++ code diagram / диаграмма кода C++blue presentation slide / синяя презентационная слайдwhite text / белый текстarrows / стрелкиflowchart / блок-схемаraw pointer / сырой указательmemory address / адрес памятиuniversal reference / универсальная ссылкаrange / диапазонreadonly string / строка только для чтенияoptional / optionalstring / строкаcontiguous array / непрерывный массивspan / spancontainer / контейнерiterator pair / пара итераторовfunction signature / сигнатура функции
- @right_wing_dev_squads / 12332 2025-06-16
- Type
- image
- Size
- 800×448 · 69.7 KiB
- Mood
- саркастичный, абсурдный
- Language
- en
- Added