C++ Pass Parameters Properly
Programing Languages: you pass a parameter X to a function by value or by reference. C++: 23. Take parameters properly Effective use of C++ is x a raw memory address ← START HERE is x an invocable use a raw pointer try in this order: std::invoke_r<Args...> auto& x return {"(Args...)"} std::move(Args...) std::function<return_t(Args...)> x std::forward<return_t(Args...)> x Which x need to be perfectly forwarded "universal reference" if x is a range If x is a read-only string Does x need to be a contiguous array Take std::string_view Take std::optional of x If x can be null If needing ownership of x Can x be an arbitrary range Take std::unique_ptr, shared_ptr If x is moved from Take std::span If x is copied Take std::string Does x need to be a specific container Take std::ranges If x is modified Take the container Take by lvalue reference Take by value Take by value reference Take std::ranges Take iterator pair If x is cheap to copy Take by value Take by const value reference
The meme presents a deliberately overwhelming C++ infographic about how to pass a parameter x to a function. It jokes that the simple question of pass-by-value versus pass-by-reference becomes an enormous decision tree full of advanced C++ rules and library types. People send it as a reaction to overly complicated C++ advice or to joke about the language's notorious complexity. EN: The meme presents a deliberately overwhelming C++ infographic about how to pass a parameter x to a function. It jokes that the simple question of pass-by-value versus pass-by-reference becomes an enormous decision tree full of advanced C++ rules and library types. People send it as a reaction to overly complicated C++ advice or to joke about the language's notorious complexity.
- @gentoomemes / 7315 2023-11-13
- Type
- image
- Size
- 800×718 · 98.4 KiB
- Mood
- саркастичный, перегруженный
- Language
- en
- Added