maputil.h 720 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * Copyright 2010-2013 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #ifndef BX_MAPUTIL_H_HEADER_GUARD
  6. #define BX_MAPUTIL_H_HEADER_GUARD
  7. #include "bx.h"
  8. namespace bx
  9. {
  10. template<typename MapType>
  11. typename MapType::iterator mapInsertOrUpdate(MapType& _map, const typename MapType::key_type& _key, const typename MapType::mapped_type& _value)
  12. {
  13. typename MapType::iterator it = _map.lower_bound(_key);
  14. if (it != _map.end()
  15. && !_map.key_comp()(_key, it->first) )
  16. {
  17. it->second = _value;
  18. return it;
  19. }
  20. typename MapType::value_type pair(_key, _value);
  21. return _map.insert(it, pair);
  22. }
  23. } // namespace bx
  24. #endif // BX_MAPUTIL_H_HEADER_GUARD