Performance Tips for C++
Performance
-
If there is some block of useless code, the compile is smart enough to ignore it and thus speed up the program.
-
Use the option
-O2to generate optimized code when you are ready to publish your code. -
Define variables only when needed to avoid the overhead of creating …
Lambda Function in C++11
Lambda Function
Check [here[(https://github.com/dclong/cearn/tree/master/lambda) for illustrative examples for the following discussions.
-
When capture variables, you can define new variables in the
[]of a lambda expression. For example, if a lambda function need the sum of two double variablexandy, you …
Initializing Variables in C++
{}is more powerful than()and thus is preferred over(). You should use always use{}except for a few cases where()is necessary. For example, if you want to create a vector of length 1000, you have to usevector<int>(1000);
instead of
vector<int> {1000};
which create a vector …
Install the GSL Library
GSL is an advance C/C++ library that is widely used. To install GSL, you can download the source file and following instruction in the included README and INSTALL document. For Unix/Linux users, the GSL library is often availabe in the repository. For example, you can use the following …
Lvalue Reference and Rvalue Reference

Difference betwen Lvalue and Rvalue Reference
-
Lvalue and Rvalue are terrible names. They are due to historical reasonal but people stuck with these names.
-
A lvalue reference has a name while a rvalue reference has no name, in other words, a lvalue reference is persistent while a rvalue reference is …