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 constexpr LabelView(std::string_view name, std::string_view value)
noexcept : name_(name), value_(value) {}
24 template <
class T, std::enable_if_t<std::is_arithmetic_v<T>>* =
nullptr>
25 constexpr LabelView(std::string_view, T) {
26 static_assert(
sizeof(T) &&
false,
"Labels should not be arithmetic values, only strings!");
29 constexpr explicit operator
bool()
const {
return !name_.empty(); }
31 constexpr std::string_view Name()
const {
return name_; }
32 constexpr std::string_view Value()
const {
return value_; }
35 std::string_view name_{};
36 std::string_view value_{};
39bool operator<(
const LabelView& x,
const LabelView& y)
noexcept;
40bool operator==(
const LabelView& x,
const LabelView& y)
noexcept;
46 explicit Label(LabelView view);
47 Label(std::string name, std::string value);
49 template <
class T, std::enable_if_t<std::is_arithmetic_v<T>>* =
nullptr>
50 Label(std::string, T) {
51 static_assert(
sizeof(T) &&
false,
"Labels should not be arithmetic values, only strings!");
54 explicit operator
bool()
const {
return !name_.empty(); }
55 explicit operator LabelView()
const {
return {name_, value_}; }
57 const std::string& Name()
const {
return name_; }
58 const std::string& Value()
const& {
return value_; }
59 std::string& Value() & {
return value_; }
60 std::string&& Value() && {
return std::move(value_); }
67bool operator<(
const Label& x,
const Label& y)
noexcept;
68bool operator==(
const Label& x,
const Label& y)
noexcept;
71class LabelsSpan
final {
73 using iterator =
const LabelView*;
74 using const_iterator =
const LabelView*;
76 LabelsSpan() =
default;
77 LabelsSpan(
const LabelView* begin,
const LabelView* end)
noexcept;
78 LabelsSpan(std::initializer_list<LabelView> il)
noexcept : LabelsSpan(il.begin(), il.end()) {}
84 decltype(*(std::declval<
const Container&>().data() + std::declval<
const Container&>().size())),
87 LabelsSpan(
const Container& cont)
noexcept : LabelsSpan(cont.data(), cont.data() + cont.size()) {}
89 const LabelView* begin()
const noexcept {
return begin_; }
90 const LabelView* end()
const noexcept {
return end_; }
91 std::size_t size()
const noexcept {
return end_ - begin_; }
92 bool empty()
const noexcept {
return end_ == begin_; }
95 const LabelView* begin_{
nullptr};
96 const LabelView* end_{
nullptr};