From 115ad715d5bb915864bfb83900f894880783d09c Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 20:29:42 -0500 Subject: [PATCH] sieve constructor should not allocate --- include/bmath/sieve.hh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/bmath/sieve.hh b/include/bmath/sieve.hh index d9886d7..5df219e 100644 --- a/include/bmath/sieve.hh +++ b/include/bmath/sieve.hh @@ -12,7 +12,7 @@ template requires(Limit > 0) class Sieve { public: - constexpr explicit Sieve() { static_cast(this)->build(); } + constexpr explicit Sieve() noexcept { static_cast(this)->build(); } protected: std::bitset sieve; @@ -41,13 +41,15 @@ class Eratosthenes : public Sieve, Limit> { [[nodiscard]] constexpr bool operator[](size_t const number) const { if consteval { if (number > Limit) { - throw std::out_of_range(std::format( - "cannot determine primality of {} > LIMIT={}", number, Limit)); + throw std::out_of_range( + std::format("cannot determine primality of {} > size of sieve {}", + number, Limit)); } } else { if (number > Limit) { - throw std::out_of_range(std::format( - "cannot determine primality of {} > LIMIT={}", number, Limit)); + throw std::out_of_range( + std::format("cannot determine primality of {} > size of sieve {}", + number, Limit)); } }