...one of the most highly
regarded and expertly designed C++ library projects in the
world.

— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards

#include <boost/math/special_functions/prime.hpp>

namespace boost { namespace math { template <class Policy> constexpr std::uint32_t prime(unsigned n, const Policy& pol); constexpr std::uint32_t prime(unsigned n); static const unsigned max_prime = 10000; }} // namespaces

The function `prime`

provides
fast table lookup to the first 10000 prime numbers (starting from 2 as the
zeroth prime: as 1 isn't terribly useful in practice). There are two function
signatures one of which takes an optional Policy
as the second parameter to control error handling.

The constant `max_prime`

is
the largest value you can pass to `prime`

without incurring an error.

Passing a value greater than `max_prime`

results in a domain_error
being raised.

This function is `constexpr`

only
if the compiler supports C++14 constexpr functions.