diff --git a/core/include/userver/utils/statistics/labels.hpp b/core/include/userver/utils/statistics/labels.hpp index 23b540eb00ae..893f7dafe44e 100644 --- a/core/include/userver/utils/statistics/labels.hpp +++ b/core/include/userver/utils/statistics/labels.hpp @@ -19,16 +19,21 @@ class LabelView final { LabelView() = default; LabelView(Label&& label) = delete; explicit LabelView(const Label& label) noexcept; - LabelView(std::string_view name, std::string_view value) noexcept : name_(name), value_(value) {} + constexpr LabelView(std::string_view name, std::string_view value) noexcept : name_(name), value_(value) {} - explicit operator bool() const { return !name_.empty(); } + template >* = nullptr> + constexpr LabelView(std::string_view, T) { + static_assert(sizeof(T) && false, "Labels should not be arithmetic values, only strings!"); + } + + constexpr explicit operator bool() const { return !name_.empty(); } - std::string_view Name() const { return name_; } - std::string_view Value() const { return value_; } + constexpr std::string_view Name() const { return name_; } + constexpr std::string_view Value() const { return value_; } private: - std::string_view name_; - std::string_view value_; + std::string_view name_{}; + std::string_view value_{}; }; bool operator<(const LabelView& x, const LabelView& y) noexcept; @@ -41,6 +46,11 @@ class Label final { explicit Label(LabelView view); Label(std::string name, std::string value); + template >* = nullptr> + Label(std::string, T) { + static_assert(sizeof(T) && false, "Labels should not be arithmetic values, only strings!"); + } + explicit operator bool() const { return !name_.empty(); } explicit operator LabelView() const { return {name_, value_}; }