userver: userver/yaml_config/map_to_array.hpp Source File
Loading...
Searching...
No Matches
map_to_array.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/yaml_config/map_to_array.hpp
4/// @brief @copybrief yaml_config::ParseMapToArray
5/// @ingroup userver_universal
6
7#include <utility>
8#include <vector>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace yaml_config {
13
14/// @brief Parses YAML object maps into vectors of named elements.
15template <typename T, typename Value>
16std::vector<T> ParseMapToArray(const Value& value) {
17 value.CheckObjectOrNull();
18 std::vector<T> parsed_array;
19 parsed_array.reserve(value.GetSize());
20
21 for (auto [elem_name, elem_value] : Items(value)) {
22 auto parsed = elem_value.template As<T>();
23 parsed.SetName(std::move(elem_name));
24 parsed_array.emplace_back(std::move(parsed));
25 }
26 return parsed_array;
27}
28
29} // namespace yaml_config
30
31USERVER_NAMESPACE_END