Compare commits

...

3 commits

Author SHA1 Message Date
Bruno BELANYI 8cb26ee316 abacus: bignum: use span
All checks were successful
continuous-integration/drone/push Build is passing
Once again, the code looks cleaner that way.
2021-10-12 15:05:43 +02:00
Bruno BELANYI 4ea7a38b61 abacus: use C++20 2021-10-12 15:05:43 +02:00
Bruno BELANYI da8b08e4e3 abacus: bignum: use IIFE
I think it looks cleaner to use Immediately Invoked Function Expressions
in such cases.
2021-10-12 15:02:37 +02:00
2 changed files with 10 additions and 10 deletions

View file

@ -4,7 +4,7 @@ enable_testing()
add_library(common_options INTERFACE)
target_compile_features(common_options INTERFACE
cxx_std_17
cxx_std_20
)
target_compile_options(common_options INTERFACE
-Wall

View file

@ -3,6 +3,7 @@
#include <algorithm>
#include <iostream>
#include <iterator>
#include <span>
#include <cassert>
#include <cmath>
@ -82,18 +83,17 @@ digits_type do_addition(digits_type const& lhs, digits_type const& rhs) {
++it2;
}
auto it = it1;
auto end = end1;
if (it1 == end1) {
it = it2;
end = end2;
}
auto leftover = [=]() {
if (it1 != end1) {
return std::span(it1, end1);
}
return std::span(it2, end2);
}();
while (it != end) {
int addition = *it + carry;
for (auto value : leftover) {
int addition = value + carry;
carry = addition / BASE;
res.push_back(addition % BASE);
++it;
}
if (carry != 0) {