diff --git a/src/openrct2/core/BitSet.hpp b/src/openrct2/core/BitSet.hpp index bb5e97dd9e..25d5eb1394 100644 --- a/src/openrct2/core/BitSet.hpp +++ b/src/openrct2/core/BitSet.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -118,7 +119,7 @@ namespace OpenRCT2 static constexpr size_t block_count = storage_capacity_bits / block_type_bit_size; static constexpr storage_block_type block_init_value{}; - static constexpr storage_block_type block_mask_value = ~block_init_value; + static constexpr storage_block_type block_mask_value = static_cast(~block_init_value); static constexpr bool requires_trim = TBitSize != storage_capacity_bits; @@ -449,25 +450,26 @@ namespace OpenRCT2 constexpr bool operator<(const BitSet& other) const noexcept { - return std::lexicographical_compare(data_.begin(), data_.end(), other.data_.begin(), other.data_.end(), std::less); + return std::lexicographical_compare( + data_.begin(), data_.end(), other.data_.begin(), other.data_.end(), std::less{}); } constexpr bool operator<=(const BitSet& other) const noexcept { return std::lexicographical_compare( - data_.begin(), data_.end(), other.data_.begin(), other.data_.end(), std::less_equal); + data_.begin(), data_.end(), other.data_.begin(), other.data_.end(), std::less_equal{}); } constexpr bool operator>(const BitSet& other) const noexcept { return std::lexicographical_compare( - data_.begin(), data_.end(), other.data_.begin(), other.data_.end(), std::greater); + data_.begin(), data_.end(), other.data_.begin(), other.data_.end(), std::greater{}); } constexpr bool operator>=(const BitSet& other) const noexcept { return std::lexicographical_compare( - data_.begin(), data_.end(), other.data_.begin(), other.data_.end(), std::greater_equal); + data_.begin(), data_.end(), other.data_.begin(), other.data_.end(), std::greater_equal{}); } private: diff --git a/test/tests/BitSetTests.cpp b/test/tests/BitSetTests.cpp index e192ec58fe..b978338780 100644 --- a/test/tests/BitSetTests.cpp +++ b/test/tests/BitSetTests.cpp @@ -14,7 +14,7 @@ using namespace OpenRCT2; TEST(BitTest, test_index_construction) { - BitSet<64> bits({ 0u, 2u, 4u, 6u, 8u, 10u }); + BitSet<64u> bits({ 0u, 2u, 4u, 6u, 8u, 10u }); #ifdef _M_X64 static_assert(std::is_same_v); #else @@ -23,13 +23,13 @@ TEST(BitTest, test_index_construction) constexpr auto size = sizeof(bits); static_assert(size == 8u); - ASSERT_EQ(bits.data()[0], 0b10101010101); + ASSERT_EQ(bits.data()[0], 0b10101010101U); ASSERT_EQ(bits.to_string(), std::string("0000000000000000000000000000000000000000000000000000010101010101")); } TEST(BitTest, test_basic) { - BitSet<8> bits; + BitSet<8u> bits; static_assert(std::is_same_v); constexpr auto size = sizeof(bits); static_assert(size == sizeof(uint8_t)); @@ -42,13 +42,13 @@ TEST(BitTest, test_basic) ASSERT_EQ(bits[0], false); bits[0] = bits[6]; ASSERT_EQ(bits[0], true); - ASSERT_EQ(bits.data()[0u], 0b01000001); + ASSERT_EQ(bits.data()[0u], 0b01000001U); ASSERT_EQ(bits.to_string(), std::string("01000001")); } TEST(BitTest, test_flip) { - BitSet<8> bits; + BitSet<8u> bits; static_assert(std::is_same_v); constexpr auto size = sizeof(bits); static_assert(size == sizeof(uint8_t)); @@ -61,7 +61,7 @@ TEST(BitTest, test_flip) TEST(BitTest, test_trim8) { - BitSet<5> bits; + BitSet<5u> bits; static_assert(std::is_same_v); constexpr auto size = sizeof(bits); static_assert(size == sizeof(uint8_t)); @@ -70,12 +70,12 @@ TEST(BitTest, test_trim8) ASSERT_EQ(bits[5], false); ASSERT_EQ(bits[6], false); ASSERT_EQ(bits[7], false); - ASSERT_EQ(bits.data()[0u], 0b00011111); + ASSERT_EQ(bits.data()[0u], 0b00011111u); } TEST(BitTest, test_trim16) { - BitSet<14> bits; + BitSet<14u> bits; static_assert(std::is_same_v); constexpr auto size = sizeof(bits); static_assert(size == sizeof(uint16_t)); @@ -83,13 +83,13 @@ TEST(BitTest, test_trim16) bits.flip(); ASSERT_EQ(bits[14], false); ASSERT_EQ(bits[15], false); - ASSERT_EQ(bits.data()[0u], 0b0011111111111111); + ASSERT_EQ(bits.data()[0u], 0b0011111111111111u); ASSERT_EQ(bits.to_string(), std::string("11111111111111")); } TEST(BitTest, test_big) { - BitSet<256> bits; + BitSet<256u> bits; constexpr auto size = sizeof(bits); static_assert(size == 32u); @@ -115,28 +115,28 @@ TEST(BitTest, test_big) TEST(BitTest, test_xor5) { - BitSet<5> bits1({ 0u, 2u, 4u }); - BitSet<5> bits2({ 0u, 1u, 3u }); + BitSet<5u> bits1({ 0u, 2u, 4u }); + BitSet<5u> bits2({ 0u, 1u, 3u }); auto res = bits1 ^ bits2; - ASSERT_EQ(res.data()[0], 0b11110); + ASSERT_EQ(res.data()[0], 0b11110u); ASSERT_EQ(res.to_string(), "11110"); } TEST(BitTest, test_xor15) { - BitSet<15> bits1({ 0u, 2u, 4u }); - BitSet<15> bits2({ 0u, 1u, 3u, 14u }); + BitSet<15u> bits1({ 0u, 2u, 4u }); + BitSet<15u> bits2({ 0u, 1u, 3u, 14u }); auto res = bits1 ^ bits2; - ASSERT_EQ(res.data()[0], 0b0100000000011110); + ASSERT_EQ(res.data()[0], 0b0100000000011110u); ASSERT_EQ(res.to_string(), "100000000011110"); } TEST(BitTest, test_or5) { - BitSet<5> bits1({ 0u, 2u, 4u }); - BitSet<5> bits2({ 0u, 1u, 3u }); + BitSet<5u> bits1({ 0u, 2u, 4u }); + BitSet<5u> bits2({ 0u, 1u, 3u }); auto res = bits1 | bits2; ASSERT_EQ(res.data()[0], 0b11111); @@ -145,18 +145,18 @@ TEST(BitTest, test_or5) TEST(BitTest, test_or15) { - BitSet<15> bits1({ 0u, 2u, 4u }); - BitSet<15> bits2({ 0u, 1u, 3u, 14u }); + BitSet<15u> bits1({ 0u, 2u, 4u }); + BitSet<15u> bits2({ 0u, 1u, 3u, 14u }); auto res = bits1 | bits2; - ASSERT_EQ(res.data()[0], 0b0100000000011111); + ASSERT_EQ(res.data()[0], 0b0100000000011111u); ASSERT_EQ(res.to_string(), "100000000011111"); } TEST(BitTest, test_and5) { - BitSet<5> bits1({ 0u, 2u, 4u }); - BitSet<5> bits2({ 0u, 1u, 3u }); + BitSet<5u> bits1({ 0u, 2u, 4u }); + BitSet<5u> bits2({ 0u, 1u, 3u }); auto res = bits1 & bits2; ASSERT_EQ(res.data()[0], 0b1); @@ -165,8 +165,8 @@ TEST(BitTest, test_and5) TEST(BitTest, test_and15) { - BitSet<15> bits1({ 0u, 2u, 4u }); - BitSet<15> bits2({ 0u, 1u, 3u, 14u }); + BitSet<15u> bits1({ 0u, 2u, 4u }); + BitSet<15u> bits2({ 0u, 1u, 3u, 14u }); auto res = bits1 & bits2; ASSERT_EQ(res.data()[0], 0b1); @@ -175,31 +175,31 @@ TEST(BitTest, test_and15) TEST(BitTest, test_neg5) { - BitSet<5> bits1({ 0u, 2u, 4u }); + BitSet<5u> bits1({ 0u, 2u, 4u }); auto res = ~bits1; - ASSERT_EQ(res.data()[0], 0b01010); + ASSERT_EQ(res.data()[0], 0b01010u); ASSERT_EQ(res.to_string(), "01010"); } TEST(BitTest, test_neg15) { - BitSet<15> bits1({ 0u, 2u, 4u }); + BitSet<15u> bits1({ 0u, 2u, 4u }); auto res = ~bits1; - ASSERT_EQ(res.data()[0], 0b111111111101010); + ASSERT_EQ(res.data()[0], 0b111111111101010u); ASSERT_EQ(res.to_string(), "111111111101010"); } TEST(BitTest, test_count) { - BitSet<31> bits1({ 0u, 2u, 4u, 7u, 9u, 12u, 16u, 19u, 22u, 29u }); + BitSet<31u> bits1({ 0u, 2u, 4u, 7u, 9u, 12u, 16u, 19u, 22u, 29u }); ASSERT_EQ(bits1.count(), 10u); } TEST(BitTest, test_iterator) { - BitSet<31> bits1({ 0u, 2u, 4u, 7u, 9u, 12u, 16u, 19u, 22u, 29u }); + BitSet<31u> bits1({ 0u, 2u, 4u, 7u, 9u, 12u, 16u, 19u, 22u, 29u }); int totalBits = 0; for (auto v : bits1) @@ -212,7 +212,7 @@ TEST(BitTest, test_iterator) TEST(BitTest, test_iterator_const) { - BitSet<31> bits1({ 0u, 2u, 4u, 7u, 9u, 12u, 16u, 19u, 22u, 29u }); + BitSet<31u> bits1({ 0u, 2u, 4u, 7u, 9u, 12u, 16u, 19u, 22u, 29u }); int totalBits = 0; auto test = [&](const auto& b) {