Skip to content

Commit

Permalink
Use new-style casting
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph-Edwards committed Oct 22, 2024
1 parent b245b41 commit 054f346
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion include/libsemigroups/bmat8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace libsemigroups {
// Constructor: takes a reference to a byte and the index of the bit in
// that byte
constexpr BitRef(uint64_t& data, size_t index) noexcept
: _data(data), _mask(uint64_t(1) << (63 - index)) {}
: _data(data), _mask(static_cast<uint64_t>(1) << (63 - index)) {}

// Assignment operator to allow setting the bit through the proxy
constexpr BitRef& operator=(bool val) noexcept {
Expand Down
6 changes: 3 additions & 3 deletions include/libsemigroups/paths.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace libsemigroups {
for (size_t i = min; i < max; ++i) {
uint64_t add = std::accumulate(acc.cbegin() + source * N,
acc.cbegin() + source * N + N,
uint64_t(0));
static_cast<uint64_t>(0));
if (add == 0) {
break;
}
Expand Down Expand Up @@ -223,7 +223,7 @@ namespace libsemigroups {
return std::accumulate(number_paths.cbegin_row(source) + min,
number_paths.cbegin_row(source)
+ std::min(topo.size(), max),
uint64_t(0));
static_cast<uint64_t>(0));
}

template <typename Node1, typename Node2>
Expand Down Expand Up @@ -290,7 +290,7 @@ namespace libsemigroups {
return std::accumulate(number_paths.cbegin_row(source) + min,
number_paths.cbegin_row(source)
+ std::min(topo.size(), max),
uint64_t(0));
static_cast<uint64_t>(0));
}

} // namespace detail
Expand Down
2 changes: 1 addition & 1 deletion src/todd-coxeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ namespace libsemigroups {

void ToddCoxeter::report_next_lookahead(size_t old_value) const {
static const std::string pad(8, ' ');
int64_t diff = int64_t(lookahead_next()) - old_value;
int64_t diff = static_cast<int64_t>(lookahead_next()) - old_value;
report_default("ToddCoxeter: next lookahead at {} | {:>12} (nodes) "
"| {:>12} (diff)\n",
pad,
Expand Down
2 changes: 1 addition & 1 deletion tests/test-bmat8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ namespace libsemigroups {
BMat8 zero(0);
REQUIRE(BMat8({{0, 0}, {0, 0}}) == zero);
REQUIRE(BMat8({{0, 0}, {0, 1}}) != zero);
REQUIRE(BMat8({{0, 0}, {0, 1}}) == BMat8(uint64_t(1) << 54));
REQUIRE(BMat8({{0, 0}, {0, 1}}) == BMat8(static_cast<uint64_t>(1) << 54));

REQUIRE_THROWS_AS(BMat8({{0, 0}}), LibsemigroupsException);
REQUIRE_THROWS_AS(BMat8({{0, 1}}), LibsemigroupsException);
Expand Down
40 changes: 20 additions & 20 deletions tests/test-constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ namespace libsemigroups {

REQUIRE(!(UNDEFINED == 0));
REQUIRE(!(UNDEFINED == size_t(0)));
REQUIRE(!(UNDEFINED == int64_t(0)));
REQUIRE(!(UNDEFINED == static_cast<int64_t>((0))));
REQUIRE(!(0 == UNDEFINED));
REQUIRE(!(size_t(0) == UNDEFINED));
REQUIRE(!(int64_t(0) == UNDEFINED));
REQUIRE(!(static_cast<int64_t>((0)) == UNDEFINED));

// operator!=
REQUIRE(!(UNDEFINED != UNDEFINED));
Expand All @@ -46,10 +46,10 @@ namespace libsemigroups {

REQUIRE(UNDEFINED != 0);
REQUIRE(UNDEFINED != size_t(0));
REQUIRE(UNDEFINED != int64_t(0));
REQUIRE(UNDEFINED != static_cast<int64_t>((0)));
REQUIRE(0 != UNDEFINED);
REQUIRE(size_t(0) != UNDEFINED);
REQUIRE(int64_t(0) != UNDEFINED);
REQUIRE(static_cast<int64_t>((0)) != UNDEFINED);

// operator>
REQUIRE(!(UNDEFINED > UNDEFINED));
Expand Down Expand Up @@ -85,10 +85,10 @@ namespace libsemigroups {

REQUIRE(!(POSITIVE_INFINITY == 0));
REQUIRE(!(POSITIVE_INFINITY == size_t(0)));
REQUIRE(!(POSITIVE_INFINITY == int64_t(0)));
REQUIRE(!(POSITIVE_INFINITY == static_cast<int64_t>((0))));
REQUIRE(!(0 == POSITIVE_INFINITY));
REQUIRE(!(size_t(0) == POSITIVE_INFINITY));
REQUIRE(!(int64_t(0) == POSITIVE_INFINITY));
REQUIRE(!(static_cast<int64_t>((0)) == POSITIVE_INFINITY));

// operator!=
REQUIRE(!(POSITIVE_INFINITY != POSITIVE_INFINITY));
Expand All @@ -98,10 +98,10 @@ namespace libsemigroups {

REQUIRE(!(POSITIVE_INFINITY == 0));
REQUIRE(POSITIVE_INFINITY != size_t(0));
REQUIRE(POSITIVE_INFINITY != int64_t(0));
REQUIRE(POSITIVE_INFINITY != static_cast<int64_t>((0)));
REQUIRE(0 != POSITIVE_INFINITY);
REQUIRE(size_t(0) != POSITIVE_INFINITY);
REQUIRE(int64_t(0) != POSITIVE_INFINITY);
REQUIRE(static_cast<int64_t>((0)) != POSITIVE_INFINITY);

// operator<
REQUIRE(!(POSITIVE_INFINITY < 0));
Expand All @@ -110,8 +110,8 @@ namespace libsemigroups {
REQUIRE(1000 < POSITIVE_INFINITY);
REQUIRE(size_t(0) < POSITIVE_INFINITY);
REQUIRE(size_t(1000) < POSITIVE_INFINITY);
REQUIRE(int64_t(0) < POSITIVE_INFINITY);
REQUIRE(int64_t(1000) < POSITIVE_INFINITY);
REQUIRE(static_cast<int64_t>((0)) < POSITIVE_INFINITY);
REQUIRE(static_cast<int64_t>((1000)) < POSITIVE_INFINITY);
REQUIRE(NEGATIVE_INFINITY < POSITIVE_INFINITY);

// operator>
Expand All @@ -132,9 +132,9 @@ namespace libsemigroups {
REQUIRE(!(NEGATIVE_INFINITY == LIMIT_MAX));

REQUIRE(!(NEGATIVE_INFINITY == 0));
REQUIRE(!(NEGATIVE_INFINITY == int64_t(0)));
REQUIRE(!(NEGATIVE_INFINITY == static_cast<int64_t>((0))));
REQUIRE(!(0 == NEGATIVE_INFINITY));
REQUIRE(!(int64_t(0) == NEGATIVE_INFINITY));
REQUIRE(!(static_cast<int64_t>((0)) == NEGATIVE_INFINITY));

// operator!=
REQUIRE(!(NEGATIVE_INFINITY != NEGATIVE_INFINITY));
Expand All @@ -143,17 +143,17 @@ namespace libsemigroups {
REQUIRE(NEGATIVE_INFINITY != LIMIT_MAX);

REQUIRE(NEGATIVE_INFINITY != 0);
REQUIRE(NEGATIVE_INFINITY != int64_t(0));
REQUIRE(NEGATIVE_INFINITY != static_cast<int64_t>((0)));
REQUIRE(0 != NEGATIVE_INFINITY);
REQUIRE(int64_t(0) != NEGATIVE_INFINITY);
REQUIRE(static_cast<int64_t>((0)) != NEGATIVE_INFINITY);

// operator<
REQUIRE(NEGATIVE_INFINITY < 0);
REQUIRE(!(NEGATIVE_INFINITY < NEGATIVE_INFINITY));
REQUIRE(!(0 < NEGATIVE_INFINITY));
REQUIRE(!(1000 < NEGATIVE_INFINITY));
REQUIRE(!(int64_t(0) < NEGATIVE_INFINITY));
REQUIRE(!(int64_t(1000) < NEGATIVE_INFINITY));
REQUIRE(!(static_cast<int64_t>((0)) < NEGATIVE_INFINITY));
REQUIRE(!(static_cast<int64_t>((1000)) < NEGATIVE_INFINITY));
REQUIRE(!(POSITIVE_INFINITY < NEGATIVE_INFINITY));

// operator>
Expand All @@ -180,9 +180,9 @@ namespace libsemigroups {
REQUIRE(!(LIMIT_MAX == NEGATIVE_INFINITY));

REQUIRE(!(LIMIT_MAX == -1));
REQUIRE(!(LIMIT_MAX == int64_t(0)));
REQUIRE(!(LIMIT_MAX == static_cast<int64_t>((0))));
REQUIRE(!(-1 == LIMIT_MAX));
REQUIRE(!(int64_t(0) == LIMIT_MAX));
REQUIRE(!(static_cast<int64_t>((0)) == LIMIT_MAX));

// operator!=
REQUIRE(!(LIMIT_MAX != LIMIT_MAX));
Expand All @@ -191,9 +191,9 @@ namespace libsemigroups {
REQUIRE(LIMIT_MAX != NEGATIVE_INFINITY);

REQUIRE(LIMIT_MAX != -1);
REQUIRE(LIMIT_MAX != int64_t(0));
REQUIRE(LIMIT_MAX != static_cast<int64_t>((0)));
REQUIRE(-1 != LIMIT_MAX);
REQUIRE(int64_t(0) != LIMIT_MAX);
REQUIRE(static_cast<int64_t>((0)) != LIMIT_MAX);

// operator>
REQUIRE(!(LIMIT_MAX > LIMIT_MAX));
Expand Down
7 changes: 4 additions & 3 deletions tests/test-digraph-with-sources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1854,9 +1854,10 @@ namespace libsemigroups {
REQUIRE(ad.number_of_paths(1, 1, 0, 10) == 1404);
REQUIRE_THROWS_AS(ad.number_of_paths(1, 1, 0, 10, algorithm::trivial),
LibsemigroupsException);
REQUIRE(ad.number_of_paths(1, 1, 0, 10)
== uint64_t(std::distance(ad.cbegin_pstilo(1, 1, 0, 10),
ad.cend_pstilo())));
REQUIRE(
ad.number_of_paths(1, 1, 0, 10)
== static_cast<uint64_t>(
(std::distance(ad.cbegin_pstilo(1, 1, 0, 10)), ad.cend_pstilo())));

auto checker2 = [&ad](word_type const& w) {
return w.size() < 10 && action_digraph_helper::follow_path(ad, 1, w) == 1;
Expand Down
3 changes: 2 additions & 1 deletion tests/test-paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,8 @@ namespace libsemigroups {
LibsemigroupsException);

p.source(1).target(1).min(0).max(10);
REQUIRE(number_of_paths(wg, 1, 1, 0, 10) == uint64_t((p | count())));
REQUIRE(number_of_paths(wg, 1, 1, 0, 10)
== static_cast<uint64_t>((p | count())));

auto checker2 = [&wg](word_type const& w) {
return w.size() < 10 && word_graph::follow_path(wg, 1, w) == 1;
Expand Down

0 comments on commit 054f346

Please sign in to comment.