Professional CMake:

A Practical Guide

Learn to use CMake effectively with practical advice from a CMake co-maintainer. You can also have the author work directly with your team!

 

C++ list initialization

Containers

Consider this very typical piece of C/C++ code for creating an array of integers from a list of specified values (called a braced initializer):

const int[] someInts = {23, 10, 5, 17};

This is simple and works well where a plain int array is needed, but sometimes we want to do something similar with STL containers.

Read moreC++ list initialization

Container iteration with C++11

C++11 introduced some features which make working with STL containers much easier. One common situation is the need to iterate over a container and to perform some operation(s) on each item. Consider the following typical example:

std::vector<SomeType> container;
// ...

for(std::vector<SomeType>::iterator iter = container.begin();
    iter != container.end();
    ++iter)
{
    const SomeType& item = *iter;
    // ...
}

This syntax has a couple of drawbacks: