abacus: bignum: use span
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Once again, the code looks cleaner that way.
This commit is contained in:
parent
4ea7a38b61
commit
8cb26ee316
|
@ -3,6 +3,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
@ -82,18 +83,17 @@ digits_type do_addition(digits_type const& lhs, digits_type const& rhs) {
|
||||||
++it2;
|
++it2;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto [it, end] = [=]() {
|
auto leftover = [=]() {
|
||||||
if (it1 != end1) {
|
if (it1 != end1) {
|
||||||
return std::make_pair(it1, end1);
|
return std::span(it1, end1);
|
||||||
}
|
}
|
||||||
return std::make_pair(it2, end2);
|
return std::span(it2, end2);
|
||||||
}();
|
}();
|
||||||
|
|
||||||
while (it != end) {
|
for (auto value : leftover) {
|
||||||
int addition = *it + carry;
|
int addition = value + carry;
|
||||||
carry = addition / BASE;
|
carry = addition / BASE;
|
||||||
res.push_back(addition % BASE);
|
res.push_back(addition % BASE);
|
||||||
++it;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (carry != 0) {
|
if (carry != 0) {
|
||||||
|
|
Loading…
Reference in a new issue