9#include <initializer_list>
22template <
typename key_type>
25template <
typename key_type,
typename mapped_type,
typename key_compare = std::less<key_type>,
26 typename allocator_type = std::allocator<std::pair<const key_type, mapped_type>>>
38 for(
auto iter :
fMap) {
39 std::cout << iter.first <<
" - " << iter.second << std::endl;
43 mapped_type&
at(
const key_type& key)
47 }
catch(std::exception& e) {
51 const mapped_type&
at(
const key_type& key)
const
55 }
catch(std::exception& e) {
61 const mapped_type&
operator[](
const key_type& key)
const {
return fMap[key]; }
63 using map_t = std::map<key_type, mapped_type, key_compare, allocator_type>;
64 typename map_t::iterator
begin() {
return fMap.begin(); }
65 typename map_t::const_iterator
begin()
const {
return fMap.begin(); }
66 typename map_t::iterator
end() {
return fMap.end(); }
67 typename map_t::const_iterator
end()
const {
return fMap.end(); }
70 bool empty() const noexcept {
return fMap.empty(); }
71 size_t size() const noexcept {
return fMap.size(); }
78 template <
class... Args>
79 std::pair<typename map_t::iterator, bool>
emplace(Args&&... args)
81 return fMap.emplace(args...);
85 void erase(
typename map_t::iterator pos) {
fMap.erase(pos); }
86 void erase(
typename map_t::iterator first,
typename map_t::iterator last) {
fMap.erase(first, last); }
89 typename map_t::size_type
count(
const key_type* key)
const {
return fMap.count(key); }
90 typename map_t::iterator
find(
const key_type& key) {
return fMap.find(key); }
91 typename map_t::const_iterator
find(
const key_type& key)
const {
return fMap.find(key); }
97 std::map<key_type, mapped_type, key_compare, allocator_type>
fMap;
100template <
typename key_type>
103 template <
typename mapped_type,
typename key_compare,
typename allocator_type>
104 TGRSIMapException(
const key_type key,
const std::map<key_type, mapped_type, key_compare, allocator_type>& map)
105 : std::exception(),
fKey(key)
107 for(
auto iter : map) {
108 fKeys.push_back(iter.first);
114 std::ostringstream str;
115 str <<
"Key " <<
fKey <<
" not found in '";
116 for(
auto key =
fKeys.begin(); key !=
fKeys.end(); ++key) {
118 if(std::next(key) !=
fKeys.end()) {
126 const char*
what() const noexcept
override {
return strdup(
detail().c_str()); }
TGRSIMapException(const key_type key, const std::map< key_type, mapped_type, key_compare, allocator_type > &map)
std::vector< key_type > fKeys
const char * what() const noexcept override
std::string detail() const noexcept
const mapped_type & operator[](const key_type &key) const
map_t::const_iterator begin() const
std::pair< typename map_t::iterator, bool > emplace(Args &&... args)
size_t size() const noexcept
mapped_type & at(const key_type &key)
map_t::size_type count(const key_type *key) const
void erase(typename map_t::iterator first, typename map_t::iterator last)
mapped_type & operator[](const key_type &key)
TGRSIMap(TGRSIMap &&) noexcept=default
std::map< key_type, mapped_type, key_compare, allocator_type > fMap
size_t max_size() const noexcept
void erase(typename map_t::iterator pos)
map_t::const_iterator find(const key_type &key) const
const mapped_type & at(const key_type &key) const
TGRSIMap(const TGRSIMap &)=default
bool empty() const noexcept
map_t::iterator find(const key_type &key)
map_t::const_iterator end() const
std::map< key_type, mapped_type, key_compare, allocator_type > map_t