Commit f14eeae2 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Cleanup lecture, remove later chapters and extend the presentation in the...

Cleanup lecture, remove later chapters and extend the presentation in the variables-and-datatypes chapter
parent 575314b6
......@@ -20,137 +20,18 @@
[]: exercises/
## General information
### Submission of solutions
*Summary of the lecture*
You may submit solutions to exercises to the corresponding tutorial repository
Access to the repository will be given in the first tutorials. We will create an
account in this local GitLab platform with your ZIH username. When created, you
will receive an invitation email to set your password. Then you will get access
to the tutorial project. The submission procedure is described there. Please read the
instructions carefully. Ask the tutor (@spraetor) if you have any further questions.
*general information about the structure of lecture and tutorial*
In this module SCPROG the exercises and projects will be submitted online into a version
control system [Git]( hosted at the MatNat [GitLab](
platform, which is a web-based Git repository manager similar to [GitHub](
and [Bitbucket](
Handing in solutions to exercises and projects digitally on such a platform is a
good way of learning and training collaborative coding, which is commonplace in
Scientific Computing research groups.
Additionally to the learning effect, you can collect points for submitted exercises
that may eventually lead to an improvement in you final exam by at most a grade 0.3. To
reach this bonus, you have to gain 66% of the possible exercise points (max. = 100).
In order to allow fast correction and evaluation of submitted solutions, we require
a predefined structure of the repositories and coding styles to be followed. Not
following these rules for repositories may result in your solution not being reviewed.
You will then have to reformat it and submit again. Not following the style guidelines
may result in point deduction, with the amount of points depending on the impact your
style could have on actual collaborative projects.
# Your Repository on GitLab
## Account
In the first tutorial we will create an account on the local GitLab platform,
using the ZIH-Login (s...-number) for the account user name associated to your TU-Dresden
email address. This ensures that you will get credit for your submissions.
## Project Name
Please form groups of up to two members and exchange contact details so you can find
each other on GitLab. One of you should create a *private* (!) project, and invite the rest
of the group. The name of your project is `scprog-Name1Name2`, where `Name1`
is the last name of the first student, `Name2` that of the second student. These
names should be sorted alphabetically. If your lineup changes for any reason during the
course of the semester, please create a new project that reflects this and inform your
## Directory Structure
Your repository should consist of two levels of directories, one for the exercise sheets and
one for the individual exercises. This results in a tree structure like this:
+-- exercise1
| +--
| +-- solution.txt
| \-- <header and source files>
+-- exercise2
| \-- <files as above>
\-- (...)
+-- exercise1
+-- exercise2
\-- (...)
You are free to name and structure your C++ files in any way you like, but there
should always be a file named `` that is a sample application of your implemented
classes. Often the content is given in the exercise, if it isn’t you are free to choose
sensible test cases yourselves. Make sure that this file `` can be compiled with
the command given in the lecture, or alternatively provide a [MakeFile](
or [CMakeLists.txt]( that builds the exercise.
The file `solution.txt` is meant for the output of your `` and for answering
questions that appear in the exercises. If an exercise is of theoretical nature and doesn’t
include actual coding, this is the only file you have to submit. Optionally you can
submit a [Markdown]( file ``
instead. This allows basic formatting of the text.
## Access to the Repository
Please give your tutor @spraetor write access (at least Reporter status) to your project so that
your submissions can be graded.
# Submission of Exercises
On each exercise sheet some exercises are marked for submission with in sum 10 possible exercise points.
You have approximately two weeks for each of these exercises, where the final date is written
next to the exercise. In order to get your solutions reviewed, it has to be committed to your
GitLab repository following the procedure:
1. For each exercise sheet create a new branch called `sheetX` where `X` is the number of
the sheet.
2. Create the new directory following the directory structure as above
3. Commit your solutions to the branch
4. Create a merge request to your master branch
After final review of your submission (and maybe inclusion of your corrections)
you get a comment in the MergeRequest section of GitLab and a :thumbsup:. This allows you to merge
your branch into your `master` branch.
# Style Guidelines
All programs you submit should follow basic programming rules like the following:
- **Formatting**
- Put each instruction on a separate line (two lines if it is very large)
- Use spaces to separate variable names, functions and operators
- Indent your lines to visually mark different lines belonging to different scopes
- **Variable names**
- The name should reflect the purpose of the variable
- Variable names start with a lowercase letter, types with an uppercase letter
- The rest of the name format for identifiers is up to you
- Simple counting integers and similar variables are exceptions
- **Comments**
- Comments allow others to understand your intentions
- Tutors can only give you points if they understand what you were trying to do
- *Guideline:* one comment per class, per function, per algorithm subtask, per tricky or "exotic" source line
- Don't comment to much either, this may visually drown the actual code or diverge from what is actually coded (!)
- Leave out trivial comments ("This is the constructor")
- **Language constructs**
- You may use any construct you want, even if it has not yet been introduced in the lecture
- Avoid constructs that have been superseded by better alternatives in the lecture
- Declare variables and references as `const` where it is possible
- Separate interface and implementation by correctly using public and private
- Use smart pointers instead of raw pointers once the lecture has introduced them
Optionally, see [Google C++ Style Guide]( for
more rules and guidelines on the coding style. Also, see the
[C++ Core Guidelines](
for a comprehensive list of best practice programming rules for C++.
# More reading
## More reading
Online references and literature useful for completing the exercises are listed below:
- **Online-References:**
......@@ -164,14 +45,4 @@ Online references and literature useful for completing the exercises are listed
- **Tutorials:**
- [MTL4](, [Git](
- **Compiler:**
- [GCC](, [Clang](, [Intel Icc](
- **Books:**
- Discovering Modern C++: An Intensive Course for Scientists, Engineers, and Programmers, Peter Gottschling, 2015:
[slub](, [online](
- *References:* Die C++ Programmiersprache (Bjarne Stroustrup),
C++ Kurz & Gut (Kyle Loudon, Rainer Grimm): [slub](
- *Beginners:* C++ Primer (Stanley Lippman, Josee Lajoie, Barbara E. Moo): [online](
- *Intermediate level:* Effective Modern C++ (Scott Meyers): [slub](, [online](,
C++ Templates: The Complete Guide (David Vandevoorde, Nicolai M. Josuttis): [online](
- *Experts:* Modern C++ Design (Andrei Alexandrescu): [online](,
C++ Template Metaprogramming (David Abrahams, Aleksey Gurovoy): [online](
- [GCC](, [Clang](, [Intel Icc](
\ No newline at end of file
\begin{zitat}{Bjarne Stroustrup (1994) \cite{stroustrup1994design}}
``It would be nice if every kind of numeric software could be written in C++ without loss of efficiency, but unless something can be found that achieves this without compromising the C++ type system it may be preferable to rely on Fortran, Assembler or architecture-specific extensions.''
``It would be nice if every kind of numeric software could be written in C++ without loss of efficiency, but unless something
can be found that achieves this without compromising the C++ type system it may be preferable to rely on Fortran, Assembler or
architecture-specific extensions.''
Scientific programming is an old discipline in computer science. The first applications on computers were indeed computations.
......@@ -52,8 +54,8 @@ that can represent our real-valued matrix $A$ and vector $\mathbf{x}$:
// initialize x
We want to solve the task $\mathbf{y} = \alpha A\mathbf{x} + \beta \mathbf{y}$ (accumulated matrix-vector multiplication) with $\mathbf{y}\in\mathbb{R}^n$ initialized to zero
and $\alpha=\beta=1$ for simplicity.
We want to solve the task $\mathbf{y} = \alpha A\mathbf{x} + \beta \mathbf{y}$ (accumulated matrix-vector multiplication) with
$\mathbf{y}\in\mathbb{R}^n$ initialized to zero and $\alpha=\beta=1$ for simplicity.
DenseVector y(n, 0.0);
......@@ -111,56 +113,6 @@ performance and how to test and optimize your implementation. Classical design p
the twin lecture SCPROG -- Fortgeschrittene Konzepte des Wissenschaftlichen Programmierens: OOP mit Java -- by Prof. W. Walter.
% \section{Structure of the lecture and tutorial}
% This module focuses on three learning goals:
% \begin{enumerate}[1)]
% \item Programming with C++
% \item Working with programming tools
% \item Discovering scientific C++ software libraries
% \end{enumerate}
% There will be a tutorial every week with exercises. The corresponding exercise sheets can be found online in a Git repository at
% \url{}
% On each exercise sheet there are a few exercises marked for submission. Approximately two weeks you have time to work on the tasks
% and are supposed to submit your solutions into the Git repository itself. Therefore, in the first tutorials you get an account and
% have to create a Git project on the TU-Dresden local GitLab server \url{}. The details about this are
% explained on the repository README page and are presented in the first tutorial. The advantage you have from submitting the exercises
% is 1. you get a personal review and feedback, 2. you learn how to work in a cooperative environment on scientific projects, and 3. you
% can get a bonus for the final oral exam (reaching 66\% of the possible exercise points gives a bonus of up to a grade of 0.3).
% \subsection{Course outline}
% \begin{itemize}
% \item Best practice in scientific programming
% \item C++ basics (data-types, operators, pointers, arrays, references, $\ldots$)
% \item Scopes, Namespaces, Functions
% \item Overloading, Specialization
% \item Basics of object-oriented class design, inheritance, polymorphie
% \item Generic Programming with templates
% \item Generic Design patterns (Functors, Iterators, Type-Traits)
% \item Algorithms and Data-Structures in the C++ standard library
% \item Meta-Programming
% \item Expression-Templates
% \item (Compile-Time symbolic differentiation)
% \end{itemize}
% \section{Literature and material}
% There is a lot of good (and a lot of bad) literature on C++ programming. Some references with links to the Slub and to online sources
% are given on the website
% \url{}
% on the subpage \texttt{Teaching/Scientific Programming with C++}, or on the README page of the repository as above. The main source for reference of C++ is the nearly complete online standard at
% \url{}
% and the official standard
% \url{}, or \\
% \url{}
\section{History of C++}
The programming language has a long history, that is described in the books by Bjarne Stroustrup: \emph{The Design and Evolution of C++, 1994},
\url{} (\emph{A History of C++: 1979--1991}) and \url{}
This diff is collapsed.
We have see already in the initial example the usage of arithmetic and many other \emph{operators}. Operators are special functions with typically prefix-notation (for unary operators) and infix notation (for binary operators) and are written with the classical mathematical symbols. In the initial example, we had \texttt{+, -, *, ::, ., <<, = , ",", ()}.
We call operators acting on one operand \emph{unary operators} (like \texttt{-, *, \&}), acting on two operands \emph{binary operator} (like \texttt{+, -, *, /, =, +=, ...}) and even acting on three operands a \emph{ternary operators} (there is only \texttt{?:}).
Operators are characterized by its properties: \emph{associativity}, \emph{precedence}, and whether they can be \emph{overloaded}.
% -------------------------------------------------------------------------------------------------
Operator associativity means the property of an operator determining the order in which to evaluate multiple occurrences of this operator in an expression without changing the result of the evaluation.
Only in \emph{associative compositions} the result depends on the associativity. In order to fix the meaning of expressions with multiple
similar operators without brackets we introduce the convention
\item A \emph{left-associative operator} is evaluated from left to right.
\item A \emph{right-associative operator} is evaluated from right to left.
All (binary) operators are classified as left or right associative
Binary arithmetic operations are \emph{left-associative}: (\texttt{+, -, *, /, \%, <, >, \&\&, ||})
\cpp{a + b + c} is equivalent to \cpp{(a + b) + c}
Assignment operators are \emph{right-associative}: (\texttt{=, +=, <<=, ...}), \ie the expression
\cpp{x= y= z} is evaluated from right to left and thus equivalent to: \cpp{x= (y= z)}
% -------------------------------------------------------------------------------------------------
Operators are ordered by its precedence. This defines a \emph{partial ordering} of the operators and specified which operators is evaluated first. The precedence can be overridden using brackets.
From basic arithmetics you know the precedence of some arithmetic operators, especially \texttt{+, -, *, /}. This precedence is known in some countries as mnemonics:
\item Germany: \textit{Punktrechnung geht vor Strichrechnung}, meaning Multiplication/Division before Addition/Subtraction
\item United States: \textbf{PEMDAS}: Parentheses, Exponents, Multiplication/Division, Addition/Subtraction. PEMDAS is often expanded to the mnemonic ``\textit{Please Excuse My Dear Aunt Sally}''.
\item Canada and New Zealand: \textbf{BEDMAS}: Brackets, Exponents, Division/Multiplication, Addition/Subtraction.
\item UK, Pakistan, India, Bangladesh and Australia and some other English-speaking countries: \textbf{BODMAS}: Brackets, Order, Division/Multiplication, Addition/Subtraction or Brackets, Of/Division/Multiplication, Addition/Subtraction.
An example with classical mathematical operators on integers:
x &= 2 * 2 + 2\, /\, 2 - 2\quad\Rightarrow\quad x = \left(\left(\left(2 * 2\right) + \left(2 / 2\right)\right) - 2\right) = 3 \\
y &= 8 / 2 * (2 + 2)\quad\Rightarrow\quad y = (8 / 2) * (2 + 2) = 16
The operator \cpp{^} does not mean exponentiation or power, but the logical X-Or. In Matlab/Octave this operator has the expected meaning, but in C++ the operator has a different precedence than the power operator would have from a mathematical perspective.
This means:
\cppline{a = b^2 + c}
is equivalent to
\cppline{a = b^(2 + c)}
\cppline{a = (b^2) + c}
There is no power operator in C++! You have to call the function \cpp{std::pow} instead.
When in doubt or to clarify the expression: use parentheses.
% -------------------------------------------------------------------------------------------------
\subsection{Examples of operators}
In the table below, the operators are ordered by precedence and information about associativity is given. Here I give you a summary of most of the operators and its meaning. Most of the operators are defined for arithmetic types (integers or floating-point numbers), but some are also defined for library types, like \cpp{std::string}, \cpp{std::vector} and others.
\subsubsection*{Arithmetic operators}
Operator & Action \\
\cpp{-} & Subtraction (unary minus) \\
\cpp{+} & Addition (unary plus) \\
\cpp{*} & Multiplication \\
\cpp{/} & Division \\
\cpp{%} & Modulo = Reminder of division, \ie for integers: if \cpp{r = a % b}, then there exists \cpp{c}, such that \cpp{a=b*c + r} \\
\cpp{--} & Decrement (Pre- and Postfix), \ie \cpp{--a} is equivalent to \cpp{a = a - 1}\\
\cpp{++} & Increment (Pre- and Postfix), \ie \cpp{++a} is equivalent to \cpp{a = a + 1} \\
int operator++(int& a, int) { // a++
int r = a;
a += 1;
return r;
int& operator++(int& a) { // ++a
a += 1
return a;
\subsubsection*{Boolean operators}
Logical operators and comparison operators
Operator & Action \\
\cpp{>} & greater than \\
\cpp{>=} & greater than or equal to \\
\cpp{<} & less than \\
\cpp{<=} & less than or equal to \\
\cpp{==} & equal to \\
\cpp{!=} & unequal to \\
\cpp{&&} & AND \\
\cpp{||} & OR \\
\cpp{!} & NOT \\
The result of a boolean expression is a \cpp{bool} value, \eg
\cppline{bool out_of_bound = x < min_x || x > max_x}
With \cxx{20}\marginpar{[\cxx{20}]} a new comparison operator is introduced, called \emph{three-way comparison operator} or sometimes also \emph{space-ship operator}. It is written as \cpp{<=>} and returns an object such that
\item \cpp{(a <=> b) < 0} if \cpp{lhs < rhs}
\item \cpp{(a <=> b) > 0} if \cpp{lhs > rhs}
\item \cpp{(a <=> b) == 0} if \cpp{lhs} and \cpp{rhs} are equal/equivalent.
and the returned object indicates the type of ordering (strong ordering, partial ordering, weak equality, ...).
\subsubsection*{Bitwise operators}
Modify or test for the bits of integers
Operator & Action \\
\cpp{&} & AND \\
\cpp{|} & OR \\
\cpp{^} & exclusive OR \\
\cpp{~} & 1-complement \\
\cpp{>>} & right-shift of the bits \\
\cpp{<<} & left-shift of the bits \\
The logical operators \cpp{<<} and \cpp{>>} are used in C++ often in a different context, namely to \emph{shift} something into a \emph{stream}. Streams are abstractions devices allowing input and output operations. The operator \cpp{<<} is therefore called \emph{insertion operator} and is used with output streams, whereas the operator \cpp{>>} is called \emph{extraction operator} and is used with input streams.
While a modern CPU efficiently implements arithmetic and logical operators on integers, one could implement those manually, by using bitwise operations and comparison with 0 only. The following pseudo code implements multiplication of two integers \texttt{a} and \texttt{b} with bit shifts, comparison and addition:
c := 0
solange b <> 0
falls (b und 1) <> 0
c := c + a
schiebe a um 1 nach links
schiebe b um 1 nach rechts
return c
It implements kind of a manual multiplication in the binary base but in the uncommon order from right to left.
\footnote{See \url{}}
As an exercise, you could implement this algorithm and compare the result with the classical multiplication.
\subsubsection*{Assignment operators}
Compound-assignment operators like \cpp{+=, -=, *=, /=, %= >>=, <<=, &=, ^=, |=} apply an operator to the left and right-side of an assignment, and store the result in the left operand.
\cppline{a += b // corresponds to a = a + b}
Compared to the simple assignment, a compound-assignment does not need to create a temporary and maybe copy it to the left-hand side operand, but works with the operand directly.
struct A { double value; };
A operator+(A const& a, A const& b) {
A c(a); // create local copy of a
c += b;
return c;
A& operator+=(A& a, A const& b) {
a.value += b.value;
return a;
\subsubsection*{Bracket-Access operators}
The round brackets \cpp{()} and the square brackets \cpp{[]} also represent operators, namely \emph{bracket-access operators}. While the square bracket is typically used as vector access and allows only one argument, \eg the vector element index, the round brackets represent a function call and thus allow any number of arguments \texttt{>= 0}.
\subsection*{Sequence of evaluation and side effects}
A sequence point defines any point in a computer program's execution at which it is guaranteed that all side effects of previous evaluations will have been performed, and no side effects from subsequent evaluations have yet been performed.
A side effect is, for example, the change of a variable not directly involved in the computation.
Logical and-then/or-else (\cpp{&&} and \cpp{||}) operators, ternary \cpp{?:} question mark operators, and commas \cpp{,} create sequence points; \cpp{+, -, <<} and so on do not!
With \cxx{17}\marginpar{[\cxx{17}]} several more operations are now sequenced and are safe to include side effects. But in general, you should know that
When you use an expression with side effects multiple times in the absence of sequence points, the resulting behavior is \textbf{undefined} in C++. Any result is possible, including one that does not make logical sense.
See also: \href{}{Wikipedia}, \href{}{}
For logical operators, at first the left operand is evaluated and based on its value it is decided whether to evaluate the right operand at all or not, \ie
A && B // first evaluate A, if A == true evaluate B and return its value
A || B // first evaluate A, if A == false, evaluate B and return its value
A ? B : C // first evaluate A, if true, evaluate B, otherwise evaluate C
(A,B,C, ...) // first evaluate A, then evaluate B, then evaluate C, ...
f() + g() // it is not specified whether f is evaluated first or g
Never rely on a function call in a logical expression.
The precedence property is not related to the order of evaluation, but to the rank of the operator. For an arbitrary function \cpp{f(a,b,c,d)} it
is not specified in which order the expressions for a, b, c, d are evaluated.
The following expressions have different behavior:
int foo(int a, int b) { return a + b; }
int x = 1;
foo(++x, x++); // Variant 1 (unspecified behavior)
x = 1;
int a = ++x, b = x++;
foo(a, b); // Variant 2 (behavior defined)
\subsection{Operators as functions}
In C++ nearly all operator can be written (and called) as a regular function. Let \texttt{o} be the symbol of the operator, \eg \texttt{o$~\in$\{+,*,(),+=,<,...\}}, then there zero, one or both of the following implementations are available:
Result operator o(Arg1 a, Arg2 b, ...) // a o b
Result Arg1::operator o(Arg2 b, ...) // Arg1 a; a o b
The variant 1 implement the operator as a free function, whereas the variant 2 implements the operator as a member function of a class, where \texttt{Arg1} is the name of that class. Whether there is a function representation of the operator and whether it is allowed to \emph{overload} that function is specified in the table below.
\textbf{\small Precedence} & \textbf{Operator} & \textbf{Description} & \textbf{Associativity} & \textbf{\small Overload} \\
1 = highest & \cpp{::}& Scope resolution & Left-to-right & ---\\
2 & \cpp{++} \cpp{--} & Suffix/postfix increment and decrement & Left-to-right & $\checkmark$ $\checkmark$ \\
& \cpp{()} & Function call & & (C)\\
& \cpp{[]} & Subscript & & (C)\\
& \cpp{. ->} & Member access & & --- (C)\\
3 & \cpp{++ --} & Prefix increment and decrement & Right-to-left & $\checkmark$ $\checkmark$ \\
& \cpp{+ -} & Unary plus and minus & & $\checkmark$ $\checkmark$\\
& \cpp{! ~} & Logical NOT and bitwise NOT & & $\checkmark$ $\checkmark$\\
& \cpp{*} & Indirection (dereference) & & $\checkmark$\\
& \cpp{&} & Address-of & & $\checkmark$\\
4 & \cpp{.* ->*} & Pointer-to-member & Left-to-right & --- $\checkmark$ \\
5 & \cpp{* / %} & Multiplication, division, and remainder& & $\checkmark$ $\checkmark$ $\checkmark$ \\
6 & \cpp{+ -} & Addition and subtraction & & $\checkmark$ $\checkmark$\\
7 & \cpp{<< >>} & Bitwise left shift and right shift & & $\checkmark$ $\checkmark$\\
8 & \cpp{<=>} & Three-way comparison operator (\cxx{20}) & & $\checkmark$\\
9 & \cpp{< <=} & For relational operators $<$ and $\leq$ respectively & & $\checkmark$ $\checkmark$\\
& \cpp{> >=} & For relational operators $>$ and $\geq$ respectively & & $\checkmark$ $\checkmark$\\
10 & \cpp{== !=} & For relational operators $=$ and $\neq$ respectively & & $\checkmark$ $\checkmark$\\
11 & \cpp{&} & Bitwise AND & & $\checkmark$\\
12 & \cpp{^} & Bitwise XOR (exclusive or) & & $\checkmark$\\
13 & \cpp{|} & Bitwise OR (inclusive or) & & $\checkmark$\\
14 & \cpp{&&} & Logical AND & & $\checkmark$\\
15 & \cpp{||} & Logical OR & & $\checkmark$\\
16 & \cpp{?:} & Ternary conditional & Right-to-left & ---\\
& \cpp{=} & Direct assignment & & (C)\\
& \cpp{#=} & Compound assignment operators [note 1] & & $\checkmark$\\
17 = lowest & \cpp{,} & Comma & Left-to-right & $\checkmark$
[note 1]: \#$~\in\{$\cpp{+, -, *, /, %, <<, >>, &, ^, |}$\}$
In the column \textit{Overload} means (C), the operator can only be implemented as member function of a class, whereas $\checkmark$ allows to write the operator as member function or free function.
A more complete table can also be found at \url{\_operators}, or \url{}.
This diff is collapsed.
\section{References and Pointers\label{sec:references}}
Although used already, the references need a revisit. References can be understood as alias to (existing) objects. Compared to classical
pointer, they do not represent the address of the references object, but the data of the objects directly.
A reference can be declared like a regular variable, using the reference qualifier \texttt{\&}:
TYPE & var1 = aliased_objekt; // (1)
TYPE && var2 = aliased_objekt; // (2) ... since C++11
Where (1) is called a lvalue-reference \index{Reference!lvalue reference} and (2) a rvalue-reference \index{Reference!rvalue reference}. A reference
must be initialized directly and since it is not possible to change where reference refers to.
int i = 0;
int& r = i; // r references i
r = 1; // changes the value of i => i == 1
i = 2; // also r == 2
References itself are not objects and do not need own memory. That is why there are no arrays of references and no references of references!
int& a[3]; // error
int& &r; // error
% -------------------------------------------------------------------------------------------------
\subsection{lvalues and rvalues / value categories}
See \url{}:
Each C++ expression (an operator with its operands, a literal, a variable name, etc.) is characterized by two independent properties:
a \emph{type} and a \emph{value category}. Each expression has some non-reference type, and each expression belongs to exactly one of the three
primary value categories: \emph{prvalue}, \emph{xvalue}, and \emph{lvalue}.
\item a \emph{glvalue} (``generalized'' lvalue) is an expression whose evaluation determines the identity of an object, bit-field, or function;
\item a \emph{prvalue} (``pure'' rvalue) is an expression whose evaluation either \begin{itemize}
\item computes the value of the operand of an operator (such prvalue has no result object), or
\item initializes an object or a bit-field (such prvalue is said to have a result object). All class and array prvalues have a result object
even if it is discarded. In certain contexts, temporary materialization occurs to create a temporary as the result object;
\item an \emph{xvalue} (an ``eXpiring'' value) is a \emph{glvalue} that denotes an object or bit-field whose resources can be reused;
\item an \emph{lvalue} (so-called, historically, because lvalues could appear on the left-hand side of an assignment expression) is a
\emph{glvalue} that is not an \emph{xvalue};
\item an \emph{rvalue} (so-called, historically, because rvalues could appear on the right-hand side of an assignment expression) is a
\emph{prvalue} or an \emph{xvalue}.
This categorization results from the idea that every expression can be characterized by two orthogonal properties:
\item[i] \textbf{has identity}: Object that has an address, a pointer, the user can determine whether 2 copies are identical
\item[m] \textbf{can be moved from}: We are allowed to leave the source of a ``copy'' in some indetermined, but valid, state.
\item[$\sim$] has not the property.
The combination \texttt{($\sim$i)($\sim$m)} does not really exists and thus, we have three leaf categories, see Figure.
Examples for lvalues, rvalues, and prvalues:
int i = 3;
int j = 4;