userver: userver/utils/str_icase_containers.hpp Source File
Loading...
Searching...
No Matches
str_icase_containers.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/utils/str_icase_containers.hpp
4/// @brief Contains utilities for working with containers with
5/// utils::StrCaseHash and utils::StrIcaseHash.
6/// @ingroup userver_universal
7
8#include <unordered_map>
9#include <unordered_set>
10
11#include <userver/utils/algo.hpp>
12#include <userver/utils/str_icase.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace utils {
17
18/// @brief Converts an unordered [multi-]map or set with the default hash to a
19/// map with utils::StrCaseHash. This might be useful when converting
20/// guaranteed-to-be-safe data to a common operating format.
21template <typename Key, typename Value>
22auto WithSafeHash(const std::unordered_map<Key, Value>& map) {
23 return utils::AsContainer<std::unordered_map<Key, Value, utils::StrCaseHash>>(map);
24}
25
26/// @overload
27template <typename Key, typename Value>
28auto WithSafeHash(std::unordered_map<Key, Value>&& map) {
29 return utils::AsContainer<std::unordered_map<Key, Value, utils::StrCaseHash>>(std::move(map));
30}
31
32/// @overload
33template <typename Key, typename Value>
34auto WithSafeHash(const std::unordered_multimap<Key, Value>& map) {
35 return utils::AsContainer<std::unordered_multimap<Key, Value, utils::StrCaseHash>>(map);
36}
37
38/// @overload
39template <typename Key, typename Value>
40auto WithSafeHash(std::unordered_multimap<Key, Value>&& map) {
41 return utils::AsContainer<std::unordered_multimap<Key, Value, utils::StrCaseHash>>(std::move(map));
42}
43
44/// @overload
45template <typename Key>
46auto WithSafeHash(const std::unordered_set<Key>& map) {
47 return utils::AsContainer<std::unordered_set<Key, utils::StrCaseHash>>(map);
48}
49
50/// @overload
51template <typename Key>
52auto WithSafeHash(std::unordered_set<Key>&& map) {
53 return utils::AsContainer<std::unordered_set<Key, utils::StrCaseHash>>(std::move(map));
54}
55
56/// @overload
57template <typename Key>
58auto WithSafeHash(const std::unordered_multiset<Key>& map) {
59 return utils::AsContainer<std::unordered_multiset<Key, utils::StrCaseHash>>(map);
60}
61
62/// @overload
63template <typename Key>
64auto WithSafeHash(std::unordered_multiset<Key>&& map) {
65 return utils::AsContainer<std::unordered_multiset<Key, utils::StrCaseHash>>(std::move(map));
66}
67
68} // namespace utils
69
70USERVER_NAMESPACE_END