5.4 — The as-if rule and compile-time optimization

Introduction to optimization In programming, optimization is the process of modifying software to make it work more efficiently (e.g. to run faster, or use fewer resources). Optimization can have a huge impact on the overall performance level of an application. Some types of optimization are typically done by hand. A …

11.10 — Using function templates in multiple files

Consider the following program, which doesn’t work correctly: main.cpp: #include <iostream> template <typename T> T addOne(T x); // function template forward declaration int main() { std::cout << addOne(1) << ‘\n’; std::cout << addOne(2.3) << ‘\n’; return 0; } add.cpp: template <typename T> T addOne(T x) // function template definition { …

0.13 — What language standard is my compiler using?

The following program is designed to print the name of the language standard your compiler is currently using. You can copy/paste, compile, and run this program to validate that your compiler is using the language standard you expect. PrintStandard.cpp: // This program prints the C++ language standard your compiler is …

13.5 — Introduction to overloading the I/O operators

In the prior lesson (), we showed this example, where we used a function to convert an enumeration into an equivalent string: #include <iostream> #include <string_view> enum Color { black, red, blue, }; constexpr std::string_view getColorName(Color color) { switch (color) { case black: return “black”; case red: return “red”; case …