From e1b0fb7e6e65329c2b0845e48a7cfb912e780bd5 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 16 Nov 2024 22:00:21 +0100 Subject: [PATCH] refactor: `first_100_primes` refactored to use a varaible template for caching the result --- src/core/include/mp-units/ext/prime.h | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/core/include/mp-units/ext/prime.h b/src/core/include/mp-units/ext/prime.h index a5a8f106..ebb3e0e2 100644 --- a/src/core/include/mp-units/ext/prime.h +++ b/src/core/include/mp-units/ext/prime.h @@ -442,20 +442,12 @@ constexpr auto get_first_of(const Rng& rng, UnaryFunction f) return get_first_of(begin(rng), end(rng), f); } -#if __cpp_constexpr < 202211L template -struct first_n_primes_impl { - static constexpr auto value = first_n_primes(); -}; -#endif +constexpr auto first_n_primes_result = first_n_primes(); [[nodiscard]] consteval std::uintmax_t find_first_factor(std::uintmax_t n) { -#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 + constexpr auto first_100_primes = first_n_primes_result<100>; for (const auto& p : first_100_primes) { if (n % p == 0u) {