ContainerUtils.h 606 B

1234567891011121314151617181920212223242526272829
  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. VCMI_LIB_NAMESPACE_BEGIN
  12. namespace vstd
  13. {
  14. template<typename K, typename V>
  15. std::map<V, K> invertMap(const std::map<K, V> & m)
  16. {
  17. std::map<V,K> other;
  18. std::transform(m.cbegin(), m.cend(), std::inserter(other, other.begin()), [](const std::pair<K, V> & p)
  19. {
  20. return std::make_pair(p.second, p.first);
  21. });
  22. return other;
  23. }
  24. }
  25. VCMI_LIB_NAMESPACE_END