Skip to content

Commit 4a10c2c

Browse files
authored
Fix and test for missing count division (#329)
1 parent 90a58d0 commit 4a10c2c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

include/boost/histogram/detail/atomic_number.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ struct atomic_number : std::atomic<T> {
4848
return *this;
4949
}
5050

51+
// not thread-safe
52+
atomic_number& operator/=(const T& x) noexcept {
53+
this->store(this->load() / x);
54+
return *this;
55+
}
56+
5157
private:
5258
// for integral types
5359
template <class U = T>

test/accumulators_count_test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ void run_tests() {
4848
c_t two(2);
4949
auto six = two * 3;
5050
BOOST_TEST_EQ(six, static_cast<T>(6));
51+
six *= 2;
52+
BOOST_TEST_EQ(six, static_cast<T>(12));
53+
}
54+
55+
{
56+
c_t six(6);
57+
auto two = six / 3;
58+
BOOST_TEST_EQ(two, static_cast<T>(2));
59+
two /= 2;
60+
BOOST_TEST_EQ(two, static_cast<T>(1));
5161
}
5262
}
5363

0 commit comments

Comments
 (0)