C++11C++14C++17Learn C++

The Main Function of a C++ Program

The source code written in C++ must be compiled (i.e. translated to the machine code) by one or another compiler such as Embarcadero RAD Studio C++ compilers before in can be runned. In general, there are two types of the resulting machine code: library and main executable (hereinafter simply executable). This post will briefly cover the later of these two. When an executable produced from a…
Read more
C++11C++14C++17Learn C++

Switch Statement in Modern C++

The C++ language provides the switch statement which can be used to replace the set of if statements (see If Statements in Modern C++). First of all, let’s define the enum type Traffic_light_color as follows: enum class Traffic_light_color { red, yellow, green }; Then, the following snippet: // Snippet 1 #include <stdexcept> #include <string_view> std::string_view…
Read more
C++11C++14C++17IteratorsLearn C++

Range-for-statement in Modern C++

Since C++11 there are elegant way to access each element of a containers (or, more generally, sequences) – so called range-for-statement. The syntaxes are follow: template<class Container> void foo(Container& container) { for (auto element : container); // (1) for (const auto element : container); // (2) for (auto& element : container); // (3) for…
Read more
C++C++11C++14C++17IteratorsLearn C++

Reverse Iterators in C++

By using bidirectional iterator or random access iterator (see Iterator Categories in C++) it’s possible to traverse the sequence in backward direction by using operator -- or by using the special adapter template class std::reverse_iterator. But why to bother with reverse iterators if the operator -- is available for iterators with bidirectional traversing capabilities? The answer is…
Read more