23class LabelView
final {
26 LabelView(Label&& label) =
delete;
27 explicit LabelView(
const Label& label);
28 constexpr LabelView(std::string_view name, std::string_view value)
32 UINVARIANT(!name_.empty(),
"The label name must not be empty.");
35 template <
class T, std::enable_if_t<std::is_arithmetic_v<T>>* =
nullptr>
36 constexpr LabelView(std::string_view, T) {
37 static_assert(!
sizeof(T),
"Labels should not be arithmetic values, only strings!");
40 constexpr explicit operator
bool()
const {
return !name_.empty(); }
42 constexpr std::string_view Name()
const {
return name_; }
43 constexpr std::string_view Value()
const {
return value_; }
46 std::string_view name_{};
47 std::string_view value_{};
88class LabelsSpan
final {
90 using iterator =
const LabelView*;
91 using const_iterator =
const LabelView*;
93 LabelsSpan() =
default;
94 LabelsSpan(
const LabelView* begin,
const LabelView* end)
noexcept;
95 LabelsSpan(std::initializer_list<LabelView> il)
noexcept : LabelsSpan(il.begin(), il.end()) {}
101 decltype(*(std::declval<
const Container&>().data() + std::declval<
const Container&>().size())),
104 LabelsSpan(
const Container& cont)
noexcept : LabelsSpan(cont.data(), cont.data() + cont.size()) {}
106 const LabelView* begin()
const noexcept {
return begin_; }
107 const LabelView* end()
const noexcept {
return end_; }
108 std::size_t size()
const noexcept {
return end_ - begin_; }
109 bool empty()
const noexcept {
return end_ == begin_; }
112 const LabelView* begin_{
nullptr};
113 const LabelView* end_{
nullptr};
121struct fmt::formatter<USERVER_NAMESPACE::
utils::statistics::LabelView> {
122 constexpr static auto parse(format_parse_context& ctx) {
return ctx.begin(); }
124 template <
typename FormatContext>
125 auto format(USERVER_NAMESPACE::
utils::statistics::LabelView value, FormatContext& ctx)
const {
126 return fmt::format_to(ctx.out(),
"{}={}", value.Name(), value.Value());
131struct fmt::formatter<USERVER_NAMESPACE::
utils::statistics::Label>
132 :
public fmt::formatter<USERVER_NAMESPACE::
utils::statistics::LabelView> {
133 template <
typename FormatContext>
134 auto format(
const USERVER_NAMESPACE::
utils::statistics::Label& value, FormatContext& ctx)
const {
135 return formatter<USERVER_NAMESPACE::
utils::statistics::LabelView>::format(
136 USERVER_NAMESPACE::
utils::statistics::LabelView{value},
143struct fmt::formatter<USERVER_NAMESPACE::
utils::statistics::LabelsSpan> {
144 constexpr static auto parse(format_parse_context& ctx) {
return ctx.begin(); }
146 fmt::format_context::iterator format(
147 USERVER_NAMESPACE::
utils::statistics::LabelsSpan value,
148 fmt::format_context& ctx