Modern C++ equivalent of Python os.cpu_count()

The C++ equivalent (since C++11 from 2011) of Python’s

example.py
os.cpu_count()

is

example.cpp
#include <thread>

std::thread::hardware_concurrency()

Also see the docs for std::thread::hardware_concurrency() on cppreference.com.


Check out similar posts by category: C/C++