Skip to content

Commit

Permalink
Remove static operator() and size_t literals to accomodate MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
rhalbersma committed Jun 19, 2024
1 parent dc6bde9 commit 4e951b0
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion benchmark/src/set/sieve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <boost/preprocessor.hpp> // BOOST_PP_COMMA

using Key = std::size_t;
constexpr Key N = 1'000'000uz;
constexpr Key N = std::size_t(1'000'000);

template<class X>
static void bm_sift_primes0(benchmark::State& state) {
Expand Down
2 changes: 1 addition & 1 deletion include/ext/boost/dynamic_bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});
}
Expand Down
4 changes: 2 additions & 2 deletions include/ext/std/bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});
}
Expand Down Expand Up @@ -253,7 +253,7 @@ template<std::size_t N>
} 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];
});
}
Expand Down
2 changes: 1 addition & 1 deletion include/opt/set/sieve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<X>()
;
Expand Down
22 changes: 11 additions & 11 deletions include/xstd/bit_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class bit_set
private:
static constexpr auto block_size = static_cast<size_type>(std::numeric_limits<Block>::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<block_type, num_blocks> m_bits{}; // zero-initialization

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
});
}
Expand All @@ -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<size_type>(std::popcount(m_bits[0]));
} else if constexpr (num_blocks == 2) {
return static_cast<size_type>(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<size_type>(std::popcount(block));
}), 0uz, std::plus<>()
}), std::size_t(0), std::plus<>()
);
}
}
Expand Down Expand Up @@ -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()
Expand All @@ -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;
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -676,7 +676,7 @@ class bit_set
-> std::pair<size_type, size_type>
{
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);
}
Expand Down
6 changes: 3 additions & 3 deletions include/xstd/bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -191,7 +191,7 @@ class bitset
[[nodiscard]] constexpr std::basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const noexcept(false)
{
auto str = std::basic_string<charT, traits, Allocator>(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;
}
Expand Down Expand Up @@ -279,7 +279,7 @@ std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>&
{
auto str = std::basic_string<charT, traits>(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')) {
Expand Down
28 changes: 14 additions & 14 deletions test/include/bitset/exhaustive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@ auto empty_set_pair(auto fun)
template<class X, auto N = limit_v<X, L1>>
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);
}
}

template<class X, auto N = limit_v<X, L1>>
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);
}
}

template<class X, auto N = limit_v<X, L1>>
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<X>(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);
Expand All @@ -85,7 +85,7 @@ auto all_cardinality_sets(auto fun)
template<class X, auto N = limit_v<X, L1>>
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<X>(N); a.set(i); assert(a.count() == 1);
fun(a);
}
Expand All @@ -97,8 +97,8 @@ template<class X, auto N = limit_v<X, L2>>
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<X>(N); a.set(i); assert(a.count() == 1);
auto b = make_bitset<X>(N); b.set(j); assert(b.count() == 1);
Expand All @@ -112,9 +112,9 @@ template<class X, auto N = limit_v<X, L3>>
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<X>(N); a.set(i); assert(a.count() == 1);
auto b = make_bitset<X>(N); b.set(j); assert(b.count() == 1);
Expand All @@ -129,12 +129,12 @@ template<class X, auto N = limit_v<X, L4>>
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<X>(N); a.set(i); a.set(j); assert(a.count() == 2);
auto b = make_bitset<X>(N); b.set(m); b.set(n); assert(b.count() == 2);
Expand Down
26 changes: 13 additions & 13 deletions test/include/bitset/primitives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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));
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit 4e951b0

Please sign in to comment.