ContainerUtils.h 559 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * ContainerUtils.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. namespace vstd
  12. {
  13. template<typename K, typename V>
  14. std::map<V, K> invertMap(const std::map<K, V> & m)
  15. {
  16. std::map<V,K> other;
  17. std::transform(m.cbegin(), m.cend(), std::inserter(other, other.begin()), [](const std::pair<K, V> & p)
  18. {
  19. return std::make_pair(p.second, p.first);
  20. });
  21. return other;
  22. }
  23. }