Skip to content

Latest commit

 

History

History
1613 lines (971 loc) · 72.4 KB

core_language.md

File metadata and controls

1613 lines (971 loc) · 72.4 KB

Core language

Table of contents


Introduction and overview

🔗

🎥

Abstract machine

🎥


ABI and implementation

🔗

🎥

Itanium C++ ABI

The Itanium C++ ABI is an ABI for C++. As an ABI, it gives precise rules for implementing the language, ensuring that separately-compiled parts of a program can successfully interoperate. It is not platform-specific and can be layered portably on top of an arbitrary C ABI. It is used as the standard C++ ABI for many major operating systems on all major architectures, and is implemented in many major C++ compilers, including GCC and Clang.

🔗

Calling conventions

🔗

Implementation of inheritance

🔗

📖

  • Ch. 1: Inheritance, Sec.: Inheritance implementation; Ch. 2: Multiple inheritance, Sec.: Multiple inheritance implementation – N.Llopis. C++ for game programmers – Charles River Media (2003)

Implementation of exceptions

See also Exceptions – Patterns, idioms, and design principles.

🔗

🎥


Keywords

🔗


Attributes

🎥

[[maybe_unused]]

See also Unused variables and return values – Patterns, idioms, and design principles.

[[likely]] / [[unlikely]]

These attributes allow the compiler to optimize for the case where paths of execution are more or less likely than any alternative path of execution.

See [[likely]] / [[unlikely]] attributes – Hardware, optimization, and OS internals.

[[nodiscard]]

This attribute encourages the compiler to issue a warning if the return value is discarded. Conservative approach suggested by N.Josuttis:

  • Should be added:
    • existing APIs: not using the return value always is a “huge mistake”; not using the return value is a source of trouble and easily can happen;
    • new APIs: not using the return value is usually an error.
  • Should not be added:
    • existing APIs: not using the return value is a possible/common way of programming at least for some input; not using the return value makes no sense but doesn’t hurt.

🔗

[[noreturn]]

This attribute indicates that the function does not return.

🔗

[[trivially_relocatable]]

This attribute specifies that the relocation operation for an object is trivial: moving the object and then immediately destroying the original is equivalent to memcpy. This attribute is not yet in the standard.

See Relocation – Memory – Optimization and hardware.


Declarations

🔗

🎥

alignas and alignment

See also Layout – Class types.

auto

For variables, specifies that the type of the variable will be automatically deduced from its initializer. For functions, specifies that the return type will be deduced from its return statements. For non-type template parameters, specifies that the type will be deduced from the argument.

🔗

const and mutable

In C++98: const means “logically const”, in C++11 const means “thread safe” (bitwise const or internally synchronized). In C++98: mutable means “not observably non-const”, in C++11 mutable means “thread safe” (bitwise const or internally synchronized).

🔗

🎥

constexpr

🔗

🎥

constexpr and dynamic allocations

consteval

decltype and std::declval()

The decltype specifier inspects the declared type of an entity or the type and value category of an expression. std::declval converts any type T to a reference type, making it possible to use member functions in the operand of the decltype specifier without the need to go through constructors.

🔗

enum, enum class

🔗

friend

🎥

Friend function templates

See Friend function templates – Function templates – Templates.

Hidden friends

🔗

🎥

inline

🔗

static

static_assert

using

🔗

using enum

Elaborated type specifier

Flexible array member

🔗

Most vexing parse

There is an ambiguity in the grammar involving expression-statements and declarations: An expression-statement with a function-style explicit type conversion as its leftmost subexpression can be indistinguishable from a declaration where the first declarator starts with a (. In those cases the statement is a declaration.

🔗

📖

  • Item 6: Be alert for C++’s most vexing parse – S.Meyers. Effective STL: 50 Specific ways to improve your use of the standard template libraryAddison-Wesley (2001)

Namespaces

🔗

Storage class specifiers

🔗

🎥

Structured binding

🔗


Initialization

🔗

Aggregate initialization

🔗

Uniform initialization

🔗

constinit


Dynamic memory

🔗

📖

Alignment

🔗

Object creation and placement new

See also Uninitialized storage – The standard library and proposals.

🎥

Global replacement of operator new and operator delete


Exceptions

See also Exceptions – Patterns, idioms, and design principles and Exceptions – The standard library and proposals.

🔗

noexcept specifier

Specifies whether a function could throw exceptions.


Expressions

nullptr

The keyword nullptr denotes the pointer literal. It is a prvalue of type std::nullptr_t.

See std::nullptr_t – The standard library and proposals.

Compound literals

A compound literal constructs an unnamed object of specified type in-place: ( type ) { initializer-list }.

🔗

User-defined literals

A user-defined literal (UDL) allows integer, floating-point, character, and string literals to produce objects of user-defined type by defining a user-defined suffix.

🔗

Operator precedence and associativity

Order of evaluation

🔗

📖

Type conversions

📖

  • Item 2: Prefer C++-style casts – S.Meyers. More effective C++: 35 new ways to improve your programs and designsAddison-Wesley (1996)

dynamic_cast

🔗

🎥

Type punning

📝

🔗

🎥

Value categories

🔗

🎥


Flow control

Range-based for loop

🔗

🎥

if

if constexpr

switch

Transfers control to one of several statements, depending on the value of a condition.

🎥


Functions and function objects

🎥

Overload resolution

🔗

Argument-dependent lookup

🔗

🎥

Function wrappers

std::function

Lambda expressions

See also Lambda expression idioms – Patterns, idioms, and design principles.

🔗

🎥

Member functions

Member function poiners

🔗

Special member functions

🎥

Explicit object parameter / deducing this

🔗

Deleted functions (= delete;)

If, instead of a function body, the special syntax = delete; is used, the function is defined as deleted. Any use of a deleted function is ill-formed (the program will not compile).

🔗

main()

🔗

🎥


Operators

🎥

Comparisons

🔗

Three-ways comparisons

🔗

🎥

Pointer comparisons

🔗

Conditional operator ?:

🔗

Logical operators

Implication

🔗

sizeof / alignof

The sizeof operator yields the size in bytes of the object or type. When applied to a class type, the result is the size of an object of that class plus any additional padding required to place such object in an array. The alignof operator returns the alignment required for any instance of a type.


Types

🎥

void

Integral types

🔗

🎥

Integral promotion

wchar_t

🔗

Floating-point types

There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double. The value representation of floating-point types is implementation-defined.

See also Floating-point arithmetic – Numeric data structures and algorithms.

🔗

__float128

🔗

Trivial and POD types

🔗

Pointer and array types

🎥

Null pointers

Class types

🎥

Destructors

🔗

Layout

🔗

🎥

Member functions

See Functions and function objects – Member functions.

Polymorphism and inheritance

See also Implementation of inheritance – ABI and implementation.

🔗

:movie_camera

📖

  • Ch. 1: Inheritance, Ch. 2: Multiple inheritance – N.Llopis. C++ for game programmers – Charles River Media (2003)

Union types

Function types

References

Lifetime of a temporary

🔗

:movie_camera

Rvalue references, universal references, and move semantics

See also Move semantics – Patterns, idioms, and design principles.

🔗

🎥

Opaque typedefs

See Opaque typedef – Patterns, idioms, and design principles.


Standards

C++11

C++14

🔗

C++17

🎥

C++20

🔗

🎥


Tricks and subtleties

🔗

🎥

Accessing private and protected members

🔗

Embedding binary data

🔗


C, C vs C++

🔗

🎥

Arrays

📖

Functions

🔗

Static variables

Conditional operator

🔗