File indexing completed on 2025-01-30 09:43:44
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_HISTOGRAM_ACCUMULATORS_OSTREAM_HPP
0008 #define BOOST_HISTOGRAM_ACCUMULATORS_OSTREAM_HPP
0009
0010 #include <boost/histogram/detail/counting_streambuf.hpp>
0011 #include <boost/histogram/fwd.hpp>
0012 #include <ios>
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
0027
0028 namespace boost {
0029 namespace histogram {
0030
0031 namespace detail {
0032
0033 template <class CharT, class Traits, class T>
0034 std::basic_ostream<CharT, Traits>& handle_nonzero_width(
0035 std::basic_ostream<CharT, Traits>& os, const T& x) {
0036 const auto w = os.width();
0037 os.width(0);
0038 std::streamsize count = 0;
0039 {
0040 auto g = make_count_guard(os, count);
0041 os << x;
0042 }
0043 if (os.flags() & std::ios::left) {
0044 os << x;
0045 for (auto i = count; i < w; ++i) os << os.fill();
0046 } else {
0047 for (auto i = count; i < w; ++i) os << os.fill();
0048 os << x;
0049 }
0050 return os;
0051 }
0052
0053 }
0054
0055 namespace accumulators {
0056
0057 template <class CharT, class Traits, class U, bool B>
0058 std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
0059 const count<U, B>& x) {
0060 return os << x.value();
0061 }
0062
0063 template <class CharT, class Traits, class U>
0064 std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
0065 const sum<U>& x) {
0066 if (os.width() == 0)
0067 return os << "sum(" << x.large_part() << " + " << x.small_part() << ")";
0068 return detail::handle_nonzero_width(os, x);
0069 }
0070
0071 template <class CharT, class Traits, class U>
0072 std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
0073 const weighted_sum<U>& x) {
0074 if (os.width() == 0)
0075 return os << "weighted_sum(" << x.value() << ", " << x.variance() << ")";
0076 return detail::handle_nonzero_width(os, x);
0077 }
0078
0079 template <class CharT, class Traits, class U>
0080 std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
0081 const mean<U>& x) {
0082 if (os.width() == 0)
0083 return os << "mean(" << x.count() << ", " << x.value() << ", " << x.variance() << ")";
0084 return detail::handle_nonzero_width(os, x);
0085 }
0086
0087 template <class CharT, class Traits, class U>
0088 std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
0089 const weighted_mean<U>& x) {
0090 if (os.width() == 0)
0091 return os << "weighted_mean(" << x.sum_of_weights() << ", " << x.value() << ", "
0092 << x.variance() << ")";
0093 return detail::handle_nonzero_width(os, x);
0094 }
0095
0096 template <class CharT, class Traits, class U>
0097 std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
0098 const fraction<U>& x) {
0099 if (os.width() == 0)
0100 return os << "fraction(" << x.successes() << ", " << x.failures() << ")";
0101 return detail::handle_nonzero_width(os, x);
0102 }
0103
0104 }
0105 }
0106 }
0107
0108 #endif
0109
0110 #endif