BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlb_caselessstringviewequalto.h
Go to the documentation of this file.
1/// @file bdlb_caselessstringviewequalto.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlb_caselessstringviewequalto.h -*-C++-*-
8#ifndef INCLUDED_BDLB_CASELESSSTRINGVIEWEQUALTO
9#define INCLUDED_BDLB_CASELESSSTRINGVIEWEQUALTO
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlb_caselessstringviewequalto bdlb_caselessstringviewequalto
15/// @brief Provide a case-insensitive equality predicate for string views.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlb
19/// @{
20/// @addtogroup bdlb_caselessstringviewequalto
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlb_caselessstringviewequalto-purpose"> Purpose</a>
25/// * <a href="#bdlb_caselessstringviewequalto-classes"> Classes </a>
26/// * <a href="#bdlb_caselessstringviewequalto-description"> Description </a>
27/// * <a href="#bdlb_caselessstringviewequalto-usage"> Usage </a>
28/// * <a href="#bdlb_caselessstringviewequalto-example-1-basic-use-of-bdlb-caselessstringviewequalto"> Example 1: Basic Use of bdlb::CaselessStringViewEqualTo </a>
29///
30/// # Purpose {#bdlb_caselessstringviewequalto-purpose}
31/// Provide a case-insensitive equality predicate for string views.
32///
33/// # Classes {#bdlb_caselessstringviewequalto-classes}
34///
35/// - bdlb::CaselessStringViewEqualTo: case-insensitive string view comparison.
36///
37/// @see bdlb_caselessstringviewhash, bdlb_caselessstringviewless
38///
39/// # Description {#bdlb_caselessstringviewequalto-description}
40/// This component provides a `struct`,
41/// `bdlb::CaselessStringViewEqualTo`, that defines a functor that checks two
42/// string views for equality using a case-insensitive string comparison. This
43/// comparison functor is suitable for supporting `bsl::string`s or
44/// `bsl::string_view`s as keys in unordered associative containers.
45///
46/// Note that using this component to do comparisons of keys in a container is
47/// less efficient than converting all the keys to the same case prior to
48/// insertion and then just doing straight string comparisons.
49///
50/// ## Usage {#bdlb_caselessstringviewequalto-usage}
51///
52///
53/// This section illustrates intended use of this component.
54///
55/// ### Example 1: Basic Use of bdlb::CaselessStringViewEqualTo {#bdlb_caselessstringviewequalto-example-1-basic-use-of-bdlb-caselessstringviewequalto}
56///
57///
58/// Suppose we have some strings that compare equal, some that don't, and some
59/// of which are equal except for the cases of some of the letters.
60/// @code
61/// const bsl::string_view a = "To be or not to be, that is the question.";
62/// const bsl::string_view b = "To be or not to be, THAT IS THE QUESTION.";
63/// const bsl::string_view c = "Sein oder nicht sein, das ist die frage.";
64/// @endcode
65/// Now, we create an object of type `bdlb::CaselessStringViewEqualTo` to do the
66/// comparisons:
67/// @code
68/// bdlb::CaselessStringViewEqualTo eq;
69/// const bdlb::CaselessStringViewEqualTo& equals = eq;
70/// @endcode
71/// Finally, we observe that `a` matches `b`, but neither matches `c`:
72/// @code
73/// assert( equals(a, b));
74/// assert( equals(b, a));
75/// assert(!equals(a, c));
76/// assert(!equals(c, a));
77/// assert(!equals(b, c));
78/// assert(!equals(c, b));
79/// @endcode
80/// @}
81/** @} */
82/** @} */
83
84/** @addtogroup bdl
85 * @{
86 */
87/** @addtogroup bdlb
88 * @{
89 */
90/** @addtogroup bdlb_caselessstringviewequalto
91 * @{
92 */
93
94#include <bdlscm_version.h>
95
96#include <bdlb_stringviewutil.h>
97
101
102#include <bsl_string_view.h>
103
104
105namespace bdlb {
106
107 // ================================
108 // struct CaselessStringViewEqualTo
109 // ================================
110
111/// This `struct` defines a case-insensitive equality comparison functor on
112/// string views, enabling them for use as keys in the standard unordered
113/// associative containers such as `bsl::unordered_map` and `bsl::unordered_set`.
114///
115/// \note Note that this `class` is an empty POD type.
116///
117/// See @ref bdlb_caselessstringviewequalto
119
120 // PUBLIC TYPES
123 typedef bool result_type;
124
125 /// Type alias indicating this is a transparent hash functor.
126 typedef void is_transparent;
127
128 // TRAITS
133
134 // CREATORS
135
136 /// Create a `CaselessStringViewEqualTo` object.
138
139 /// Create a `CaselessStringViewEqualTo` object.
140 /// \note Note that as
141 /// `CaselessStringViewEqualTo` is an empty (stateless) type, this
142 /// operation has no observable effect.
144 default;
145
146 /// Destroy this object.
148
149 // MANIPULATORS
150
151 /// Assign to this object the value of the specified `rhs` object, and
152 /// return a reference providing modifiable access to this object.
153 ///
154 /// \note Note that as `CaselessStringViewEqualTo` is an empty (stateless) type,
155 /// this operation has no observable effect.
157 = default;
158
159 // ACCESSORS
160
161 /// Return `true` if the specified `lhs` string view has the same (case
162 /// insensitive) value as the specified `rhs` string view, and `false`
163 /// otherwise.
164 bool operator()(bsl::string_view lhs, bsl::string_view rhs) const;
165};
166
167// ============================================================================
168// INLINE DEFINITIONS
169// ============================================================================
170
171 // --------------------------------
172 // struct CaselessStringViewEqualTo
173 // --------------------------------
174
175// ACCESSORS
176inline
177bool CaselessStringViewEqualTo::operator()(bsl::string_view lhs,
178 bsl::string_view rhs) const
179{
181}
182
183} // close package namespace
184
185
186#endif
187
188// ----------------------------------------------------------------------------
189// Copyright 2021 Bloomberg Finance L.P.
190//
191// Licensed under the Apache License, Version 2.0 (the "License");
192// you may not use this file except in compliance with the License.
193// You may obtain a copy of the License at
194//
195// http://www.apache.org/licenses/LICENSE-2.0
196//
197// Unless required by applicable law or agreed to in writing, software
198// distributed under the License is distributed on an "AS IS" BASIS,
199// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200// See the License for the specific language governing permissions and
201// limitations under the License.
202// ----------------------------- END-OF-FILE ----------------------------------
203
204/** @} */
205/** @} */
206/** @} */
#define BSLMF_NESTED_TRAIT_DECLARATION(t_TYPE, t_TRAIT)
Definition bslmf_nestedtraitdeclaration.h:231
Definition bslstl_stringview.h:471
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlb_algorithmworkaroundutil.h:74
Definition bdlat_valuetypefunctions.h:939
Definition bdlb_caselessstringviewequalto.h:118
bsl::string_view first_argument_type
Definition bdlb_caselessstringviewequalto.h:121
BSLMF_NESTED_TRAIT_DECLARATION(CaselessStringViewEqualTo, bsl::is_trivially_copyable) BSLMF_NESTED_TRAIT_DECLARATION(CaselessStringViewEqualTo
bool result_type
Definition bdlb_caselessstringviewequalto.h:123
void is_transparent
Type alias indicating this is a transparent hash functor.
Definition bdlb_caselessstringviewequalto.h:126
bsl::string_view second_argument_type
Definition bdlb_caselessstringviewequalto.h:122
static bool areEqualCaseless(const bsl::string_view &lhs, const bsl::string_view &rhs)
Definition bdlb_stringviewutil.h:405
Definition bslmf_istriviallycopyable.h:324
Definition bslmf_istriviallydefaultconstructible.h:296