Quickstart
Why C++
C++ has always been a great language for Scientific Computing, High-Performance Computing, and Data Analysis:
- Most programmers are familiar with its basic syntax;
- It's been among the most popular languages over last 40 years;
- Access to hundreds of thousands of high-performance libraries;
- Performance level almost no other language can achieve;
- Complex abstractions with zero-overhead;
- Easy access to parallelism;
- Numerous compilers with great optimization options available;
- Innumerable target platforms, from microcontrollers, to GPUs, to mobile, to webassembly;
- Does not rely on any virtual machine;
- Easy bindings from/to virtually any other programming language (Python , Javascript, PHP, R , Java, Matlab , Rust , Swift , Julia, C, ... you name it);
- Great tools for static analysis to avoid bugs;
- Avoids the two-languages problem in scientific computing: one for prototyping and one to reimplement all the work once the experiments are successful;
- No need for special licenses to distribute your compiled code, like it is common in technical languages that rely on virtual machines;
- Allows saving tons of money and extra-security for applications to be run in the cloud or dedicated servers.
Why Modern C++
Many people have move from C++ over the last decade and might not be aware that the Modern C++ ecosystem has evolved to cover almost all use cases that made C++ inconvenient for certain tasks in the past:
- Efficient interpreters with beautiful IDEs;
- Cross-platform build systems, including microcontrollers , GPUs , mobile and webassembly;
- Package managers;
- Type deduction;
- Variant types;
- Types for optional data;
- Cheap automatic memory management via smart pointers;
- Numerous data structures out of the box;
- Modules;
- Concepts;
- Functional programming;
- Convenient meta programming;
- Structured bindings and tuples;
- Ranges;
- Move semantics.
By incentivizing and highlighting modern C++ features in instructional content , it's also possible to combine the familiar syntax of C and old C++ to achieve high levels of abstraction with a gentle learning curve.
How this repository works
Snippets
- The
snippets
directory has lots of short programs with useful C++ snippets - GitHub actions ensures all snippets are working on GCC, MSVC, and Clang.
- We generate GitHub pages with all snippets by groups of tasks
Libraries
We give preference to libraries in this order:
- Libraries supported by most C++ compilers
- Libraries accepted into the C++ standard
- Libraries likely to be accepted into the next C++ standard
- Libraries representative of existing practice
External Libraries
For external libraries, we also include a short CMake snippet in the build script with:
find_package
to find, setup, and link the large external librariesFetchContents
to download, build, and link the external library
Snippets and Examples
Examples are often long and don't represent independent tasks you can copy and paste. Snippets represent independent tasks you can copy and paste.
Why not get my snippets directly from cppreference
or cplusplus.com
?
cppreference
is not meant for snippets and this repository is not meant to be a reference for the C++ standard. Some
implications are:
- The snippets:
- Meant to list the commands you most often need in a library.
- Lots of independent tasks for copying and pasting
- Include corresponding build scripts when something more complex is required
- Include external libraries when it's existing practice
- Organized roughly in the order someone learning C++ might need them
- The examples in cppreference or cplusplus.com:
- Meant to make points about the internals of the libraries.
- A single task meant to prove a point
- Has nothing to do with build scripts
- Has nothing to do with external libraries
- Might mix simple and complex concepts to make a point
GitHub Pages
We generate GitHub pages with all snippets:
- The GitHub pages are generated with mkdocs material
- Snippets are categorized by groups of tasks
- Sections are easy to explore, copy, and paste