MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / ordered

Function ordered

include/daScript/misc/das_common.h:22–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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.

Callers 9

addRequirementsFunction · 0.85
addModuleMethod · 0.85
for_each_enumerationFunction · 0.85
debug_helper_iter_typesFunction · 0.85
debug_helper_iter_varsFunction · 0.85
debug_helper_iter_funcsFunction · 0.85
debug_helper_iter_enumsFunction · 0.85

Calls 3

sortFunction · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected