mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 04:14:27 +02:00
perf: first_100_primes
moved to the static storage
This commit is contained in:
@@ -38,6 +38,7 @@ import std;
|
|||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <version>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -441,9 +442,20 @@ constexpr auto get_first_of(const Rng& rng, UnaryFunction f)
|
|||||||
return get_first_of(begin(rng), end(rng), f);
|
return get_first_of(begin(rng), end(rng), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __cpp_constexpr < 202211L
|
||||||
|
template<std::size_t N>
|
||||||
|
struct first_n_primes_impl {
|
||||||
|
static constexpr auto value = first_n_primes<N>();
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
[[nodiscard]] consteval std::uintmax_t find_first_factor(std::uintmax_t n)
|
[[nodiscard]] consteval std::uintmax_t find_first_factor(std::uintmax_t n)
|
||||||
{
|
{
|
||||||
constexpr auto first_100_primes = first_n_primes<100>();
|
#if __cpp_constexpr >= 202211L
|
||||||
|
static constexpr auto first_100_primes = first_n_primes<100>();
|
||||||
|
#else
|
||||||
|
constexpr auto first_100_primes = first_n_primes_impl<100>::value;
|
||||||
|
#endif
|
||||||
|
|
||||||
for (const auto& p : first_100_primes) {
|
for (const auto& p : first_100_primes) {
|
||||||
if (n % p == 0u) {
|
if (n % p == 0u) {
|
||||||
|
Reference in New Issue
Block a user