10#include <userver/utils/statistics/histogram_view.hpp>
11#include <userver/utils/statistics/rate.hpp>
13USERVER_NAMESPACE_BEGIN
15namespace utils::statistics {
20class MetricValue
final {
22 using RawType = std::variant<std::int64_t,
double,
Rate, HistogramView>;
25 MetricValue(
const MetricValue&) =
default;
26 MetricValue& operator=(
const MetricValue&) =
default;
28 bool operator==(
const MetricValue& other)
const noexcept {
29 return value_ == other.value_;
32 bool operator!=(
const MetricValue& other)
const noexcept {
33 return value_ != other.value_;
38 std::int64_t
AsInt()
const {
return std::get<std::int64_t>(value_); }
42 double AsFloat()
const {
return std::get<
double>(value_); }
49 bool IsRate()
const noexcept {
return std::holds_alternative<Rate>(value_); }
53 HistogramView
AsHistogram()
const {
return std::get<HistogramView>(value_); }
57 return std::holds_alternative<HistogramView>(value_);
62 template <
typename VisitorFunc>
63 decltype(
auto)
Visit(VisitorFunc visitor)
const {
64 return std::visit(visitor, value_);
68 MetricValue()
noexcept : value_(std::int64_t{0}) {}
70 explicit MetricValue(RawType value)
noexcept : value_(value) {}