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) &&
false,
"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_{};
86class LabelsSpan
final {
88 using iterator =
const LabelView*;
89 using const_iterator =
const LabelView*;
91 LabelsSpan() =
default;
92 LabelsSpan(
const LabelView* begin,
const LabelView* end)
noexcept;
93 LabelsSpan(std::initializer_list<LabelView> il)
noexcept : LabelsSpan(il.begin(), il.end()) {}
99 decltype(*(std::declval<
const Container&>().data() + std::declval<
const Container&>().size())),
102 LabelsSpan(
const Container& cont)
noexcept : LabelsSpan(cont.data(), cont.data() + cont.size()) {}
104 const LabelView* begin()
const noexcept {
return begin_; }
105 const LabelView* end()
const noexcept {
return end_; }
106 std::size_t size()
const noexcept {
return end_ - begin_; }
107 bool empty()
const noexcept {
return end_ == begin_; }
110 const LabelView* begin_{
nullptr};
111 const LabelView* end_{
nullptr};
119struct fmt::formatter<USERVER_NAMESPACE::utils::statistics::LabelView> {
120 constexpr static auto parse(format_parse_context& ctx) {
return ctx.begin(); }
122 template <
typename FormatContext>
123 auto format(USERVER_NAMESPACE::utils::statistics::LabelView value, FormatContext& ctx)
const {
124 return fmt::format_to(ctx.out(),
"{}={}", value.Name(), value.Value());
129struct fmt::formatter<USERVER_NAMESPACE::utils::statistics::Label>
130 :
public fmt::formatter<USERVER_NAMESPACE::utils::statistics::LabelView> {
131 template <
typename FormatContext>
132 auto format(
const USERVER_NAMESPACE::utils::statistics::Label& value, FormatContext& ctx)
const {
133 return formatter<USERVER_NAMESPACE::utils::statistics::LabelView>::format(
134 USERVER_NAMESPACE::utils::statistics::LabelView{value},
141struct fmt::formatter<USERVER_NAMESPACE::utils::statistics::LabelsSpan> {
142 constexpr static auto parse(format_parse_context& ctx) {
return ctx.begin(); }
144 fmt::format_context::iterator format(
145 USERVER_NAMESPACE::utils::statistics::LabelsSpan value,
146 fmt::format_context& ctx