From 4e951b09240dc7d058c038db8b49b8b60498d950 Mon Sep 17 00:00:00 2001 From: rhalbersma Date: Wed, 19 Jun 2024 09:43:58 +0200 Subject: [PATCH] Remove static operator() and size_t literals to accomodate MSVC --- benchmark/src/set/sieve.cpp | 2 +- include/ext/boost/dynamic_bitset.hpp | 2 +- include/ext/std/bitset.hpp | 4 ++-- include/opt/set/sieve.hpp | 2 +- include/xstd/bit_set.hpp | 22 +++++++++++----------- include/xstd/bitset.hpp | 6 +++--- test/include/bitset/exhaustive.hpp | 28 ++++++++++++++-------------- test/include/bitset/primitives.hpp | 26 +++++++++++++------------- 8 files changed, 46 insertions(+), 46 deletions(-) diff --git a/benchmark/src/set/sieve.cpp b/benchmark/src/set/sieve.cpp index 3eef304..64f49bf 100644 --- a/benchmark/src/set/sieve.cpp +++ b/benchmark/src/set/sieve.cpp @@ -11,7 +11,7 @@ #include // BOOST_PP_COMMA using Key = std::size_t; -constexpr Key N = 1'000'000uz; +constexpr Key N = std::size_t(1'000'000); template static void bm_sift_primes0(benchmark::State& state) { diff --git a/include/ext/boost/dynamic_bitset.hpp b/include/ext/boost/dynamic_bitset.hpp index fa78332..eb86656 100644 --- a/include/ext/boost/dynamic_bitset.hpp +++ b/include/ext/boost/dynamic_bitset.hpp @@ -90,7 +90,7 @@ class dynamic_bitset_iterator [[nodiscard]] value_type find_prev(value_type n) noexcept { assert(m_ptr->any()); - return *std::ranges::find_if(std::views::iota(0uz, std::ranges::min(n, m_ptr->size())) | std::views::reverse, [&](auto i) { + return *std::ranges::find_if(std::views::iota(std::size_t(0), std::ranges::min(n, m_ptr->size())) | std::views::reverse, [&](auto i) { return (*m_ptr)[i]; }); } diff --git a/include/ext/std/bitset.hpp b/include/ext/std/bitset.hpp index f30dd82..1e46d3d 100644 --- a/include/ext/std/bitset.hpp +++ b/include/ext/std/bitset.hpp @@ -148,7 +148,7 @@ class bitset_iterator [[nodiscard]] constexpr value_type find_prev(value_type n) const noexcept { assert(m_ptr->any()); - return *std::ranges::find_if(std::views::iota(0uz, n) | std::views::reverse, [&](auto i) { + return *std::ranges::find_if(std::views::iota(std::size_t(0), n) | std::views::reverse, [&](auto i) { return (*m_ptr)[i]; }); } @@ -253,7 +253,7 @@ template } else if constexpr (requires { c._Find_first(); }) { return c._Find_first(); } else { - return *std::ranges::find_if(std::views::iota(0uz, N), [&](auto i) { + return *std::ranges::find_if(std::views::iota(std::size_t(0), N), [&](auto i) { return c[i]; }); } diff --git a/include/opt/set/sieve.hpp b/include/opt/set/sieve.hpp index d64bd2f..efff899 100644 --- a/include/opt/set/sieve.hpp +++ b/include/opt/set/sieve.hpp @@ -66,7 +66,7 @@ auto filter_twins(X const& primes) { return primes | std::views::adjacent<3> - | std::views::filter([](auto&& x) static { auto&& [ prev, self, next ] = x; return self - 2 == prev || self + 2 == next; }) + | std::views::filter([](auto&& x) { auto&& [ prev, self, next ] = x; return self - 2 == prev || self + 2 == next; }) | std::views::elements<1> | std::ranges::to() ; diff --git a/include/xstd/bit_set.hpp b/include/xstd/bit_set.hpp index 6836a69..ab0bbfc 100644 --- a/include/xstd/bit_set.hpp +++ b/include/xstd/bit_set.hpp @@ -73,7 +73,7 @@ class bit_set private: static constexpr auto block_size = static_cast(std::numeric_limits::digits); static constexpr auto num_bits = aligned_size(N, block_size); - static constexpr auto num_blocks = std::ranges::max(num_bits / block_size, 1uz); + static constexpr auto num_blocks = std::ranges::max(num_bits / block_size, std::size_t(1)); std::array m_bits{}; // zero-initialization @@ -185,7 +185,7 @@ class bit_set } else if (num_blocks == 2) { return m_bits[0] == ones && m_bits[1] == used_bits; } else if (num_blocks >= 3) { - return std::ranges::all_of(m_bits | std::views::take(last_block), [](auto block) static { + return std::ranges::all_of(m_bits | std::views::take(last_block), [](auto block) { return block == ones; }) && m_bits[last_block] == used_bits; } @@ -197,7 +197,7 @@ class bit_set } else if constexpr (num_blocks == 2) { return m_bits[0] == ones && m_bits[1] == ones; } else if constexpr (num_blocks >= 3) { - return std::ranges::all_of(m_bits, [](auto block) static { + return std::ranges::all_of(m_bits, [](auto block) { return block == ones; }); } @@ -207,16 +207,16 @@ class bit_set [[nodiscard]] constexpr size_type size() const noexcept { if constexpr (N == 0) { - return 0uz; + return std::size_t(0); } else if constexpr (num_blocks == 1) { return static_cast(std::popcount(m_bits[0])); } else if constexpr (num_blocks == 2) { return static_cast(std::popcount(m_bits[0]) + std::popcount(m_bits[1])); } else if constexpr (num_blocks >= 3) { return std::ranges::fold_left( - m_bits | std::views::transform([](auto block) static { + m_bits | std::views::transform([](auto block) { return static_cast(std::popcount(block)); - }), 0uz, std::plus<>() + }), std::size_t(0), std::plus<>() ); } } @@ -581,7 +581,7 @@ class bit_set } else if constexpr (num_blocks >= 3) { return std::ranges::none_of( std::views::zip_transform( - [](auto lhs, auto rhs) static { return lhs & ~rhs; }, + [](auto lhs, auto rhs) { return lhs & ~rhs; }, this->m_bits, other.m_bits ), std::identity() @@ -605,7 +605,7 @@ class bit_set (this->m_bits[0] == other.m_bits[0] && this->m_bits[1] == other.m_bits[1]) ); } else if constexpr (num_blocks >= 3) { - auto i = 0uz; + auto i = std::size_t(0); for (/* init-statement before loop */; i < num_blocks; ++i) { if (this->m_bits[i] & ~other.m_bits[i]) { return false; @@ -616,7 +616,7 @@ class bit_set } return (i == num_blocks) ? false : std::ranges::none_of( std::views::zip_transform( - [](auto lhs, auto rhs) static { return lhs & ~rhs; }, + [](auto lhs, auto rhs) { return lhs & ~rhs; }, this->m_bits, other.m_bits ) | std::views::drop(i), std::identity() @@ -638,7 +638,7 @@ class bit_set } else if constexpr (num_blocks >= 3) { return std::ranges::any_of( std::views::zip_transform( - [](auto lhs, auto rhs) static { return lhs & rhs; }, + [](auto lhs, auto rhs) { return lhs & rhs; }, this->m_bits, other.m_bits ), std::identity() @@ -676,7 +676,7 @@ class bit_set -> std::pair { if constexpr (num_blocks == 1) { - return { 0uz, n }; + return { std::size_t(0), n }; } else if constexpr (num_blocks >= 2) { return div_mod(n, block_size); } diff --git a/include/xstd/bitset.hpp b/include/xstd/bitset.hpp index 82b3608..bc3e08c 100644 --- a/include/xstd/bitset.hpp +++ b/include/xstd/bitset.hpp @@ -47,7 +47,7 @@ class bitset } auto const rlen = std::ranges::min(n, str.size() - pos); auto const M = std::ranges::min(N, rlen); - for (auto i : std::views::iota(0uz, M)) { + for (auto i : std::views::iota(std::size_t(0), M)) { auto const ch = str[pos + M - 1 - i]; if (traits::eq(ch, zero)) { continue; @@ -191,7 +191,7 @@ class bitset [[nodiscard]] constexpr std::basic_string to_string(charT zero = charT('0'), charT one = charT('1')) const noexcept(false) { auto str = std::basic_string(N, zero); - for (auto i : std::views::iota(0uz, N)) { + for (auto i : std::views::iota(std::size_t(0), N)) { if (m_bits.contains(N - 1 - i)) { str[i] = one; } @@ -279,7 +279,7 @@ std::basic_istream& operator>>(std::basic_istream& { auto str = std::basic_string(N, is.widen('0')); charT ch; - auto i = 0uz; + auto i = std::size_t(0); for (/* init-statement before loop */; i < N && !is.eof() && (is.peek() == is.widen('0') || is.peek() == is.widen('1')); ++i) { is >> ch; if (ch == is.widen('1')) { diff --git a/test/include/bitset/exhaustive.hpp b/test/include/bitset/exhaustive.hpp index 1bd9882..66ed207 100644 --- a/test/include/bitset/exhaustive.hpp +++ b/test/include/bitset/exhaustive.hpp @@ -56,7 +56,7 @@ auto empty_set_pair(auto fun) template> auto all_valid(auto fun) { - for (auto i : std::views::iota(0uz, N)) { + for (auto i : std::views::iota(std::size_t(0), N)) { fun(i); } } @@ -64,7 +64,7 @@ auto all_valid(auto fun) template> auto any_value(auto fun) { - for (auto i : std::views::iota(0uz, N + 1)) { + for (auto i : std::views::iota(std::size_t(0), N + 1)) { fun(i); } } @@ -72,9 +72,9 @@ auto any_value(auto fun) template> auto all_cardinality_sets(auto fun) { - for (auto i : std::views::iota(0uz, N + 1)) { + for (auto i : std::views::iota(std::size_t(0), N + 1)) { auto a = make_bitset(N); - for (auto j : std::views::iota(0uz, i)) { + for (auto j : std::views::iota(std::size_t(0), i)) { a.set(j); } assert(a.count() == i); @@ -85,7 +85,7 @@ auto all_cardinality_sets(auto fun) template> auto all_singleton_sets(auto fun) { - for (auto i : std::views::iota(0uz, N)) { + for (auto i : std::views::iota(std::size_t(0), N)) { auto a = make_bitset(N); a.set(i); assert(a.count() == 1); fun(a); } @@ -97,8 +97,8 @@ template> auto all_singleton_set_pairs(auto fun) { for (auto [ i, j ] : std::views::cartesian_product( - std::views::iota(0uz, N), - std::views::iota(0uz, N)) + std::views::iota(std::size_t(0), N), + std::views::iota(std::size_t(0), N)) ) { auto a = make_bitset(N); a.set(i); assert(a.count() == 1); auto b = make_bitset(N); b.set(j); assert(b.count() == 1); @@ -112,9 +112,9 @@ template> auto all_singleton_set_triples(auto fun) { for (auto [ i, j, k ] : std::views::cartesian_product( - std::views::iota(0uz, N), - std::views::iota(0uz, N), - std::views::iota(0uz, N) + std::views::iota(std::size_t(0), N), + std::views::iota(std::size_t(0), N), + std::views::iota(std::size_t(0), N) )) { auto a = make_bitset(N); a.set(i); assert(a.count() == 1); auto b = make_bitset(N); b.set(j); assert(b.count() == 1); @@ -129,12 +129,12 @@ template> auto all_doubleton_set_pairs(auto fun) { for (auto [ j, n ] : std::views::cartesian_product( - std::views::iota(1uz, std::ranges::max(N, 1uz)), - std::views::iota(1uz, std::ranges::max(N, 1uz)) + std::views::iota(std::size_t(1), std::ranges::max(N, std::size_t(1))), + std::views::iota(std::size_t(1), std::ranges::max(N, std::size_t(1))) )) { for (auto [ i, m ] : std::views::cartesian_product( - std::views::iota(0uz, j), - std::views::iota(0uz, n) + std::views::iota(std::size_t(0), j), + std::views::iota(std::size_t(0), n) )) { auto a = make_bitset(N); a.set(i); a.set(j); assert(a.count() == 2); auto b = make_bitset(N); b.set(m); b.set(n); assert(b.count() == 2); diff --git a/test/include/bitset/primitives.hpp b/test/include/bitset/primitives.hpp index a530770..4bcfb6e 100644 --- a/test/include/bitset/primitives.hpp +++ b/test/include/bitset/primitives.hpp @@ -36,7 +36,7 @@ struct mem_bit_and_assign { auto const src = self; auto const& dst = self &= rhs; - for (auto const N = self.size(); auto i : std::views::iota(0uz, N)) { + for (auto const N = self.size(); auto i : std::views::iota(std::size_t(0), N)) { BOOST_CHECK_EQUAL(dst[i], !rhs[i] ? false : src[i]); // [bitset.members]/1 } BOOST_CHECK_EQUAL(std::addressof(dst), std::addressof(self)); // [bitset.members]/2 @@ -50,7 +50,7 @@ struct mem_bit_or_assign { auto const src = self; auto const& dst = self |= rhs; - for (auto const N = self.size(); auto i : std::views::iota(0uz, N)) { + for (auto const N = self.size(); auto i : std::views::iota(std::size_t(0), N)) { BOOST_CHECK_EQUAL(dst[i], rhs[i] ? true : src[i]); // [bitset.members]/3 } BOOST_CHECK_EQUAL(std::addressof(dst), std::addressof(self)); // [bitset.members]/4 @@ -64,7 +64,7 @@ struct mem_bit_xor_assign { auto const src = self; auto const& dst = self ^= rhs; - for (auto const N = self.size(); auto i : std::views::iota(0uz, N)) { + for (auto const N = self.size(); auto i : std::views::iota(std::size_t(0), N)) { BOOST_CHECK_EQUAL(dst[i], rhs[i] ? !src[i] : src[i]); // [bitset.members]/5 } BOOST_CHECK_EQUAL(std::addressof(dst), std::addressof(self)); // [bitset.members]/6 @@ -78,7 +78,7 @@ struct mem_bit_minus_assign { auto const src = self; auto const& dst = self -= rhs; - for (auto const N = self.size(); auto i : std::views::iota(0uz, N)) { + for (auto const N = self.size(); auto i : std::views::iota(std::size_t(0), N)) { BOOST_CHECK_EQUAL(dst[i], rhs[i] ? false : src[i]); } BOOST_CHECK_EQUAL(std::addressof(dst), std::addressof(self)); @@ -91,7 +91,7 @@ struct mem_shift_left_assign { auto const src = self; auto const& dst = self <<= pos; - for (auto const N = self.size(); auto I : std::views::iota(0uz, N)) { + for (auto const N = self.size(); auto I : std::views::iota(std::size_t(0), N)) { if (I < pos) { BOOST_CHECK(!dst[I]); // [bitset.members]/7.1 } else { @@ -108,7 +108,7 @@ struct mem_shift_right_assign { auto const src = self; auto const& dst = self >>= pos; - for (auto const N = self.size(); auto I : std::views::iota(0uz, N)) { + for (auto const N = self.size(); auto I : std::views::iota(std::size_t(0), N)) { if (pos >= N - I) { BOOST_CHECK(!dst[I]); // [bitset.members]/9.1 } else { @@ -151,7 +151,7 @@ struct mem_set if (auto const N = self.size(); pos < N) { auto const src = self; auto const& dst = self.set(pos, val); - for (auto i : std::views::iota(0uz, N)) { + for (auto i : std::views::iota(std::size_t(0), N)) { BOOST_CHECK_EQUAL(dst[i], i == pos ? val : src[i]); // [bitset.members]/15 } BOOST_CHECK_EQUAL(std::addressof(dst), std::addressof(self)); // [bitset.members]/16 @@ -175,7 +175,7 @@ struct mem_reset if (auto const N = self.size(); pos < N) { auto const src = self; auto const& dst = self.reset(pos); - for (auto i : std::views::iota(0uz, N)) { + for (auto i : std::views::iota(std::size_t(0), N)) { BOOST_CHECK_EQUAL(dst[i], i == pos ? false : src[i]); // [bitset.members]/20 } BOOST_CHECK_EQUAL(std::addressof(dst), std::addressof(self)); // [bitset.members]/21 @@ -201,7 +201,7 @@ struct mem_flip { auto const src = self; auto const& dst = self.flip(); - for (auto const N = self.size(); auto i : std::views::iota(0uz, N)) { + for (auto const N = self.size(); auto i : std::views::iota(std::size_t(0), N)) { BOOST_CHECK_NE(dst[i], src[i]); // [bitset.members]/25 } BOOST_CHECK_EQUAL(std::addressof(dst), std::addressof(self)); // [bitset.members]/26 @@ -212,7 +212,7 @@ struct mem_flip if (auto const N = self.size(); pos < N) { auto const src = self; auto const& dst = self.flip(pos); - for (auto i : std::views::iota(0uz, N)) { + for (auto i : std::views::iota(std::size_t(0), N)) { BOOST_CHECK_EQUAL(dst[i], i == pos ? !src[i] : src[i]); // [bitset.members]/27 } BOOST_CHECK_EQUAL(std::addressof(dst), std::addressof(self)); // [bitset.members]/28 @@ -260,9 +260,9 @@ struct mem_count BOOST_CHECK_EQUAL( self.count(), std::ranges::fold_left( - std::views::iota(0uz, N) | std::views::transform([&](auto i) { + std::views::iota(std::size_t(0), N) | std::views::transform([&](auto i) { return self[i]; - }), 0uz, std::plus<>() + }), std::size_t(0), std::plus<>() ) ); // [bitset.members]/43 } @@ -287,7 +287,7 @@ struct mem_equal_to auto const N = self.size(); BOOST_CHECK_EQUAL( self == rhs, - std::ranges::all_of(std::views::iota(0uz, N), [&](auto i) { + std::ranges::all_of(std::views::iota(std::size_t(0), N), [&](auto i) { return self[i] == rhs[i]; }) ); // [bitset.members]/45