What you are seeing here is the use of lambda functions in C++ (which are a C++11 feature).
What is lambda function? Basically, it is a function that you can write inline in your source code. By doing so, you are able to easily create quick functions inline, when previously you needed to write a separate named function.
In your case, here is what is going on:
for_each(begin(v), end(v), [](int n){ cout << n << endl; });
^^
||
This is the identifier that tells the compiler that what we are creating here is a lambda function.
for_each(begin(v), end(v), [](int n){ cout << n << endl; });
^^^^^
|||||
This is the argument list, which in this case is an integer coming from your array v[]
.
for_each(begin(v), end(v), [](int n){ cout << n << endl; });
^^^^^
|||||
From here we can see the function body. It's like if you were to create a regular function, just it is inlined with the rest of your code.
As said before, lambda functions are inline functions, so you might be wondering where is the return type. It is optional if the lambda is not very complex, since the compiler can deduce what is the return type. In your case the compiler knows that your function returns nothing. If you wanted it to explicitly return an int for example, you could tell the compiler what you expect the function to return like this:
[] () -> int { return 2; };