BDE 4.14.0 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
114/// `bsl::unordered_set`. Note that this `class` is an empty POD type.
116
117 // PUBLIC TYPES
120 typedef bool result_type;
121
122 /// Type alias indicating this is a transparent hash functor.
123 typedef void is_transparent;
124
125 // TRAITS
130
131 // CREATORS
132
133 /// Create a `CaselessStringViewEqualTo` object.
135
136 /// Create a `CaselessStringViewEqualTo` object. Note that as
137 /// `CaselessStringViewEqualTo` is an empty (stateless) type, this
138 /// operation has no observable effect.
140 default;
141
142 /// Destroy this object.
144
145 // MANIPULATORS
146
147 /// Assign to this object the value of the specified `rhs` object, and
148 /// return a reference providing modifiable access to this object. Note
149 /// that as `CaselessStringViewEqualTo` is an empty (stateless) type,
150 /// this operation has no observable effect.
152 = default;
153
154 // ACCESSORS
155
156 /// Return `true` if the specified `lhs` string view has the same (case
157 /// insensitive) value as the specified `rhs` string view, and `false`
158 /// otherwise.
159 bool operator()(bsl::string_view lhs, bsl::string_view rhs) const;
160};
161
162// ============================================================================
163// INLINE DEFINITIONS
164// ============================================================================
165
166 // --------------------------------
167 // struct CaselessStringViewEqualTo
168 // --------------------------------
169
170// ACCESSORS
171inline
172bool CaselessStringViewEqualTo::operator()(bsl::string_view lhs,
173 bsl::string_view rhs) const
174{
176}
177
178} // close package namespace
179
180
181#endif
182
183// ----------------------------------------------------------------------------
184// Copyright 2021 Bloomberg Finance L.P.
185//
186// Licensed under the Apache License, Version 2.0 (the "License");
187// you may not use this file except in compliance with the License.
188// You may obtain a copy of the License at
189//
190// http://www.apache.org/licenses/LICENSE-2.0
191//
192// Unless required by applicable law or agreed to in writing, software
193// distributed under the License is distributed on an "AS IS" BASIS,
194// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
195// See the License for the specific language governing permissions and
196// limitations under the License.
197// ----------------------------- END-OF-FILE ----------------------------------
198
199/** @} */
200/** @} */
201/** @} */
#define BSLMF_NESTED_TRAIT_DECLARATION(t_TYPE, t_TRAIT)
Definition bslmf_nestedtraitdeclaration.h:231
Definition bslstl_stringview.h:441
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_algorithmworkaroundutil.h:74
Definition bdlb_printmethods.h:283
Definition bdlb_caselessstringviewequalto.h:115
bsl::string_view first_argument_type
Definition bdlb_caselessstringviewequalto.h:118
BSLMF_NESTED_TRAIT_DECLARATION(CaselessStringViewEqualTo, bsl::is_trivially_copyable) BSLMF_NESTED_TRAIT_DECLARATION(CaselessStringViewEqualTo
bool result_type
Definition bdlb_caselessstringviewequalto.h:120
void is_transparent
Type alias indicating this is a transparent hash functor.
Definition bdlb_caselessstringviewequalto.h:123
bsl::string_view second_argument_type
Definition bdlb_caselessstringviewequalto.h:119
static bool areEqualCaseless(const bsl::string_view &lhs, const bsl::string_view &rhs)
Definition bdlb_stringviewutil.h:402
Definition bslmf_istriviallycopyable.h:329
Definition bslmf_istriviallydefaultconstructible.h:293