10USERVER_NAMESPACE_BEGIN
12namespace utils::statistics {
17class LabelView
final {
19 LabelView() =
default;
20 LabelView(Label&& label) =
delete;
21 explicit LabelView(
const Label& label)
noexcept;
22 LabelView(std::string_view name, std::string_view value)
noexcept : name_(name), value_(value) {}
24 explicit operator
bool()
const {
return !name_.empty(); }
26 std::string_view Name()
const {
return name_; }
27 std::string_view Value()
const {
return value_; }
30 std::string_view name_;
31 std::string_view value_;
34bool operator<(
const LabelView& x,
const LabelView& y)
noexcept;
35bool operator==(
const LabelView& x,
const LabelView& y)
noexcept;
41 explicit Label(LabelView view);
42 Label(std::string name, std::string value);
44 explicit operator
bool()
const {
return !name_.empty(); }
45 explicit operator LabelView()
const {
return {name_, value_}; }
47 const std::string& Name()
const {
return name_; }
48 const std::string& Value()
const& {
return value_; }
49 std::string& Value() & {
return value_; }
50 std::string&& Value() && {
return std::move(value_); }
57bool operator<(
const Label& x,
const Label& y)
noexcept;
58bool operator==(
const Label& x,
const Label& y)
noexcept;
61class LabelsSpan
final {
63 using iterator =
const LabelView*;
64 using const_iterator =
const LabelView*;
66 LabelsSpan() =
default;
67 LabelsSpan(
const LabelView* begin,
const LabelView* end)
noexcept;
68 LabelsSpan(std::initializer_list<LabelView> il)
noexcept : LabelsSpan(il.begin(), il.end()) {}
74 decltype(*(std::declval<
const Container&>().data() + std::declval<
const Container&>().size())),
77 LabelsSpan(
const Container& cont)
noexcept : LabelsSpan(cont.data(), cont.data() + cont.size()) {}
79 const LabelView* begin()
const noexcept {
return begin_; }
80 const LabelView* end()
const noexcept {
return end_; }
81 std::size_t size()
const noexcept {
return end_ - begin_; }
82 bool empty()
const noexcept {
return end_ == begin_; }
85 const LabelView* begin_{
nullptr};
86 const LabelView* end_{
nullptr};