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