Skip to content

Commit dc83ac9

Browse files
committed
fix components: allow passing string_view as custom name to Append
commit_hash:aba32910ca2a4a3d8b32f5d5ae12a135bc25af8c
1 parent 1029586 commit dc83ac9

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

core/include/userver/components/component_list.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ class Manager;
2020
namespace impl {
2121

2222
template <class T>
23-
auto NameRegistrationFromComponentType() -> decltype(std::string{T::kName}) {
24-
return std::string{T::kName};
23+
auto NameRegistrationFromComponentType()
24+
-> decltype(std::string_view{T::kName}) {
25+
return std::string_view{T::kName};
2526
}
2627

2728
template <class T, class... Args>
2829
auto NameRegistrationFromComponentType(Args...) {
2930
static_assert(!sizeof(T),
3031
"Component does not have a 'kName' member convertible to "
31-
"std::string. You have to explicitly specify the name: "
32+
"std::string_view. You have to explicitly specify the name: "
3233
"component_list.Append<T>(name).");
33-
return std::string{};
34+
return std::string_view{};
3435
}
3536

3637
using ComponentBaseFactory =
@@ -138,7 +139,7 @@ class ComponentList final {
138139

139140
/// Appends a component with a provided component name.
140141
template <typename Component>
141-
ComponentList& Append(std::string name) &;
142+
ComponentList& Append(std::string_view name) &;
142143

143144
/// Merges components from `other` into `*this`.
144145
ComponentList& AppendComponentList(ComponentList&& other) &;
@@ -176,9 +177,9 @@ ComponentList& ComponentList::Append() & {
176177
}
177178

178179
template <typename Component>
179-
ComponentList& ComponentList::Append(std::string name) & {
180+
ComponentList& ComponentList::Append(std::string_view name) & {
180181
using Adder = impl::ComponentAdder<Component>;
181-
auto adder = std::make_unique<const Adder>(std::move(name));
182+
auto adder = std::make_unique<const Adder>(std::string{name});
182183
return Append(std::move(adder));
183184
}
184185

0 commit comments

Comments
 (0)