Home >Backend Development >C++ >How Do C 14 Transparent Comparators Change Associative Container Lookups?
Changing Associative Containers in C 14 with Transparent Comparators
C 14 has introduced a significant change in associative containers, allowing for "transparent comparators." This change requires that find, count, lower_bound, upper_bound, and equal_range member function templates not participate in overload resolution unless the type Compare::is_transparent exists.
Purpose of Transparent Comparators
Transparent comparators enable the comparison of elements in an associative container using a type different from the key type. This expands the functionality of associative containers, allowing for more flexible and efficient lookups.
Benefits and Changes
This change benefits heterogeneous lookup scenarios, allowing for direct comparison of different data types within the container. However, it does not fundamentally alter the standard containers' behavior by default. If a transparent comparator (e.g., std::less<>) is not explicitly used, containers will continue to operate as before.
Impact on Existing Code
The default comparator for std::set now implicitly specifies Key = std::less
In summary, transparent comparators in C 14 provide enhanced functionality for associative containers, enabling more diverse data comparisons. However, it is important to note that transparent comparators are disabled by default and can be safely adopted by existing code if necessary.
The above is the detailed content of How Do C 14 Transparent Comparators Change Associative Container Lookups?. For more information, please follow other related articles on the PHP Chinese website!