8 Comments
User's avatar
Yacob Cohen-Arazi's avatar

Thanks for posting. This is something that we all need to keep in mind.

It was added to 14 for the ordered containers (map, set) and was added to the unordered ones in 20.

Taras Tsugrii's avatar

yep and unfortunately it's easy to miss in case of implicit conversions. Making everything explicit is my top hope for future C++.

Boris's avatar

Thank you for the article! One more question: Testing it on wandbox, I've seen that it works with the compiler option c++2a but doesn't work for c++17. Is there any way to deal with it for the c++17?

Taras Tsugrii's avatar

You're very welcome. This feature was introduced in C++14 for ordered containers like std::map and std::set, and later in C++20 for unordered containers like std::unordered_map and std::unordered_set according to https://en.cppreference.com/w/cpp/functional.html#Transparent_function_objects. If you need it for earlier versions of C++ standard, I'd recommend to using 3rd party libraries like abseil or folly, since std collections are inefficient anyways and shouldn't be used for performance-sensitive applications.

Boris's avatar

Thank you for the article! One more question: Testing it on wandbox, I've seen that it works with the compiler option c++2a but doesn't work for c++17. Is there any way to deal with it for the c++17?

Boris's avatar

Thank you for the article! One more question: Testing it on wandbox, I've seen that it works with the compiler option c++2a but doesn't work for c++17. Is there any way to deal with it for the c++17?

Nicholas Broune's avatar

Strings are severely what? :)

Taras Tsugrii's avatar

oops, looks like substack ate a few words. I meant to say that strings are severely overused. Sometimes I argue that they shouldn't even have native support in programming languages so that programmers have natural friction when trying to use them. But it's a long rent for a separate article.