| 20 | |
| 21 | template <typename K, typename V, typename Compare = std::less<K>> |
| 22 | vector<pair<K, V>> ordered(const das_hash_map<K, V> &unsorted_map, Compare cmp = {}) { |
| 23 | static_assert(!is_pointer_v<K> || |
| 24 | !is_same_v<Compare, less<K>>, |
| 25 | "When K is pointer you should provide user-defined comparator. " |
| 26 | "Because we use this method to avoid nondeterminism in map traversal."); |
| 27 | vector<pair<K, V>> sorted_vector(unsorted_map.begin(), unsorted_map.end()); |
| 28 | |
| 29 | // Sort the vector by key |
| 30 | sort(sorted_vector.begin(), sorted_vector.end(), |
| 31 | [&cmp](const auto &p1, const auto &p2) { return cmp(p1.first, p2.first); } ); |
| 32 | return sorted_vector; |
| 33 | } |
| 34 | |
| 35 | // Insert-only variant — same body, different parameter type. Two overloads |
| 36 | // rather than a generic template so the static_assert / signature stay symmetric. |
no test coverage detected