Search

B.4 — Introduction to C++20

What is C++20?

In February of 2020, the ISO (International Organization for Standardization) approved a new version of C++, called C++20. C++20 contains the most changes to the language since C++11.

New improvements in C++20

For your interest, here’s a list of the major improvements that C++20 adds. Note that this list is not comprehensive, . . . → Read More: B.4 — Introduction to C++20

8.14 — Function template instantiation

In the previous lesson (8.13 — Function templates), we introduced function templates, and converted a normal max() function into a max<T> function template:

In this lesson, we’ll focus on how function templates are used.

Using a function template

Function templates are not actually functions — their code isn’t compiled or . . . → Read More: 8.14 — Function template instantiation

8.x — Chapter 8 summary and quiz

You made it! The topics in this chapter (particularly type aliases, overloaded functions, and function templates) appear everywhere in the C++ standard library. We’ve got one more chapter to go (introducing compound types), and then we’ll be ready to dig into some of the most useful pieces of the standard library!

Quick review

The . . . → Read More: 8.x — Chapter 8 summary and quiz

8.15 — Function templates with multiple template types

In lesson 8.13 — Function templates, we wrote a function template to calculate the maximum of two values:

Now consider the following similar program:

You may be surprised to find that this program won’t compile. Instead, the compiler will issue a bunch of (probably crazy looking) error messages. On Visual Studio, the author . . . → Read More: 8.15 — Function templates with multiple template types

8.11 — Function overload resolution and ambiguous matches

In the previous lesson (8.10 — Function overload differentiation), we discussed which attributes of a function are used to differentiate overloaded functions from each other. If an overloaded function is not properly differentiated from the other overloads of the same name, then the compiler will issue a compile error.

However, having a set of differentiated . . . → Read More: 8.11 — Function overload resolution and ambiguous matches

8.10 — Function overload differentiation

In the prior lesson (8.9 — Introduction to function overloading), we introduced the concept of function overloading, allows us to create multiple functions with the same name, so long as each identically named function has different parameters (or the functions can be otherwise differentiated).

In this lesson, we’ll talk about how overloaded functions are differentiated. . . . → Read More: 8.10 — Function overload differentiation

8.8 — Type deduction for functions

Consider the following program:

When this function is compiled, the compiler will determine that x + y evaluates to an int, then ensure that type of the return value matches the declared return type of the function (or that the return value type can be converted to the declared return type).

Since the compiler . . . → Read More: 8.8 — Type deduction for functions

8.4 — Arithmetic conversions

In lesson 5.1 — Operator precedence and associativity, we discussed how expressions are evaluated according to the precedence and associativity of their operators.

Consider the following expression:

When binary operator+ is invoked, it is given two operands, both of type int. Because both operands are the same type, that type will be used . . . → Read More: 8.4 — Arithmetic conversions

8.3 — Numeric conversions

In the previous lesson (8.2 — Floating-point and integral promotion), we covered numeric promotions, which are conversions of specific narrower numeric types to wider numeric types (typically int or double) that can be processed efficiently.

C++ supports another category of numeric type conversions, called numeric conversions, that cover additional type conversions not covered by the . . . → Read More: 8.3 — Numeric conversions

8.2 — Floating-point and integral promotion

In lesson 4.3 — Object sizes and the sizeof operator, we noted that C++ has minimum size guarantees for each of the fundamental types. However, the actual size of these types can vary based on the compiler and architecture.

This variability was allowed so that the int and double data types could be set to . . . → Read More: 8.2 — Floating-point and integral promotion