File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed
Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,8 @@ class mean {
152152 }
153153
154154private:
155+ friend struct unsafe_access ;
156+
155157 internal_data_type data_{0 , 0 , 0 };
156158};
157159
Original file line number Diff line number Diff line change @@ -110,6 +110,15 @@ struct unsafe_access {
110110 static constexpr auto & storage_adaptor_impl (storage_adaptor<T>& storage) {
111111 return static_cast <typename storage_adaptor<T>::impl_type&>(storage);
112112 }
113+
114+ /* *
115+ Get internal data of accumulators::mean.
116+ @param obj instance of accumulator.
117+ */
118+ template <class T >
119+ static constexpr auto & accumulators_mean_impl (T&& m) {
120+ return m.data_ ;
121+ }
113122};
114123
115124} // namespace histogram
Original file line number Diff line number Diff line change 77#include < boost/core/lightweight_test.hpp>
88#include < boost/histogram/accumulators/mean.hpp>
99#include < boost/histogram/accumulators/ostream.hpp>
10+ #include < boost/histogram/unsafe_access.hpp>
1011#include < boost/histogram/weight.hpp>
1112#include < sstream>
1213#include " is_close.hpp"
@@ -110,5 +111,16 @@ int main() {
110111 BOOST_TEST_IS_CLOSE (a.variance (), b.variance (), 1e-3 );
111112 }
112113
114+ // unsafe_access
115+ {
116+ m_t a;
117+ a (1 );
118+ a (2 );
119+
120+ BOOST_TEST_EQ (a.count (), 2 );
121+ unsafe_access::accumulators_mean (a).sum_ = 1 ;
122+ BOOST_TEST_EQ (a.count (), 1 );
123+ }
124+
113125 return boost::report_errors ();
114126}
You can’t perform that action at this time.
0 commit comments