Added mapRemove.

This commit is contained in:
Branimir Karadžić
2016-03-15 18:41:58 -07:00
parent 096a70b7ff
commit 80dd79936a
3 changed files with 38 additions and 1 deletions

View File

@@ -24,6 +24,35 @@ namespace bx
typename MapType::value_type pair(_key, _value);
return _map.insert(it, pair);
}
template<typename MapType>
bool mapRemove(MapType& _map, const typename MapType::value_type::first_type& _first)
{
typename MapType::const_iterator it = _map.find(_first);
if (it != _map.end() )
{
_map.erase(it);
return true;
}
return false;
}
template<typename MapType>
bool mapRemove(MapType& _map, const typename MapType::value_type::second_type& _second)
{
for (typename MapType::const_iterator it = _map.begin(), itEnd = _map.end(); it != itEnd; ++it)
{
if (it->second == _second)
{
_map.erase(it);
return true;
}
}
return false;
}
} // namespace bx
#endif // BX_MAPUTIL_H_HEADER_GUARD

View File

@@ -33,6 +33,9 @@ namespace tinystl {
template<typename Key, typename Value>
struct pair {
typedef Key first_type;
typedef Value second_type;
pair();
pair(const Key& key, const Value& value);