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

Add Transparent Comparator Support #134

Open
joesdiner opened this issue Apr 19, 2024 · 0 comments · May be fixed by #135
Open

Add Transparent Comparator Support #134

joesdiner opened this issue Apr 19, 2024 · 0 comments · May be fixed by #135

Comments

@joesdiner
Copy link

joesdiner commented Apr 19, 2024

It would be great of boost::program_options::variables_map could have transparent comparator support (c++14 feature), to potentially avoid unnecessary object creation when accessing values in the map. Theoretically only a std::less<> needs to be added as the third template parameter of the std::map variables_map inherits from. Currently:

// 1
boost::program_options::variable_map vm;
vm.find("test"); // implicit std::string object created and destoryed 

// 2
std::string_view sv("test");
vm.find(sv); // does not compile

// 3
vm.find(std::string(sv)); // only way to inspect with a std::string_view, explicit std::string object created and destroyed

With a transparent comparator 1 will not create a std::string object and just compare directly against the c-string literal. 2 will work as shown without any extra objects being created. 3 will be unnecessary

@joesdiner joesdiner linked a pull request Apr 19, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant