mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-09 23:04:07 +00:00
add unsafe_access and test it
This commit is contained in:
parent
2d8a55f80e
commit
b731ef252c
@ -152,6 +152,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
friend struct unsafe_access;
|
||||
|
||||
internal_data_type data_{0, 0, 0};
|
||||
};
|
||||
|
||||
|
@ -110,6 +110,15 @@ struct unsafe_access {
|
||||
static constexpr auto& storage_adaptor_impl(storage_adaptor<T>& storage) {
|
||||
return static_cast<typename storage_adaptor<T>::impl_type&>(storage);
|
||||
}
|
||||
|
||||
/**
|
||||
Get internal data of accumulators::mean.
|
||||
@param obj instance of accumulator.
|
||||
*/
|
||||
template <class T>
|
||||
static constexpr auto& accumulators_mean_impl(T&& m) {
|
||||
return m.data_;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace histogram
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/histogram/accumulators/mean.hpp>
|
||||
#include <boost/histogram/accumulators/ostream.hpp>
|
||||
#include <boost/histogram/unsafe_access.hpp>
|
||||
#include <boost/histogram/weight.hpp>
|
||||
#include <sstream>
|
||||
#include "is_close.hpp"
|
||||
@ -110,5 +111,16 @@ int main() {
|
||||
BOOST_TEST_IS_CLOSE(a.variance(), b.variance(), 1e-3);
|
||||
}
|
||||
|
||||
// unsafe_access
|
||||
{
|
||||
m_t a;
|
||||
a(1);
|
||||
a(2);
|
||||
|
||||
BOOST_TEST_EQ(a.count(), 2);
|
||||
unsafe_access::accumulators_mean(a).sum_ = 1;
|
||||
BOOST_TEST_EQ(a.count(), 1);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user