Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
josuttis_nm_c20_the_complete_guide.pdf
Скачиваний:
44
Добавлен:
27.03.2023
Размер:
5.85 Mб
Скачать

Glossary

This glossary provides a short definition of the most important non-trivial technical terms used in this book.

A

aggregate

Aggregates are simple class or struct types, with restrictions so that the focus lies on storing data and not providing complex behavior. Coming from the programming language C, they are historically raw arrays, structs, and combinations of these two features, which you can initialize with curly braces. In C++, the key requirement is that aggregates have only public data members, no constructors, and no virtual functions. Note that these requirements have changed slightly in C++20. Note also that you can now initialize aggregates with parentheses.

argument-dependent lookup (ADL)

A feature that allows the programmer to skip namespace qualification of a function when one of the parameters is in its namespace. This means that a function is also looked up in all namespaces of the arguments passed.

C

class template argument deduction (CTAD)

The process that implicitly determines template arguments from the context in which class templates are used. It was introduced with C++17 and allows you to skip the specification of template arguments of an object when the template parameters can be deduced from the constructor.

703

704

Glossary

F

forwarding reference

The term that the C++ standard uses for universal references.

full specialization

An alternative definition for a (primary) template that no longer depends on any template parameter.

function object (functor)

An object that can be used as a function. For this, operator() is defined in the class. All lambdas are function objects.

G

glvalue

A value category of expressions that produce a location for a stored value (generalized localizable value). A glvalue can be an lvalue or an xvalue.

I

incomplete type

A class, struct, or unscoped enumeration type that is declared but not defined, an array of unknown size, void (optionally with const and/or volatile), or an array of an incomplete element type.

L

lvalue

A value category of expressions that produce a location for a stored value that is not assumed to be movable (i.e., glvalues that are not xvalues). Examples are:

Named objects (variables)

String literals

Returned lvalue references

Functions and all references to functions

Data members of lvalues

Glossary

705

P

partial specialization

An alternative definition for a (primary) template that still depends on one or more template parameters.

predicate

A callable (function, function object, or lambda) that checks whether a certain criterion applies to one or more arguments. It returns a Boolean value, is read-only, and stateless.

prvalue

A value category of expressions that perform initializations. Prvalues can be assumed to designate pure mathematical values such as 1 or true and temporary objects without names. Examples are:

All literals except string literals (42, true, nullptr, etc.)

Returned values (values not returned by reference)

Results of constructor calls

Lambdas

this

What was called an rvalue before C++11 is called a prvalue since C++11.

R

resource acquisition is initialization (RAII)

A programming pattern to delegate clean-ups necessary for the end of using a resource to a destructor so that the clean-ups happen automatically when the object that represents the resource leaves its scope or ends its lifetime.

regular type

A type that matches the semantics of built-in value types (such as int). Based on the definition in http://stepanovpapers.com/DeSt98.pdf, a regular type provides the following basic operations:

Default construction (T x;)

Copying (T y = x;) and in C++, moving

Assignment (x = y;) and in C++, move assignment

Equality and inequality (x == y and x != y)

Ordering (x < y etc.)

These operations follow the “usual” naive rules:

If one object is a copy of the other, the objects are equal.

A copy of an object is equal to an object created with the default constructor to which the source value was assigned.

Objects have value semantics. If two objects are equal and we modify one of them, they are no longer equal.

If only the comparison operators are missing, the type is called semiregular.

706

Glossary

rvalue

A value category of expressions that are not lvalues. An rvalue can be a prvalue (such as a temporary object without a name) or an xvalue (e.g., an lvalue marked with std::move()). What was called an rvalue before C++11 is called a prvalue since C++11.

S

semiregular type

A type that is regular but does not provide comparison operators:

If one object is a copy of the other, the objects are equal.

A copy of an object is equal to an object created with the default constructor to which the source value was assigned.

Objects have value semantics. If two objects are equal and we modify one of them, they are no longer equal.

substitution failure is not an error (SFINAE)

A mechanism that silently discards templates instead of triggering compilation errors when arguments to template parameters make their declarations ill-formed. You can use the mechanism to disable templates for certain arguments by forcing ill-formed declarations then.

small string optimization (SSO)

An approach to save allocating memory for short strings by always reserving memory for a certain number of characters. A typical value in standard library implementations is to always reserve 16 or 24 bytes of memory so that the string can have 15 or 23 characters (plus 1 byte for the null terminator) without allocating memory. This makes all string objects larger but usually saves a lot of running time because in practice, strings are often shorter than 16 or 24 characters and allocating memory on the heap is quite an expensive operation.

stateless

A function or operation is stateless if it does not change its state due to a call. This has the effect that it does not change its behavior over time and always yields the same result for the same arguments.

standard template library (STL)

The STL is the part of the C++ standard library that deals with containers (data structures), algorithms, and as glue, the iterators. This approach was adopted for the first C++ standard with the goal that programmers can benefit from various standard data structures and algorithms without having to implement them. As generic code, you still get compile-time error messages when you try to combine things that are not supported.

Glossary

707

U

universal reference

A reference that can universally refer to any object while not making it const. It can also extend the lifetime of return values. It is declared as an rvalue reference of a template parameter (T&&) or with auto&&. Universal references are useful for perfectly forwarding arguments with std::forward<>() (for that reason, the C++ standard names them forwarding references).

However, they also are the only kind of references that can refer to any expression (both lvalues and rvalues) without making the value const. For this reason, they are necessary to declare parameters of generic functions that take views.

V

value category

A classification of expressions. The traditional value categories lvalues and rvalues were inherited from the programming language C. C++11 introduced additional categories, meaning that C++ now has the following primary value categories:

prvalues (pure rvalues), which are values used to initialize objects (including parameters)

lvalues (localizable values), which are objects you can ask for the address

xvalues (eXpiring values), which are objects where we no longer need the value (usually, objects marked with std::move())

In addition, C++ has the following combined value categories:

glvalues (generalized lvalues), which means “either lvalue or xvalue”

rvalues (readable values), which means “either rvalue or xvalue”

variable template

A generic variable. It allows us to define variables or static members by substituting the template parameters with specific types or values.

variadic template

A template with a template parameter that represents an arbitrary number of types or values.

X

xvalue

A value category of expressions that produce a location for a stored object that can be assumed to be no longer needed. Examples are:

Values marked with std::move()

Returned rvalue references

Casts of objects (not of functions) to an rvalue reference

Value members of rvalues

708

This page is intentionally left blank