userver: userver/yaml_config/map_to_array.hpp Source File
Loading...
Searching...
No Matches
map_to_array.hpp
1#pragma once
2
3#include <utility>
4#include <vector>
5
6USERVER_NAMESPACE_BEGIN
7
8namespace yaml_config {
9
10template <typename T, typename Value>
11std::vector<T> ParseMapToArray(const Value& value) {
12 value.CheckObjectOrNull();
13 std::vector<T> parsed_array;
14 parsed_array.reserve(value.GetSize());
15
16 for (auto [elem_name, elem_value] : Items(value)) {
17 auto parsed = elem_value.template As<T>();
18 parsed.SetName(std::move(elem_name));
19 parsed_array.emplace_back(std::move(parsed));
20 }
21 return parsed_array;
22}
23
24} // namespace yaml_config
25
26USERVER_NAMESPACE_END