Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparing keys between two tsl::ordered_map objects #40

Open
michael-projectx opened this issue Apr 15, 2023 · 0 comments
Open

Comparing keys between two tsl::ordered_map objects #40

michael-projectx opened this issue Apr 15, 2023 · 0 comments

Comments

@michael-projectx
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant