Skip to content
Open
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
68 changes: 34 additions & 34 deletions include/gul14/SlidingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ class SlidingBuffer {
*/
auto back() const noexcept -> const_reference
{
if (idx_end_ == 0)
return storage_[capacity() - 1];
if (idx_end_ == 0u)
return storage_[capacity() - 1u];
else
return storage_[idx_end_ - 1];
return storage_[idx_end_ - 1u];
}

/**
Expand Down Expand Up @@ -667,7 +667,7 @@ class SlidingBuffer {
* \param buff Reference to the SlidingBuffer the iterator points into.
* \param num Index of the element the iterator points to.
*/
explicit SlidingBufferIterator(BufferPointer buff, size_type num = 0) noexcept
explicit SlidingBufferIterator(BufferPointer buff, size_type num = 0u) noexcept
: position_{ num }
, buffer_{ buff }
{
Expand All @@ -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);
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_);
}

/// Access element pointed to by the iterator
Expand Down Expand Up @@ -981,10 +981,10 @@ class SlidingBuffer {

//////
// Vanishing
if (new_capacity == 0) {
storage_.resize(0);
idx_begin_ = 0;
idx_end_ = 0;
if (new_capacity == 0u) {
storage_.resize(0u);
idx_begin_ = 0u;
idx_end_ = 0u;
full_ = false;
return;
}
Expand All @@ -994,9 +994,9 @@ 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_begin_ = 0u;
idx_end_ = old_size;
full_ = false;
return;
Expand All @@ -1006,9 +1006,9 @@ 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_begin_ = 0u;
idx_end_ = old_size;
full_ = false;
}
Expand All @@ -1017,11 +1017,11 @@ 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;
idx_end_ = 0;
idx_begin_ = 0u;
idx_end_ = 0u;
}
}
};
Expand Down Expand Up @@ -1120,8 +1120,8 @@ 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_;
if (not full_ and (idx_end_ == 0u or idx_end_ >= idx_begin_))
return storage_.begin() + static_cast<difference_type>(idx_begin_);

return storage_.begin();
}
Expand All @@ -1140,8 +1140,8 @@ class SlidingBufferExposed : public SlidingBuffer<ElementT, fixed_capacity, Cont
*/
auto cbegin() const noexcept -> const_iterator
{
if (not full_ and (idx_end_ == 0 or idx_end_ >= idx_begin_))
return storage_.cbegin() + idx_begin_;
if (not full_ and (idx_end_ == 0u or idx_end_ >= idx_begin_))
return storage_.cbegin() + static_cast<difference_type>(idx_begin_);

return storage_.cbegin();
}
Expand All @@ -1165,10 +1165,10 @@ class SlidingBufferExposed : public SlidingBuffer<ElementT, fixed_capacity, Cont
*/
auto end() noexcept -> iterator
{
if (full_ or idx_begin_ != 0)
if (full_ or idx_begin_ != 0u)
return storage_.end();

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

/// \overload
Expand All @@ -1185,10 +1185,10 @@ class SlidingBufferExposed : public SlidingBuffer<ElementT, fixed_capacity, Cont
*/
auto cend() const noexcept -> const_iterator
{
if (full_ or idx_begin_ != 0)
if (full_ or idx_begin_ != 0u)
return storage_.cend();

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

/**
Expand Down Expand Up @@ -1278,8 +1278,8 @@ class SlidingBufferExposed : public SlidingBuffer<ElementT, fixed_capacity, Cont
and (new_capacity > 0)
and (new_capacity != old_capacity)
and (not full_)
and (idx_end_ == 0)
and (idx_begin_ != 0);
and (idx_end_ == 0u)
and (idx_begin_ != 0u);

if (not right_align)
return this->change_capacity(new_capacity, shrink_behavior);
Expand All @@ -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
8 changes: 4 additions & 4 deletions include/gul14/date.h
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,8 @@ operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday_last&
inline namespace literals
{

constexpr gul14::date::day operator "" _d(unsigned long long d) noexcept;
constexpr gul14::date::year operator "" _y(unsigned long long y) noexcept;
constexpr gul14::date::day operator ""_d(unsigned long long d) noexcept;
constexpr gul14::date::year operator ""_y(unsigned long long y) noexcept;

} // inline namespace literals
#endif // !defined(_MSC_VER) || (_MSC_VER >= 1900)
Expand Down Expand Up @@ -1810,14 +1810,14 @@ inline namespace literals

constexpr inline
gul14::date::day
operator "" _d(unsigned long long d) noexcept
operator ""_d(unsigned long long d) noexcept
{
return gul14::date::day{static_cast<unsigned>(d)};
}

constexpr inline
gul14::date::year
operator "" _y(unsigned long long y) noexcept
operator ""_y(unsigned long long y) noexcept
{
return gul14::date::year(static_cast<int>(y));
}
Expand Down
2 changes: 1 addition & 1 deletion include/gul14/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ inline constexpr typename std::remove_reference<T>::type&& constexpr_move(T&& t)
#if defined NDEBUG
#define GUL_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR)
#else
#define GUL_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([]{assert(!#CHECK);}(), (EXPR)))
#define GUL_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([]{assert((void(#CHECK), false));}(), (EXPR)))
#endif


Expand Down
2 changes: 1 addition & 1 deletion include/gul14/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class span {

/// See [std::span](https://en.cppreference.com/w/cpp/container/span).
constexpr span(pointer first_elem, pointer last_elem)
: storage_(first_elem, last_elem - first_elem)
: storage_(first_elem, static_cast<std::size_t>(last_elem - first_elem))
{}

/// See [std::span](https://en.cppreference.com/w/cpp/container/span).
Expand Down
2 changes: 1 addition & 1 deletion include/gul14/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ template <typename Iterator>
inline std::string
hex_string(Iterator begin, Iterator end, string_view separator = "")
{
const std::size_t n = std::distance(begin, end);
const std::size_t n = static_cast<std::size_t>(std::distance(begin, end));

std::string result;

Expand Down
11 changes: 6 additions & 5 deletions include/gul14/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <string>
#include <cstring>
#include <iosfwd>
#include <ios>

#include "gul14/internal.h"

Expand Down Expand Up @@ -571,9 +572,9 @@ inline void sv_insert_fill_chars(std::basic_ostream<charT, traits>& os, std::siz
charT fill_chars[chunk_size];
std::fill_n(fill_chars, static_cast< std::size_t >(chunk_size), os.fill());
for (; n >= chunk_size && os.good(); n -= chunk_size)
os.write(fill_chars, static_cast< std::size_t >(chunk_size));
os.write(fill_chars, static_cast< std::streamsize >(chunk_size));
if (n > 0 && os.good())
os.write(fill_chars, n);
os.write(fill_chars, static_cast< std::streamsize >(n));
}

template<class charT, class traits>
Expand All @@ -585,10 +586,10 @@ void sv_insert_aligned(std::basic_ostream<charT, typename char_traits<charT>::ba
if (!align_left) {
detail::sv_insert_fill_chars(os, alignment_size);
if (os.good())
os.write(str.data(), size);
os.write(str.data(), static_cast< std::streamsize >(size));
}
else {
os.write(str.data(), size);
os.write(str.data(), static_cast< std::streamsize >(size));
if (os.good())
detail::sv_insert_fill_chars(os, alignment_size);
}
Expand All @@ -605,7 +606,7 @@ operator<<(std::basic_ostream<charT, typename char_traits<charT>::base_traits>&
const std::size_t size = str.size();
const std::size_t w = static_cast< std::size_t >(os.width());
if (w <= size)
os.write(str.data(), size);
os.write(str.data(), static_cast< std::streamsize >(size));
else
detail::sv_insert_aligned(os, str);
os.width(0);
Expand Down
Loading
Loading