BDE 4.14.0 Production release
|
Provide a standard compatible equality predicate for C-strings.
This component provides a struct
, bdlb::CStringEqualTo
, that defines a functor that checks two null-terminated strings for equality using a case-sensitive string comparison, rather than simply comparing the two addresses (as the std::equal_to
functor would do). This comparison functor is suitable for supporting C-strings as keys in unordered associative containers. Note that the container behavior would be undefined if the strings referenced by such pointers were to change value.
This section illustrates intended use of this component.
The following snippets of code illustrate how to create and use a bdlb::CStringEqualTo
object as a binary predicate for the standard library function bsl::equal
to test that two ranges of null-terminated character strings are equal.
First, we create few sequences with null-terminated character strings, making sure that their elements have different memory addresses:
Now, use bdlb::CStringEqualTo() as a binary predicate to compare sequences:
Finally, we observe that bdlb::CStringEqualTo
compares character string by their values, while the default comparator compares addresses: