Language
C++
- First appeared
- 1985
- Paradigm
- Multi-paradigm, compiled, statically typed
- Toolchain
- GCC 14.2 (g++, C++23)
- Container image
debian:trixie-20261027-slim + g++-14 14.2.0-19
Bjarne Stroustrup started C++ at Bell Labs as “C with Classes”, and the first commercial release came in 1985. It keeps C’s speed and its direct access to memory and adds classes, templates, and a large standard library of containers and algorithms. Games, browsers, databases, and trading systems are written in it, and so are the engines under data science libraries such as TensorFlow, PyTorch, and XGBoost, none of which is installed here.
The implementations use C++23, compiled with g++ with every warning an
error. The standard library brings std::vector, std::map, std::sort,
and std::println, but no statistics and no matrices, so the methods are
written out.
Quirks
std::accumulateadds in the type of its starting value: from0it sums 28.6, 43.8, and 11.5 to 82, from0.0to 83.9, and the compiler doesn’t warn.- Sizes are unsigned. On a vector of 3,
v.size() - 4is 18446744073709551615, not −1. - Parentheses and braces build different vectors:
std::vector<int> a(3, 1)is three 1s, butb{3, 1}is the two numbers 3 and 1. v[5]past the end is undefined behavior, with no check;v.at(5)checks and throwsstd::out_of_range.- Template errors are long. Passing a whole vector to
std::println, which GCC 14 can’t format yet, produces 131 lines of errors.
Concepts in C++
- Cross-validation
- Decision tree
- Descriptive statistics
- k-means clustering
- k-nearest neighbors
- Linear regression
- Logistic regression
- Naive Bayes
- Principal component analysis
Run the examples locally
You need Docker and Python 3. The harness builds the pinned container and runs every C++ example:
git clone https://github.com/qnixon/dswithx.git
cd dswithx
python3 harness/run_tests.py --language cpp