** THIS REPO IS NO LONGER MAINTAINED See the fork at bbvch for the current version**
These are examples illustrating the use of some of the C++11/14/17 features used in the booklet about C++11/14/17 language (german) produced by bbv software services
- g++ 7.0.1 - All examples compile and run
- clang 5.0.0 - All examples compile and run
- MSVC 14.1 (Visual Studio 2017) - C++14 complete, missing most of the C++17 features
Tip: use https://godbolt.org/ to test various other compilers
CMake will generate a makefile that will create an make target/executable for each *.cc file. At the moment (29. June 2017) only gcc 7.0.1 is C++17 feature complete. CMake will build makefiles for other compilers as well, but some examples will fail to compile.
To specify a non-default compiler (i.e. g++7) to use $CC
and $CXX
environment variables or use cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++-7
to specify the compiler to use.
As soon as more and more compilers are able to compile the full C++17 feature set they will be added. If you find one missing, raise an issue on github for it. https://github.com/bernedom/CPP_Booklet
$>cmake .
$>make
Or
$>cmake .
$>cmake --build . --target all
In order to link the examples in the .cc files to the printed version of the booklet the examples are annotated in code with \\@<number
CMake will parse the .cc files in the source folder for annotations for the example numbers in the print version of the booklet and split these files into files to create a syntax highlighted html file for each example. To build the html files from the splitted files run $>make html
Note whenever a new example is annotated in a .cc file cmake needs to be run again to separate the files again.
Alternatively the run separate_into_examples.py
to split the files manually.
As most make tools (GNU make, nmake) exit if a target fails to build additional options have to be passed to make to continue even on a failed target
for GNU make use $>make -i
for nmake use $>nmake -I
if using cmake to build use $>cmake --build . --target all
Some examples contain code that is intentionally to fail to compile. Usually this is done to illustrate some C++ feature. To compile the sources to allow for such failure use. Note the use of the -i flags else make stops on the first failure
$>make clean
$>make CXX_FLAGS+=-DEXPECT_FAILED_COMPILATION -i
Or if using cmake directly to build
$>cmake --build . --target all -- CXX_FLAGS+=-DEXPECT_FAILED_COMPILATION -i
clang: $>clang++ -std=c++1z file.cc -o file.exe
g++: $>g++ -std=c++17 file.cc -o file.exe
use $>clang++ -std=c++1z -S
to compile to assembler code
All examples are formatted using clang-format
$>clang-format -i file.cc
for formatting
to generate syntax highlighed html files for each file in ./source you need vim
with syntax highlighting and a colorscheme enabledd. if you have this simply run generate_html.sh
and it will drop the generated files into the folder /html