userver: userver/utils/str_icase_containers.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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>>(
24 map);
25}
26
27/// @overload
28template <typename Key, typename Value>
29auto WithSafeHash(std::unordered_map<Key, Value>&& map) {
30 return utils::AsContainer<std::unordered_map<Key, Value, utils::StrCaseHash>>(
31 std::move(map));
32}
33
34/// @overload
35template <typename Key, typename Value>
36auto WithSafeHash(const std::unordered_multimap<Key, Value>& map) {
37 return utils::AsContainer<
38 std::unordered_multimap<Key, Value, utils::StrCaseHash>>(map);
39}
40
41/// @overload
42template <typename Key, typename Value>
43auto WithSafeHash(std::unordered_multimap<Key, Value>&& map) {
44 return utils::AsContainer<
45 std::unordered_multimap<Key, Value, utils::StrCaseHash>>(std::move(map));
46}
47
48/// @overload
49template <typename Key>
50auto WithSafeHash(const std::unordered_set<Key>& map) {
51 return utils::AsContainer<std::unordered_set<Key, utils::StrCaseHash>>(map);
52}
53
54/// @overload
55template <typename Key>
56auto WithSafeHash(std::unordered_set<Key>&& map) {
57 return utils::AsContainer<std::unordered_set<Key, utils::StrCaseHash>>(
58 std::move(map));
59}
60
61/// @overload
62template <typename Key>
63auto WithSafeHash(const std::unordered_multiset<Key>& map) {
64 return utils::AsContainer<std::unordered_multiset<Key, utils::StrCaseHash>>(
65 map);
66}
67
68/// @overload
69template <typename Key>
70auto WithSafeHash(std::unordered_multiset<Key>&& map) {
71 return utils::AsContainer<std::unordered_multiset<Key, utils::StrCaseHash>>(
72 std::move(map));
73}
74
75} // namespace utils
76
77USERVER_NAMESPACE_END