Fix and test for missing count division (#329)

This commit is contained in:
Hans Dembinski 2021-08-19 14:22:41 +02:00 committed by GitHub
parent 90a58d03ee
commit 4a10c2c11b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -48,6 +48,12 @@ struct atomic_number : std::atomic<T> {
return *this;
}
// not thread-safe
atomic_number& operator/=(const T& x) noexcept {
this->store(this->load() / x);
return *this;
}
private:
// for integral types
template <class U = T>

View File

@ -48,6 +48,16 @@ void run_tests() {
c_t two(2);
auto six = two * 3;
BOOST_TEST_EQ(six, static_cast<T>(6));
six *= 2;
BOOST_TEST_EQ(six, static_cast<T>(12));
}
{
c_t six(6);
auto two = six / 3;
BOOST_TEST_EQ(two, static_cast<T>(2));
two /= 2;
BOOST_TEST_EQ(two, static_cast<T>(1));
}
}