Loops are among the basic constructs you find in nearly all programming languages. Of the available variations,
for loops are the most common ones. The word
for is so small that it is not affected by the tax on long keywords and variable names that programming languages seem to be subject of. Thus, you will find
for as a keyword in most of them.
C++11 supports a multitude of styles to write
for loops. Let us have a look at some of these possibilities for a simple example.
Continue reading “May the FORs be with you”
std::shared_ptr<Value> is one of the starlets in C++11’s recently polished standard template library.
shared_ptrs work just like normal C-style pointers except that they keep track of how many pointers point to the same object. Once the last
shared_ptr pointing to an object goes out of scope, the object pointed at will be deleted. For convenience, the standard library offers the factory function
auto value = std::make_shared<Value>("a", "few", "arguments");
std::make_shared<Value>() creates a new object of type
Value, where the arguments given to
make_shared() are forwarded to the constructor of
Value. The newly created object is immediately wrapped in a
std::shared_ptr<Value>, which is then returned to the caller.
Continue reading “Underprivileged unique pointers: retrofitting make_unique”