ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
ALib.Strings.StdFunctors.H
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8#ifndef H_ALIB_STRINGS_STDFUNCTORS
9#define H_ALIB_STRINGS_STDFUNCTORS
10#pragma once
11#ifndef INL_ALIB
12# include "alib/alib.inl"
13#endif
14#if ALIB_STRINGS
15#include "ALib.Lang.H"
16#include "ALib.Strings.H"
17
18#if DOXYGEN
19 namespace alib::strings {
20 /// This namespace contains sub-namespaces that provide compatibility of 3rd-party types and
21 /// module \alib_strings_nl.<br>
22 /// The entities of those namespaces become available with the inclusion of specific headers
23 /// that import a certain C++20 Module or inject the functionality into a namespace in a
24 /// traditional fashion, for example, header \implude{Strings.StdFunctors}.
25 namespace compatibility {
26
27 /// This namespace documents compatibility features of \alib_strings_nl and the
28 /// standard C++ class library found in namespace \c std.
29 namespace std {
30}}}
31#endif
32
33//##################################################################################################
34// #### std::hash and std::equal_to for ALib string types
35//##################################################################################################
36#if DOXYGEN
38#else
39namespace std {
40#endif
41
42//==================================================================================================
43/// Specialization of functor <c>std::hash</c> for type \alib{strings;TString<TChar>;String}.
44/// Note that this specialization can also be used in combination with derived string-types, like
45/// \alib{strings;TAString<TChar>;AString}.
46///
47/// This specialization is provided with the inclusion of header-file
48/// \implude{Strings.StdFunctors}.<br>
49///
50/// \note
51/// While the documentation indicates namespace <c>alib::strings::compatibility::std</c>,
52/// the true location is namespace <c>std</c> (as mandatory).
53///
54/// @tparam TChar The character type of the string.
55//==================================================================================================
56template<typename TChar>
57struct hash<alib::strings::TString<TChar>> {
58 /// Calculates the hash code for \alib strings.
59 /// @param src The string object to hash.
60 /// @return The hash code.
61 std::size_t operator()(const alib::strings::TString<TChar>& src) const
62 { return src.Hashcode(); }
63};
64
65//==================================================================================================
66/// Specialization of functor <c>std::equal_to</c> for type \alib{strings;TString<TChar>;String}.
67/// Note that this specialization can also be used in combination with derived string-types, like
68/// \alib{strings;TAString<TChar>;AString}.
69///
70/// This specialization is provided with the inclusion of header-file
71/// \implude{Strings.StdFunctors}.<br>
72///
73/// \note
74/// While the documentation indicates namespace <c>alib::strings::compatibility::std</c>,
75/// the true location is namespace <c>std</c> (as mandatory).
76///
77/// @tparam TChar The character type of the strings to compare.
78//==================================================================================================
79template<typename TChar>
80struct equal_to<alib::strings::TString<TChar>>
81{
82 /// Invokes \alib{strings;TString::Equals;String::Equals} on \p{lhs}, passing \p{rhs}
83 /// and returns the result.
84 /// @param lhs The first string object.
85 /// @param rhs The second string object.
86 /// @return The result of the comparison.
88 const alib::strings::TString<TChar>& rhs ) const
89 { return lhs.Equals( rhs ); }
90};
91
92//==================================================================================================
93/// Specialization of functor <c>std::less</c> for strings of templated character type.
94///
95/// For the comparison, \alib{strings::TString;CompareTo} is invoked on \p{lhs} with passing
96/// \p{rhs}.
97///
98/// This specialization is provided with the inclusion of header-file
99/// \implude{Strings.StdFunctors}.<br>
100///
101/// \note
102/// While the documentation indicates namespace <c>alib::strings::compatibility::std</c>,
103/// the true location is namespace <c>std</c> (as mandatory).
104///
105/// @tparam TChar The character type of the strings to compare.
106//==================================================================================================
107template<typename TChar>
108struct less<alib::strings::TString<TChar>>
109{
110 /// Compares the two given strings.
111 /// @param lhs The left-hand side string.
112 /// @param rhs The right-hand side string.
113 /// @return The result of the comparison.
115 const alib::strings::TString<TChar>& rhs) const
116 { return lhs.CompareTo(rhs) < 0; }
117};
118
119#if !DOXYGEN
120} // namespace [std]
121namespace alib {
122#endif
123
124//==================================================================================================
125/// Functor that can be used as an explicitly given replacement for <c>std::hash</c> with template
126/// types (containers) found in namespace \c std.<br>
127/// While the specialization of <c>std::hash</c> for type \alib{strings;TString<TChar>;String},
128/// which is used by the default values of template arguments of the corresponding types in namespace
129/// \c std, performs a case-sensitive hash code calculation, this version creates the same
130/// hash code for two strings that only differ in the letter case of one or more characters.
131///
132/// Note that this specialization can also be used in combination with derived string-types, like
133/// \alib{strings;TAString<TChar>;AString}.
134///
135/// This functor is provided with the inclusion of header-file
136/// \implude{Strings.StdFunctors}.
137///
138/// \note
139/// While the documentation indicates namespace <c>alib::strings::compatibility::std</c>,
140/// the true location is namespace <c>std</c> (as mandatory).
141///
142/// @tparam TChar The character type of the string. Defaults to \alib{characters;character}.
143//==================================================================================================
144template<typename TChar= characters::character>
146{
147 /// Calculates the hash code \alib strings, ignoring the letter case.
148 /// @param src The string object to hash.
149 /// @return The hash code.
150 size_t operator()(const strings::TString<TChar>& src) const { return src.HashcodeIgnoreCase(); }
151};
152
153//==================================================================================================
154/// Functor that can be used as an explicitly given replacement for <c>std::equal_to</c> with template
155/// types (containers) found in namespace \c std.<br>
156/// While the specialization of <c>std::equal_to</c> for type \alib{strings;TString<TChar>;String},
157/// which is used by the default values of template arguments of the corresponding types in namespace
158/// \c std, performs a case-sensitive comparison, this version ignores the letter case of the
159/// characters of the given strings.
160///
161/// Note that this specialization can also be used in combination with derived string-types, like
162/// \alib{strings;TAString<TChar>;AString}.
163///
164/// This functor is provided with the inclusion of header-file
165/// \implude{Strings.StdFunctors}.
166///
167/// \note
168/// While the documentation indicates namespace <c>alib::strings::compatibility::std</c>,
169/// the true location is namespace <c>alib</c>.
170///
171/// @tparam TChar The character type of the strings to compare.
172/// Defaults to \alib{characters;character}.
173//==================================================================================================
174template<typename TChar= characters::character>
176{
177 /// Invokes \alib{strings;TString::Equals;String::Equals} on \p{lhs}, passing \p{rhs}
178 /// and returns the result.
179 ///
180 /// @param lhs The first string object.
181 /// @param rhs The second string object.
182 /// @return The result of the comparison.
184 const strings::TString<TChar>& rhs ) const
185 { return lhs.template Equals<alib::CHK, lang::Case::Ignore>( rhs ); }
186};
187
188//==================================================================================================
189/// Specialization of functor <c>std::less</c> for strings of templated character type.
190///
191/// For the comparison, \alib{strings::TString;CompareTo;CompareTo<Case::Ignore>} is invoked on
192/// \p{lhs} with passing \p{rhs}.
193///
194/// This specialization is provided with the inclusion of header-file
195/// \implude{Strings.StdFunctors}.<br>
196///
197/// \note
198/// While the documentation indicates namespace <c>alib::strings::compatibility::std</c>,
199/// the true location is namespace <c>std</c> (as mandatory).
200///
201/// @tparam TChar The character type of the strings to compare.
202/// Defaults to \alib{characters;character}.
203//==================================================================================================
204template<typename TChar= characters::character>
206{
207 /// Compares the two given strings.
208 /// @param lhs The left-hand side string.
209 /// @param rhs The right-hand side string.
210 /// @return \c true if \p{lhs} is less than \p{rhs}.
212 const strings::TString<TChar>& rhs) const
213 { return lhs.template CompareTo<lang::Case::Ignore>( rhs ) < 0; }
214};
215
216} // namespace alib
217
218#endif // ALIB_STRINGS
219#endif // H_ALIB_STRINGS_STDFUNCTORS
std::size_t HashcodeIgnoreCase() const
std::size_t Hashcode() const
bool Equals(const TString< TChar > &rhs) const
Definition string.inl:531
int CompareTo(const TString< TChar > &rhs) const
Definition string.inl:584
bool operator()(const alib::strings::TString< TChar > &lhs, const alib::strings::TString< TChar > &rhs) const
bool operator()(const strings::TString< TChar > &lhs, const strings::TString< TChar > &rhs) const
std::size_t operator()(const alib::strings::TString< TChar > &src) const
size_t operator()(const strings::TString< TChar > &src) const
bool operator()(const alib::strings::TString< TChar > &lhs, const alib::strings::TString< TChar > &rhs) const
bool operator()(const strings::TString< TChar > &lhs, const strings::TString< TChar > &rhs) const