mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 12:54:25 +02:00
refactor: first_100_primes
refactored to use a varaible template for caching the result
This commit is contained in:
@@ -442,20 +442,12 @@ 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>
|
template<std::size_t N>
|
||||||
struct first_n_primes_impl {
|
constexpr auto first_n_primes_result = first_n_primes<N>();
|
||||||
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)
|
||||||
{
|
{
|
||||||
#if __cpp_constexpr >= 202211L
|
constexpr auto first_100_primes = first_n_primes_result<100>;
|
||||||
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