gz-cpp-util 1.3
A c++20 library containing various utilities
utility.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5#include <unordered_map>
6#include <map>
7
8namespace gz::util {
9 template<typename T>
10 concept SplitStringInVectorImplemented = std::same_as<T, std::string_view> || std::same_as<T, std::string>;
11
31 template<SplitStringInVectorImplemented T>
32 std::vector<T> splitStringInVector(const std::string_view& s, const std::string& separator, bool skipEmptyStrings=false);
33
39 {
40 using hash_type = std::hash<std::string_view>;
41 using is_transparent = void;
42
43 size_t operator()(const char* str) const { return hash_type{}(str); }
44 size_t operator()(std::string_view str) const { return hash_type{}(str); }
45 size_t operator()(std::string const& str) const { return hash_type{}(str); }
46 };
61 template<typename T>
62 using unordered_string_map = std::unordered_map<std::string, T, util::string_hash, std::equal_to<>>;
66 template<typename T>
67 using string_map = std::map<std::string, T, util::string_hash, std::equal_to<>>;
72} // namespace gz::util
73
Definition: utility.hpp:39
std::map< std::string, T, util::string_hash, std::equal_to<> > string_map
same as unordered_string_map, but using std::map instead of std::unordered_map
Definition: utility.hpp:67
std::unordered_map< std::string, T, util::string_hash, std::equal_to<> > unordered_string_map
A unordered_map where you can use string_views to access elements.
Definition: utility.hpp:62