+ 2
C++ cool tricks?
Can anyone suggest me tricks in c++ like: a=a+b-(b=a); //for swapping variables or: (condition) ? true : false; //coditions, or: string s = "abcde"; for (int x:s){ cout << x << endl; } //ranged for loop, or functions like: stoi(string, nullptr, 10) //converts any base to base 10.
3 ответов
+ 5
1) decltype() returns the type of a variable. Thus, you may use it when you do not have an idea about what the return type is going to be.
Eg - decltype(variable) var2;
2) typeid() accepts types and lets you compare them as if they were variables.
Eg - if(typeid(var2)==typeid(int)) cout<<"Int";
+ 4
that's a lot of effort just to avoid semicolons ^^
+ 4
auto variable = expression;
This means that the type is determined looking at the expression.