utils: hasKey(), getKeyOrEmpty(), getAll(): Take params as references
Somehow, the fact that multimap was being copyied slipped through.
Bu işleme şunda yer alıyor:
ebeveyn
44ade88cae
işleme
b1a8572eb6
8
utils.h
8
utils.h
@ -20,13 +20,13 @@ std::string strreplace(const std::string &str, const std::string &search, const
|
||||
std::string html_xss(std::string_view str);
|
||||
std::string getenv(const std::string &key);
|
||||
|
||||
template <class T, class U> bool hasKey(const std::map<T, U> &map, T key)
|
||||
template <class T, class U> bool hasKey(const std::map<T, U> &map, const T &key)
|
||||
{
|
||||
auto k = map.find(key);
|
||||
return k != map.end();
|
||||
}
|
||||
|
||||
template <class T, class U> U getKeyOrEmpty(const std::map<T, U> &map, T key)
|
||||
template <class T, class U> U getKeyOrEmpty(const std::map<T, U> &map, const T &key)
|
||||
{
|
||||
auto k = map.find(key);
|
||||
if(k != map.end())
|
||||
@ -36,7 +36,7 @@ template <class T, class U> U getKeyOrEmpty(const std::map<T, U> &map, T key)
|
||||
return U();
|
||||
}
|
||||
|
||||
template <class T, class U> U getKeyOrEmpty(std::multimap<T, U> map, T key)
|
||||
template <class T, class U> U getKeyOrEmpty(const std::multimap<T, U> &map, const T &key)
|
||||
{
|
||||
auto k = map.find(key);
|
||||
if(k != map.end())
|
||||
@ -46,7 +46,7 @@ template <class T, class U> U getKeyOrEmpty(std::multimap<T, U> map, T key)
|
||||
return U();
|
||||
}
|
||||
|
||||
template <class T, class U> std::vector<U> getAll(std::multimap<T, U> map, T key)
|
||||
template <class T, class U> std::vector<U> getAll(const std::multimap<T, U> &map, const T &key)
|
||||
{
|
||||
std::vector<U> result;
|
||||
auto range = map.equal_range(key);
|
||||
|
Yükleniyor…
Yeni konuda referans
Bir kullanıcı engelle