refactor: consistent std::size_t usage

This commit is contained in:
Mateusz Pusz
2024-07-16 12:12:54 +02:00
parent c57142c18a
commit d51fb6d6c1
3 changed files with 13 additions and 13 deletions

View File

@@ -93,7 +93,7 @@ struct fmt_arg_ref {
template<typename Char>
struct fill_t {
private:
static constexpr size_t max_size = 4 / sizeof(Char);
static constexpr std::size_t max_size = 4 / sizeof(Char);
// At most one codepoint (so one char32_t or four utf-8 char8_t)
std::array<Char, max_size> data_ = {Char{' '}};
unsigned char size_ = 1;
@@ -103,16 +103,16 @@ public:
{
auto size = str.size();
if (size > max_size) MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid fill"));
for (size_t i = 0; i < size && i < max_size; ++i) data_[i] = str[i];
for (std::size_t i = 0; i < size && i < max_size; ++i) data_[i] = str[i];
size_ = static_cast<unsigned char>(size);
return *this;
}
[[nodiscard]] constexpr size_t size() const { return size_; }
[[nodiscard]] constexpr std::size_t size() const { return size_; }
[[nodiscard]] constexpr const Char* data() const { return data_.data(); }
[[nodiscard]] constexpr Char& operator[](size_t index) { return data_[index]; }
[[nodiscard]] constexpr const Char& operator[](size_t index) const { return data_[index]; }
[[nodiscard]] constexpr Char& operator[](std::size_t index) { return data_[index]; }
[[nodiscard]] constexpr const Char& operator[](std::size_t index) const { return data_[index]; }
};
MP_UNITS_EXPORT_END

View File

@@ -214,33 +214,33 @@ public:
MP_UNITS_EXPECTS(lhs[N1 - 1] == CharT{});
CharT txt[N1 + N];
CharT* it = txt;
for (size_t i = 0; i != N1 - 1; ++i) *it++ = lhs[i];
for (std::size_t i = 0; i != N1 - 1; ++i) *it++ = lhs[i];
for (CharT c : rhs) *it++ = c;
*it++ = CharT();
return txt;
}
// non-member comparison functions
template<size_t N2>
template<std::size_t N2>
[[nodiscard]] friend constexpr bool operator==(const basic_fixed_string& lhs,
const basic_fixed_string<CharT, N2, Traits>& rhs)
{
return lhs.view() == rhs.view();
}
template<size_t N2>
template<std::size_t N2>
[[nodiscard]] friend consteval bool operator==(const basic_fixed_string& lhs, const CharT (&rhs)[N2])
{
MP_UNITS_EXPECTS(rhs[N2 - 1] == CharT{});
return lhs.view() == std::basic_string_view<CharT, Traits>(std::cbegin(rhs), std::cend(rhs) - 1);
}
template<size_t N2>
template<std::size_t N2>
[[nodiscard]] friend constexpr auto operator<=>(const basic_fixed_string& lhs,
const basic_fixed_string<CharT, N2, Traits>& rhs)
{
return lhs.view() <=> rhs.view();
}
template<size_t N2>
template<std::size_t N2>
[[nodiscard]] friend consteval auto operator<=>(const basic_fixed_string& lhs, const CharT (&rhs)[N2])
{
MP_UNITS_EXPECTS(rhs[N2 - 1] == CharT{});
@@ -268,7 +268,7 @@ template<one_of<char, char8_t, char16_t, char32_t, wchar_t> CharT, std::size_t N
basic_fixed_string(std::from_range_t, std::array<CharT, N>) -> basic_fixed_string<CharT, N>;
// specialized algorithms
template<class CharT, size_t N, class Traits>
template<class CharT, std::size_t N, class Traits>
constexpr void swap(basic_fixed_string<CharT, N, Traits>& x, basic_fixed_string<CharT, N, Traits>& y) noexcept
{
x.swap(y);

View File

@@ -38,7 +38,7 @@ template<Quantity Q, typename InputIt>
std::vector<typename Q::rep> i_qty_to_rep(InputIt first, InputIt last)
{
std::vector<typename Q::rep> intervals_rep;
intervals_rep.reserve(static_cast<size_t>(std::distance(first, last)));
intervals_rep.reserve(static_cast<std::size_t>(std::distance(first, last)));
for (InputIt itr = first; itr != last; ++itr) {
intervals_rep.push_back(itr->numerical_value_ref_in(Q::unit));
}
@@ -67,7 +67,7 @@ std::vector<typename Q::rep> fw_bl_pwc(std::initializer_list<Q>& bl, UnaryOperat
}
std::vector<rep> weights;
weights.reserve(bl.size());
for (size_t i = 0; i < bl.size() - 1; ++i) {
for (std::size_t i = 0; i < bl.size() - 1; ++i) {
weights.push_back(w_bl[i] + w_bl[i + 1]);
}
weights.push_back(0);