Saturday, August 27, 2016

C++'s syntactic sugars

Lets first look at the Wikipedia definition of syntactic sugar:
Syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express.
For the first syntactic sugar we have to go back in time. In C a[i] is syntactically equivalent to *(a + i) which allows us to write this:
int a[5];
a[2] = 1;
but also this:
3[a] = 5;
Which more than perfectly illustrates what a syntactic sugar is.

C++11 introduced the range-based for loop:
std::vector<int> v = {0, 1, 2, 3, 4, 5};
for (const int& i : v) // access by const reference
    std::cout << i << ' '; 

Sunday, August 7, 2016

Code colorization

This month I started a new job and my new colleagues got a little bit shocked by how I am abusing the MSVC editor colors. My source looks like this: