mortennobel / cpp-cheatsheet Goto Github PK
View Code? Open in Web Editor NEWModern C++ Cheatsheet
Modern C++ Cheatsheet
would this cheat sheet incorporate C++20 features?
There is no semicolon after the do operation before while
Addition of move constructor
T(T&& obj): data(std::move(obj.data)) { obj.data = nullptr } // enables the resources owned by an rvalue object to be moved into an lvalue without copying
move assignment operator
T& operator=(T&& obj) { data = std::move(obj.data); return *this; } // enables the resources owned by an rvalue object to be moved into an lvalue without copying
This is important because a person is bound to come across these eventually. Although it might be a bit advanced for someone who is just starting out.
int a = 100'000'00;
I am just refreshing my c++ syntax knowledge has been unused for years. Isn't there an operator like '+' missing in the literals section at line
"hello" "world" // Concatenated strings
Shouldn't it be?
"hello" + "world" // Concatenated strings
Finally a good cheatsheet for C++!!
Great job!
The switch case explanation is a bit misleading . There should be a break statement after every case for it to function as an if-else statement, otherwise it will evaluate all the cases.
switch (x) { // x must be int
case X1: a; break; // If x == X1 (must be a const), jump here
case X2: b; break; // Else if x == X2, jump here
default: c; // Else jump here (optional)
}
inline
does not optimize for speed: https://stackoverflow.com/questions/1759300/when-should-i-write-the-keyword-inline-for-a-function-method/1759575#1759575.
inline is more like static or extern than a directive telling the compiler to inline your functions. extern, static, inline are linkage directives, used almost exclusively by the linker, not the compiler.
It is said that inline hints to the compiler that you think the function should be inlined. That may have been true in 1998, but a decade later the compiler needs no such hints. Not to mention humans are usually wrong when it comes to optimizing code, so most compilers flat out ignore the 'hint'.
Instead, its primary purpose is the following:
this function will be defined in multiple translation units, don't worry about it. The linker needs to make sure all translation units use a single instance of the variable/function.
It's also very useful for global variables (as of C++17).
Would you mind adding a licence file?
I recommend the default licence, which big enterprises (e.g. Google) expect us developers to freely use the code: https://www.apache.org/licenses/LICENSE-2.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.