C++11, BS book extract, part II, chapter 7 + 8 +9 + 10 + 11

nullptr instead of NULL

raw string literalsR”(ccc)” notation for a sequence of characters ccc, for wchar_t – it is LR”(angst)”, u8 – UTF8, u – UTF16,  U – UTF32, can be combined with R as well.

Reference to reference can only happen as the result of an alias  or a template type argument.

 Unqualified Lists – {} are used besides initialization a variable

  • A function argument
  • A return value
  • The right-hand operand of an assignment operator ( = , += , ∗= , etc.)
  • A subscript


A lambda expression consists of a sequence of parts:

  • A possibly empty capture list
  • An optional parameter list
  • An optional mutable specifier
  • An optional noexcept specifier
  • An optional return type declaration of the form −> type
  • A body, specifying the code to be executed. The body is delimited by {}

Lambda capture list can be –

  • [] : an empty capture list (no captures).
  • [&] : implicitly capture by reference (all local names)
  • [=] : implicitly capture by value (all local names)
  • [ capture-list ] : explicit capture
  • [&, capture-list ] : implicitly capture by reference all local variables with names not mentioned in the list
  • [=, capture-list ] : implicitly capture by value all local variables with names not mentioned in the list

A lambda that captures nothing can be assigned to a pointer to function of an appropriate type

C++11, BS book extract, part II, chapter 6

Fundamental Types

  • bool
  • (signed/unsigned)char, wchar_t, char16_t (UTF16), char32_t(UTF32)
  • short, (signed/unsigned) int, long long
  • float, double, long double
  • void
  • pointer
  • array
  • reference
  • struct, class
  • enum

{} -initializer syntax to prevent narrowing alignof() operator returns the alignment of its argument expression we can use the type specifier alignas : alignas(T) means ‘‘align just like a T .’’ void user(const vector& vx) {     constexpr int bufmax = 1024;     alignas(X) buffer[bufmax];     // uninitialized     const int max = min(vx.size(),bufmax/siz eof(X));     uninitialized_copy(vx.begin(),vx.begin()+max,buffer);     // … }   Scope

  • Local scope
  • Class scope
  • Namespace scope
  • Global scope
  • Statement scope
  • Function scope

Initialization X a1 {v}; – initializer list – prevents data gets lost, like narrowing (integer of float point datatypes) or floating integer type conversion but auto should be initialized with assignment auto z1 {99}; // z1 is an initializer_list auto z2 = 99; // z2 is an int difference for vector as well vector v1 {99}; // v1 is a vector of 1 element with the value 99 vector v2(99); // v2 is a vector of 99 elements each with the default value 0  Prefer {} initialization over alternatives unless you have a strong reason not to. The empty initializer list, {} , is used to indicate that a default value is desired. Nice example – char buf[max] {}; // initialize every char to 0 If initialization is missed

  • Static objects (global, local static, static members) are initialized by default
  • Dynamic – heap or stack based – are not initialized.

The language provides two mechanisms for deducing a type from an expression:

  • auto for deducing a type of an object from its initializer; the type can be the type of a vari- able, a const , or a constexpr .
  • decltype(expr) for deducing the type of something that is not a simple initializer, such as the return type for a function or the type of a class member.

Weird syntax template auto operator+(const Matrix& a, const Matrix& b) −> Matrix<decltype(T{}+U{})>;   The lifetime of an object starts when its constructor completes and ends when its destructor starts executing.

  • Automatic
  • Static
  • Free store (Heap)
  • Temporary objects
  • Thread-local objects; that is, objects declared thread_local

using instead of typedef, using could not be prepended with unsigned/signed

C++11, BS book extract, part I, chapter 5

Concurrency, task,  threads.

Sharing data – mutex, unique_lock

condition_variable, methods – wait,  notify_one, …

Tasks – promise (set_value, set_exception), future (get), packaged_task, async…

Type functions, like numeric limits

Tuple – like pair, but for unlimited amount of types/members


Math, complex numbers, random numbers

Valarray – vector arithmetic


C++11, BS book extract, part I, chapter 4

STL overview


copy(), find(), sort()
duration, time_point
sqrt(), pow()
complex, sqrt(), pow()
fstream, ifstream, ofstream
future, promise
istream, ostream, cin, cout

map, multimap
unique_ptr, shared_ptr, allocator
default_random_engine, normal_distribution
regex, smatch
string, basic_string
set, multiset
istrstream, ostrstream
unordered_map, unordered_multimap
move(), swap(), pair


array A fixed-size array
vector A variable-size vector
list A doubly-linked list
forward_list A singly-linked list
deque A double-ended queue
set A set
multiset A set in which a value can occur many times
map An associative array
multimap A map in which a key can occur many times
unordered_map A map using a hashed lookup
unordered_multimap A multimap using a hashed lookup
unordered_set A set using a hashed lookup
unordered_multiset A multiset using a hashed lookup

unique_ptr to represent unique ownership
shared_ptr to represent shared ownership

C++11, BS book extract, part I, chapter 3

The std::initializer_list used to define the initializer-list constructor is a standard-library type known to the compiler

A class hierarchy offers two kinds of benefits:
Interface inheritance: An object of a derived class can be used wherever an object of a base class is required.
Implementation inheritance: A base class provides functions or data that simplifies the implementation of derived classes.

The =delete mechanism is general, that is, it can be used to suppress any operation

The notation [&](int a){ return a<x; } is called a lambda expression
Had we wanted to ‘‘capture’’ only x by reference, we could have said so: [&x]. Had we wanted to give the generated object a copy of x, we could have said so: [=x]. Capture nothing is [], capture all local names used by reference is [&], and capture all local names used by value is [=].

A template can be defined to accept an arbitrary number of arguments of arbitrary types. Such a template is called a variadic template.
template<typename T, typename… Tail>
void f(T head, Tail… tail)
g(head); // do something to head
f(tail…); // tr y again with tail
void f() { } // do nothing

using instead of typedef – using size_t = unsigned int;

C++11, BS book extract, part I, chapter 2

A declaration is a statement that introduces a name into the program. It specifies a type for the
named entity:
• A type defines a set of possible values and a set of operations (for an object).
• An object is some memory that holds a value of some type.
• A value is a set of bits interpreted according to a type.
• A variable is a named object.

curly-brace-delimited initializer lists saves you from conversions that lose information - narrowing conversions

use auto where we don’t have a specific reason to mention the type explicitly.

constexpr - compile time replacement for "define", meaning roughly ‘‘to be evaluated at compile time’’, keyword for variable or function. Such function can be called with non-constexpr parameters,
but at this case, return value will non-constexpr too.
To be constexpr, a function must be rather simple: just a return-statement computing a value.

range-for-statement - for (auto x : v)


enum class - in opposite to plain old enum, it could not be converted into int.

static_assert - no surprise, just causes compile time errors if fails, example: static_assert(4<=sizeof(int), "integers are too small");