Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions include/gul17/SlidingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ class SlidingBuffer {
/// Increase iterator by a given number of positions.
auto operator+=(difference_type d) noexcept -> SlidingBufferIterator&
{
position_ += d;
position_ += static_cast<size_type>(d);
Comment thread
alt-graph marked this conversation as resolved.
return *this;
}

Expand All @@ -700,15 +700,15 @@ class SlidingBuffer {
operator+(const SlidingBufferIterator &it, difference_type d) noexcept
-> SlidingBufferIterator
{
return SlidingBufferIterator{ it.buffer_, it.position_ + d };
return SlidingBufferIterator{ it.buffer_, it.position_ + static_cast<size_type>(d) };
}

/// Add an integer and an iterator.
friend auto
operator+(difference_type d, const SlidingBufferIterator &it) noexcept
-> SlidingBufferIterator
{
return SlidingBufferIterator{ it.buffer_, it.position_ + d };
return SlidingBufferIterator{ it.buffer_, it.position_ + static_cast<size_type>(d) };
}

/// Pre-decrement iterator by one position
Expand All @@ -729,7 +729,7 @@ class SlidingBuffer {
/// Decrease iterator by a given number of positions.
auto operator-=(difference_type d) noexcept -> SlidingBufferIterator&
{
position_ -= d;
position_ -= static_cast<size_type>(d);
return *this;
}

Expand All @@ -738,15 +738,15 @@ class SlidingBuffer {
operator-(const SlidingBufferIterator &it, difference_type d) noexcept
-> SlidingBufferIterator
{
return SlidingBufferIterator{ it.buffer_, it.position_ - d };
return SlidingBufferIterator{ it.buffer_, it.position_ - static_cast<size_type>(d) };
}

/// Subtract two iterators.
friend auto
operator-(const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept
-> difference_type
{
return lhs.position_ - rhs.position_;
return static_cast<difference_type>(lhs.position_ - rhs.position_);
Comment thread
alt-graph marked this conversation as resolved.
}

/// Access element pointed to by the iterator
Expand Down Expand Up @@ -994,7 +994,7 @@ class SlidingBuffer {
// Growing
if (new_capacity > old_capacity) {
// Make SlidingBuffer indices equal to those of the underlying container
std::rotate(storage_.begin(), storage_.begin() + idx_begin_, storage_.end());
std::rotate(storage_.begin(), storage_.begin() + static_cast<difference_type>(idx_begin_), storage_.end());
storage_.resize(new_capacity);
idx_begin_ = 0;
idx_end_ = old_size;
Expand All @@ -1006,7 +1006,7 @@ class SlidingBuffer {
// Shrinking
if (old_size < new_capacity) {
// All data fits into new capacity, just move it there
std::rotate(storage_.begin(), storage_.begin() + idx_begin_, storage_.end());
std::rotate(storage_.begin(), storage_.begin() + static_cast<difference_type>(idx_begin_), storage_.end());
storage_.resize(new_capacity);
idx_begin_ = 0;
idx_end_ = old_size;
Expand All @@ -1017,7 +1017,7 @@ class SlidingBuffer {
if (shrink_behavior == ShrinkBehavior::keep_back_elements)
new_front = (idx_end_ + old_capacity - new_capacity) % old_capacity;

std::rotate(storage_.begin(), storage_.begin() + new_front, storage_.end());
std::rotate(storage_.begin(), storage_.begin() + static_cast<difference_type>(new_front), storage_.end());
storage_.resize(new_capacity);
full_ = true;
idx_begin_ = 0;
Expand Down Expand Up @@ -1121,7 +1121,7 @@ class SlidingBufferExposed : public SlidingBuffer<ElementT, fixed_capacity, Cont
auto begin() noexcept -> iterator
{
if (not full_ and (idx_end_ == 0 or idx_end_ >= idx_begin_))
return storage_.begin() + idx_begin_;
return storage_.begin() + static_cast<difference_type>(idx_begin_);

return storage_.begin();
}
Expand Down Expand Up @@ -1168,7 +1168,7 @@ class SlidingBufferExposed : public SlidingBuffer<ElementT, fixed_capacity, Cont
if (full_ or idx_begin_ != 0)
return storage_.end();

return storage_.begin() + idx_end_;
return storage_.begin() + static_cast<difference_type>(idx_end_);
}

/// \overload
Expand Down Expand Up @@ -1288,8 +1288,8 @@ class SlidingBufferExposed : public SlidingBuffer<ElementT, fixed_capacity, Cont
// Growing
if (new_capacity > old_capacity) {
storage_.resize(new_capacity);
std::move_backward(storage_.begin() + idx_begin_,
storage_.begin() + old_capacity, storage_.end());
std::move_backward(storage_.begin() + static_cast<difference_type>(idx_begin_),
storage_.begin() + static_cast<difference_type>(old_capacity), storage_.end());
idx_begin_ += new_capacity - old_capacity;
return;
}
Expand All @@ -1298,7 +1298,7 @@ class SlidingBufferExposed : public SlidingBuffer<ElementT, fixed_capacity, Cont
// Shrinking
full_ = (this->size() >= new_capacity);
auto const required_shift = std::min(old_capacity - new_capacity, idx_begin_);
std::rotate(storage_.begin(), storage_.begin() + required_shift, storage_.end());
std::rotate(storage_.begin(), storage_.begin() + static_cast<difference_type>(required_shift), storage_.end());
idx_begin_ -= required_shift;
storage_.resize(new_capacity);
}
Expand Down
4 changes: 2 additions & 2 deletions include/gul17/join_split.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ split(std::string_view text, const std::regex& delimiter,
if (parts == previous and not parts->length())
break;
auto const& match = parts->prefix();
insert_fct(result, std::string_view(match.first, match.length()));
insert_fct(result, std::string_view(match.first, static_cast<std::size_t>(match.length())));
previous = parts;
}

auto const& match = previous->suffix();
insert_fct(result, std::string_view(match.first, match.length()));
insert_fct(result, std::string_view(match.first, static_cast<std::size_t>(match.length())));
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion include/gul17/statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ namespace {

auto size() const noexcept -> std::size_t
{
return std::distance(begin_, end_);
return static_cast<std::size_t>(std::distance(begin_, end_));
}
};

Expand Down
24 changes: 12 additions & 12 deletions tests/test_SlidingBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ TEST_CASE("SlidingBuffer test", "[SlidingBuffer]")
auto end = buff1.end();
auto i = 0;
for (; it != end; ++it, ++i) {
auto ref = buff1.at(i).val;
REQUIRE(buff1[i].val == ref);
auto ref = buff1.at(static_cast<std::size_t>(i)).val;
REQUIRE(buff1[static_cast<std::size_t>(i)].val == ref);
REQUIRE((*it).val == ref);
REQUIRE(it->val == ref);
}
Expand All @@ -249,14 +249,14 @@ TEST_CASE("SlidingBuffer test", "[SlidingBuffer]")
end2 = buff1.rend();
i = 0;
for (; it2 != end2; ++it2, ++i) {
auto ref = buff1.at(9-i).val;
auto ref = buff1.at(static_cast<std::size_t>(9 - i)).val;
REQUIRE((*it2).val == ref);
}
REQUIRE(i == 10);

auto j = 0;
for (auto const& e : buff1) {
REQUIRE(e.val == buff1[j++].val);
REQUIRE(e.val == buff1[static_cast<std::size_t>(j++)].val);
}

auto x = buff1.begin();
Expand Down Expand Up @@ -913,8 +913,8 @@ TEST_CASE("SlidingBufferExposed test", "[SlidingBuffer]")
REQUIRE(i == 10);
auto index_data = std::vector<double>{ };
while (i--) {
auto ref = buff1.at(i).val;
REQUIRE(buff1[i].val == ref);
auto ref = buff1.at(static_cast<std::size_t>(i)).val;
REQUIRE(buff1[static_cast<std::size_t>(i)].val == ref);
index_data.push_back(ref);
}
std::sort(index_data.begin(), index_data.end());
Expand Down Expand Up @@ -1343,7 +1343,7 @@ TEST_CASE("SlidingBufferExposed: Shrinking behavior", "[SlidingBuffer]")
TEST_CASE("SlidingBufferIterator: LegacyIterator requirements", "[SlidingBufferIterator]")
{
SlidingBuffer<int, 10> buf;
for (auto i = 0u; i < buf.capacity(); i++)
for (int i = 0; i < static_cast<int>(buf.capacity()); i++)
buf.push_back(i);

SECTION("prefix operator++ and dereferencing")
Expand All @@ -1361,7 +1361,7 @@ TEST_CASE("SlidingBufferIterator: LegacyForwardIterator requirements",
"[SlidingBufferIterator]")
{
SlidingBuffer<int, 10> buf;
for (auto i = 0u; i < buf.capacity(); i++)
for (int i = 0; i < static_cast<int>(buf.capacity()); i++)
buf.push_back(i);

SECTION("postfix operator++")
Expand Down Expand Up @@ -1391,7 +1391,7 @@ TEST_CASE("SlidingBufferIterator: LegacyBidirectionalIterator requirements",
"[SlidingBufferIterator]")
{
SlidingBuffer<int, 10> buf;
for (auto i = 0u; i < buf.capacity(); i++)
for (int i = 0; i < static_cast<int>(buf.capacity()); i++)
buf.push_back(i);

SECTION("prefix operator--")
Expand All @@ -1418,7 +1418,7 @@ TEST_CASE("SlidingBufferIterator: LegacyRandomAccessIterator requirements",
"[SlidingBufferIterator]")
{
SlidingBuffer<int, 10> buf;
for (auto i = 0u; i < buf.capacity(); i++)
for (int i = 0; i < static_cast<int>(buf.capacity()); i++)
buf.push_back(i);

SECTION("operator+=")
Expand Down Expand Up @@ -1502,7 +1502,7 @@ TEST_CASE("SlidingBufferIterator: LegacyRandomAccessIterator requirements",

++it;
for (int i = -1; i < static_cast<int>(buf.size()) - 1; ++i)
REQUIRE(it[i] == buf[i + 1]);
REQUIRE(it[i] == buf[static_cast<decltype(buf)::size_type>(i + 1)]);
}

SECTION("Comparison operators")
Expand All @@ -1525,7 +1525,7 @@ TEST_CASE("SlidingBufferIterator: LegacyRandomAccessIterator requirements",
TEST_CASE("SlidingBufferIterator: std::distance()", "[SlidingBufferIterator]")
{
SlidingBuffer<int, 10> buf;
for (auto i = 0u; i < buf.capacity(); i++)
for (int i = 0; i < static_cast<int>(buf.capacity()); i++)
buf.push_back(i);

REQUIRE(std::distance(buf.begin(), buf.begin()) == 0);
Expand Down
Loading
Loading