All recipes in this book are kept as simple and self-contained as possible. They are easy to compile and run, but depending on the reader’s choice of operating system and compiler, there are differences. Let’s have a look how to compile and run all the recipes, and what else to pay attention to.
What you need for this book
Compiling and running the recipes
All the code in this book has been developed and tested on Linux and MacOS, using the GNU C++ compiler, g++, and the LLVM C++ compiler, clang++.
Building an example in the shell can be done with the following command using g++:
$ g++ -std=c++1z -o recipe_app recipe_code.cpp
Using clang++, the command is similar:
$ clang++ -std=c++1z –o recipe_app recipe_code.cpp
Both the command-line examples assume that the file recipe_code.cpp is the text file containing your C++ code. After compiling the program, the executable binary will have the filename recipe_app and can be executed as follows:
$ ./recipe_app
In a lot of examples, we read the content of entire files via standard input. In such cases, we use the standard UNIX pipes and the UNIX cat command to direct the file content into our app, as follows:
$ cat file.txt | ./recipe_app
This works on Linux and MacOS. In the Microsoft Windows shell, it works as follows:
> recipe_app.exe < file.txt
If you do not happen to run your programs from the command-line shell, but from the Microsoft Visual Studio IDE, then you need to open the dialogue, "Configuration properties > Debugging", and add the "< file.txt" part to the command line of the app that Visual Studio uses for launching.
Requirements for early adopters
If you happen to read this book in the earliest days of C++17 and use bleeding- edge compilers to compile the code, you might experience that some recipes do not compile yet. This depends on how much of the C++17 STL has been implemented already in your STL distribution.
While writing this book, it was necessary to add the path prefix experimental/ to the headers <execution_policy> and <filesystem>. There might also be additional includes such as algorithm, numeric, and so on, in the experimental/ folder of your STL distribution, depending on how new and stable it is.
The same applies for the namespace of brand new features. The parts of the library that were included from the experimental part of the STL are usually exported not within the std namespace but the std::experimental namespace.