Skip to content

Commit ee79165

Browse files
committed
🚨 Fix some clang-tidy issues
1 parent 18b00c5 commit ee79165

File tree

23 files changed

+135
-130
lines changed

23 files changed

+135
-130
lines changed

include/safe/algorithm/irange.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ template <typename BeginT, typename EndT> struct irange {
2121
constexpr iterator(irange const *parent, T value, bool end)
2222
: parent_{parent}, value_{value}, end_{end} {}
2323

24-
constexpr ret_t operator*() const { return unsafe_cast<ret_t>(value_); }
24+
constexpr auto operator*() const -> ret_t {
25+
return unsafe_cast<ret_t>(value_);
26+
}
2527

2628
constexpr auto operator++() {
2729
auto const new_unsafe_value = value_++;
@@ -37,14 +39,11 @@ template <typename BeginT, typename EndT> struct irange {
3739
return *this;
3840
}
3941

40-
constexpr bool operator==(iterator rhs) {
42+
constexpr auto operator==(iterator rhs) -> bool {
4143
if (end_) {
4244
return rhs.end_;
43-
44-
} else {
45-
return parent_ == rhs.parent_ && value_ == rhs.value_ &&
46-
!rhs.end_;
4745
}
46+
return parent_ == rhs.parent_ && value_ == rhs.value_ && !rhs.end_;
4847
}
4948
};
5049

@@ -62,4 +61,4 @@ template <typename BeginT, typename EndT> struct irange {
6261
this, end_.unsafe_value() - 1, true};
6362
}
6463
};
65-
} // namespace safe
64+
} // namespace safe

include/safe/array.hpp

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,96 +28,106 @@ template <typename T, std::size_t Size> struct array {
2828

2929
// TODO: constructors
3030
template <typename... Us>
31-
constexpr array(Us... values) : storage({values...}) {}
31+
constexpr explicit array(Us... values) : storage({values...}) {}
3232

33-
[[nodiscard]] constexpr reference
34-
operator[](var<size_type, ival<0, Size - 1>> pos) {
33+
[[nodiscard]] constexpr auto
34+
operator[](var<size_type, ival<0, Size - 1>> pos) -> reference {
3535
return storage[pos.unsafe_value()];
3636
}
3737

38-
[[nodiscard]] constexpr const_reference
39-
operator[](var<size_type, ival<0, Size - 1>> pos) const {
38+
[[nodiscard]] constexpr auto
39+
operator[](var<size_type, ival<0, Size - 1>> pos) const -> const_reference {
4040
return storage[pos.unsafe_value()];
4141
}
4242

43-
[[nodiscard]] constexpr reference
44-
at(var<size_type, ival<0, Size - 1>> pos) {
43+
[[nodiscard]] constexpr auto at(var<size_type, ival<0, Size - 1>> pos)
44+
-> reference {
4545
return storage[pos.unsafe_value()];
4646
}
4747

48-
[[nodiscard]] constexpr const_reference
49-
at(var<size_type, ival<0, Size - 1>> pos) const {
48+
[[nodiscard]] constexpr auto at(var<size_type, ival<0, Size - 1>> pos) const
49+
-> const_reference {
5050
return storage[pos.unsafe_value()];
5151
}
5252

53-
[[nodiscard]] constexpr reference front() { return storage.front(); }
53+
[[nodiscard]] constexpr auto front() -> reference {
54+
return storage.front();
55+
}
5456

55-
[[nodiscard]] constexpr const_reference front() const {
57+
[[nodiscard]] constexpr auto front() const -> const_reference {
5658
return storage.front();
5759
}
5860

59-
[[nodiscard]] constexpr reference back() { return storage.back(); }
61+
[[nodiscard]] constexpr auto back() -> reference { return storage.back(); }
6062

61-
[[nodiscard]] constexpr const_reference back() const {
63+
[[nodiscard]] constexpr auto back() const -> const_reference {
6264
return storage.back();
6365
}
6466

6567
// NOTE: intentionally omitting data()
6668

67-
[[nodiscard]] constexpr iterator begin() { return storage.begin(); }
69+
[[nodiscard]] constexpr auto begin() -> iterator { return storage.begin(); }
6870

69-
[[nodiscard]] constexpr const_iterator begin() const {
71+
[[nodiscard]] constexpr auto begin() const -> const_iterator {
7072
return storage.begin();
7173
}
7274

73-
[[nodiscard]] constexpr const_iterator cbegin() const {
75+
[[nodiscard]] constexpr auto cbegin() const -> const_iterator {
7476
return storage.cbegin();
7577
}
7678

77-
[[nodiscard]] constexpr iterator end() { return storage.end(); }
79+
[[nodiscard]] constexpr auto end() -> iterator { return storage.end(); }
7880

79-
[[nodiscard]] constexpr const_iterator end() const { return storage.end(); }
81+
[[nodiscard]] constexpr auto end() const -> const_iterator {
82+
return storage.end();
83+
}
8084

81-
[[nodiscard]] constexpr const_iterator cend() const {
85+
[[nodiscard]] constexpr auto cend() const -> const_iterator {
8286
return storage.cend();
8387
}
8488

85-
[[nodiscard]] constexpr reverse_iterator rbegin() {
89+
[[nodiscard]] constexpr auto rbegin() -> reverse_iterator {
8690
return storage.rbegin();
8791
}
8892

89-
[[nodiscard]] constexpr const_reverse_iterator rbegin() const {
93+
[[nodiscard]] constexpr auto rbegin() const -> const_reverse_iterator {
9094
return storage.rbegin();
9195
}
9296

93-
[[nodiscard]] constexpr const_reverse_iterator crbegin() const {
97+
[[nodiscard]] constexpr auto crbegin() const -> const_reverse_iterator {
9498
return storage.crbegin();
9599
}
96100

97-
[[nodiscard]] constexpr reverse_iterator rend() { return storage.rend(); }
101+
[[nodiscard]] constexpr auto rend() -> reverse_iterator {
102+
return storage.rend();
103+
}
98104

99-
[[nodiscard]] constexpr const_reverse_iterator rend() const {
105+
[[nodiscard]] constexpr auto rend() const -> const_reverse_iterator {
100106
return storage.rend();
101107
}
102108

103-
[[nodiscard]] constexpr const_reverse_iterator crend() const {
109+
[[nodiscard]] constexpr auto crend() const -> const_reverse_iterator {
104110
return storage.crend();
105111
}
106112

107-
[[nodiscard]] constexpr bool empty() const { return storage.empty(); }
113+
[[nodiscard]] constexpr auto empty() const -> bool {
114+
return storage.empty();
115+
}
108116

109-
[[nodiscard]] constexpr size_type size() const { return storage.size(); }
117+
[[nodiscard]] constexpr auto size() const -> size_type {
118+
return storage.size();
119+
}
110120

111-
[[nodiscard]] constexpr size_type max_size() const {
121+
[[nodiscard]] constexpr auto max_size() const -> size_type {
112122
return storage.max_size();
113123
}
114124

115125
constexpr void fill(T const &value) { storage.fill(value); }
116126

117127
constexpr void swap(array &other) { storage.swap(other.storage); }
118128

119-
[[nodiscard]] friend constexpr bool operator==(array const &lhs,
120-
array const &rhs) {
129+
[[nodiscard]] friend constexpr auto operator==(array const &lhs,
130+
array const &rhs) -> bool {
121131
return lhs.storage == rhs.storage;
122132
}
123133

@@ -132,22 +142,24 @@ template <class T, class... U> array(T, U...) -> array<T, 1 + sizeof...(U)>;
132142

133143
namespace std {
134144
template <std::size_t I, class T, std::size_t N>
135-
[[nodiscard]] constexpr T &get(safe::array<T, N> &a) noexcept {
145+
[[nodiscard]] constexpr auto get(safe::array<T, N> &a) noexcept -> T & {
136146
return a[safe::constant<std::size_t, I>];
137147
}
138148

139149
template <std::size_t I, class T, std::size_t N>
140-
[[nodiscard]] constexpr T &&get(safe::array<T, N> &&a) noexcept {
141-
return a[safe::constant<std::size_t, I>];
150+
[[nodiscard]] constexpr auto get(safe::array<T, N> &&a) noexcept -> T && {
151+
return std::move(a)[safe::constant<std::size_t, I>];
142152
}
143153

144154
template <std::size_t I, class T, std::size_t N>
145-
[[nodiscard]] constexpr T const &get(safe::array<T, N> const &a) noexcept {
155+
[[nodiscard]] constexpr auto get(safe::array<T, N> const &a) noexcept
156+
-> T const & {
146157
return a[safe::constant<std::size_t, I>];
147158
}
148159

149160
template <std::size_t I, class T, std::size_t N>
150-
[[nodiscard]] constexpr T const &&get(safe::array<T, N> const &&a) noexcept {
161+
[[nodiscard]] constexpr auto get(safe::array<T, N> const &&a) noexcept
162+
-> T const && {
151163
return a[safe::constant<std::size_t, I>];
152164
}
153165

@@ -164,4 +176,4 @@ template <std::size_t I, class T, std::size_t N>
164176
struct tuple_element<I, safe::array<T, N>> {
165177
using type = T;
166178
};
167-
} // namespace std
179+
} // namespace std

include/safe/big_integer/detail/compare.hpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ template <std::size_t LhsNumBits, std::size_t RhsNumBits>
1717

1818
if (lhs.get(i) < rhs.get(i)) {
1919
return std::strong_ordering::less;
20-
21-
} else if (lhs.get(i) > rhs.get(i)) {
20+
}
21+
if (lhs.get(i) > rhs.get(i)) {
2222
return std::strong_ordering::greater;
2323
}
2424
} while (i > 0);
@@ -33,15 +33,12 @@ template <std::size_t LhsNumBits, std::size_t RhsNumBits>
3333
if (lhs.negative()) {
3434
if (rhs.negative()) {
3535
return unsigned_compare(lhs, rhs);
36-
} else {
37-
return std::strong_ordering::less;
38-
}
39-
} else {
40-
if (rhs.negative()) {
41-
return std::strong_ordering::greater;
42-
} else {
43-
return unsigned_compare(lhs, rhs);
4436
}
37+
return std::strong_ordering::less;
38+
}
39+
if (rhs.negative()) {
40+
return std::strong_ordering::greater;
4541
}
42+
return unsigned_compare(lhs, rhs);
4643
}
47-
} // namespace safe::_big_integer::detail
44+
} // namespace safe::_big_integer::detail

include/safe/big_integer/detail/multiplies.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ constexpr static auto unsigned_multiplies = [](auto &result, auto const &lhs,
2121

2222
result_t partial_product{
2323
{static_cast<elem_t>(raw_partial_product & 0xffff'ffffu),
24-
static_cast<elem_t>(raw_partial_product >> 32)}};
24+
static_cast<elem_t>(raw_partial_product >> 32u)}};
2525

2626
bit_shift_left(partial_product, partial_product, (i + j) * 32);
2727

@@ -59,4 +59,4 @@ constexpr static auto multiplies = [](auto &result, auto const &lhs,
5959
}
6060
}
6161
};
62-
} // namespace safe::_big_integer::detail
62+
} // namespace safe::_big_integer::detail

include/safe/big_integer/detail/plus.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ constexpr static auto plus =
1313
double_elem_t const result =
1414
lhs + rhs + static_cast<double_elem_t>(carry);
1515

16-
carry = result >> 32;
16+
carry = result >> 32u;
1717
return result & 0xffff'ffffu;
1818
});
1919

@@ -29,4 +29,4 @@ constexpr static auto minus = [](auto &result, auto const &lhs,
2929
negate(negative_rhs, rhs);
3030
plus(result, lhs, negative_rhs);
3131
};
32-
} // namespace safe::_big_integer::detail
32+
} // namespace safe::_big_integer::detail

include/safe/big_integer/detail/shift.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ constexpr static auto bit_shift_left =
3333
reverse_zip_transform([=](elem_t const upper, elem_t const lower) {
3434
if (bit_shift_amt == 0) {
3535
return upper;
36-
} else {
37-
return (upper << bit_shift_amt) | (lower >> (32 - bit_shift_amt));
3836
}
37+
return (upper << bit_shift_amt) | (lower >> (32 - bit_shift_amt));
3938
})(result, lhs_shifted_upper, lhs_shifted_lower);
4039
};
4140

@@ -63,9 +62,8 @@ constexpr static auto bit_shift_right =
6362
zip_transform([=](elem_t const upper, elem_t const lower) {
6463
if (bit_shift_amt == 0) {
6564
return lower;
66-
} else {
67-
return (upper << (32 - bit_shift_amt)) | (lower >> bit_shift_amt);
6865
}
66+
return (upper << (32 - bit_shift_amt)) | (lower >> bit_shift_amt);
6967
})(result, lhs_shifted_upper, lhs_shifted_lower);
7068
};
71-
} // namespace safe::_big_integer::detail
69+
} // namespace safe::_big_integer::detail

include/safe/big_integer/detail/storage.hpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ template <std::size_t NumBits> struct storage {
1919
std::array<elem_t, num_elems> elems{};
2020

2121
constexpr storage() = default;
22-
23-
constexpr storage(std::array<elem_t, num_elems> const &new_elems) {
24-
elems = new_elems;
25-
}
22+
constexpr storage(std::array<elem_t, num_elems> const &new_elems)
23+
: elems{new_elems} {}
2624

2725
template <std::size_t RhsNumBits>
2826
constexpr storage(storage<RhsNumBits> const &rhs) {
@@ -51,22 +49,21 @@ template <std::size_t NumBits> struct storage {
5149
return true;
5250
}
5351

54-
[[nodiscard]] constexpr bool negative() const {
52+
[[nodiscard]] constexpr auto negative() const -> bool {
5553
return (elems.back() >> 31) & 1;
5654
}
5755

5856
[[nodiscard]] constexpr auto get(int32_t i) const -> elem_t {
5957
if (i < 0) {
6058
return 0u;
61-
} else if (i < num_elems) {
59+
}
60+
if (i < num_elems) {
6261
return elems[i];
63-
} else {
64-
if (negative()) {
65-
return 0xffff'ffffu;
66-
} else {
67-
return 0u;
68-
}
6962
}
63+
if (negative()) {
64+
return 0xffff'ffffu;
65+
}
66+
return 0u;
7067
}
7168

7269
constexpr auto set(int32_t i, elem_t elem) -> void {
@@ -101,18 +98,19 @@ template <typename T>
10198
}
10299

103100
template <std::size_t NumBits>
104-
[[nodiscard]] constexpr auto const &
105-
to_storage(interface::big_integer<NumBits> const &v) {
101+
[[nodiscard]] constexpr auto
102+
to_storage(interface::big_integer<NumBits> const &v) -> auto const & {
106103
return v.unsafe_storage;
107104
}
108105

109106
template <std::size_t NumBits>
110-
[[nodiscard]] constexpr auto &to_storage(storage<NumBits> &v) {
107+
[[nodiscard]] constexpr auto to_storage(storage<NumBits> &v) -> auto & {
111108
return v;
112109
}
113110

114111
template <std::size_t NumBits>
115-
[[nodiscard]] constexpr auto const &to_storage(storage<NumBits> const &v) {
112+
[[nodiscard]] constexpr auto to_storage(storage<NumBits> const &v)
113+
-> auto const & {
116114
return v;
117115
}
118116

@@ -167,4 +165,4 @@ constexpr static auto sum_width = [](std::size_t left_bits,
167165
std::size_t right_bits) -> std::size_t {
168166
return left_bits + right_bits;
169167
};
170-
} // namespace safe::_big_integer::detail
168+
} // namespace safe::_big_integer::detail

include/safe/big_integer/interface/big_integer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
namespace safe::_big_integer::interface {
1212
template <std::size_t NumBits> struct big_integer {
13-
detail::storage<NumBits> unsafe_storage;
13+
detail::storage<NumBits> unsafe_storage{};
1414

1515
constexpr big_integer(auto value)
1616
: unsafe_storage{detail::to_storage(value)} {}
17-
constexpr big_integer() : unsafe_storage{} {}
17+
constexpr big_integer() = default;
1818

1919
constexpr auto operator&=(auto const &rhs) -> big_integer & {
2020
return do_assign_op(detail::bit_and, rhs);
@@ -386,4 +386,4 @@ struct std::numeric_limits<
386386
constexpr static auto signaling_NaN() noexcept -> T { return T{0}; }
387387

388388
constexpr static auto denorm_min() noexcept -> T { return T{0}; }
389-
};
389+
};

0 commit comments

Comments
 (0)