GDB

GDB Tutorial: Some Cool Tips to Debug C/C++ Code

C++

Introduction to C++11 and C++14 with Example Code Snippet

4 Lamba Expressions of Lambda Functions

1
[firstPart](secondPart) TypeYouReturn{BodyOfLambda}(actualParameters);

lambda function:

1
double dUpperPart=[]{double dX, double dY}double{return dX*dX+dY*dY;}
1
2
3
4
vector<int> iVector;
for_each(begin(iVector),end(iVector),[](int n){
  if(n%2==0) cout << n << endl;
});

5 Static Assertion

1
static_assert(evaluateExpression, stringMessage);
1
static_assert(sizeof(long long int)>=16;"This is unexpected");

7 move and &&

1
2
MovableClass(MovableClass&&);
MOvableClass&& operator=(MovableClass&&);

8 Few Notes about Pointers

unique_ptr: If something has ownership it could not be shared, but it is movable.

1
2
3
4
5
6
7
unique_ptr<someType> suniquePtr(new someType(args));
...
uniquePtr.release();

shared_ptr<someType> somePtr(new someType(args));

weak_ptr<someType> weakPtr=somePtr;

9 Uniform Initialization and Initializer Lists

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
//old styles of initialization with constructor
CSomeClass SomeObject(argumnet1, argument2);
//the above can be changed to
CSomeClass SomeObject={argument1,argument2};

//obsolete
vector<int> ourVector;
for(int i=0;i<5;ourVector.push_back(i++));
//better
vector<int> ourVector={0,1,2,3,4};
1
2
3
4
5
class CChild: public CParment
{
  public:
  using CParent::CParent
}