Tessil / ordered-map

C++ hash map and hash set which preserve the order of insertion
MIT License
512 stars 66 forks source link

Comparing keys between two tsl::ordered_map objects #40

Open michael-projectx opened 1 year ago

michael-projectx commented 1 year ago

This is more of a question than an issue:

I have two tsl::ordered_map objects with the same signature, e.g. tsl::ordered_map<std::string, std::shared_ptr<MyCustomType>>

I'd like to be able to find the intersection of common keys between them. When using a std::unordered_map, I can use the ranges-v3 library to do this:

std::unordered_map<std::string, std::shared_ptr<MyCustomType>> = { {"key1", ...}, {"key2", ...} };
std::unordered_map<std::string, std::shared_ptr<MyCustomType>> = { {"key3", ...}, {"key2", ...} };

const auto common_keys =
      ranges::views::set_intersection(cfg1 | ranges::views::keys, cfg2 | ranges::views::keys);

// common_keys will contain "key2"

When I do the same with a tsl::ordered_map then common_keys is empty. This makes sense per the readme indicating that insertion order matters for the equality operator. The question then is, how would I achieve the above?