BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslstl_stringview.h
Go to the documentation of this file.
1/// @file bslstl_stringview.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_stringview.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_STRINGVIEW
9#define INCLUDED_BSLSTL_STRINGVIEW
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_stringview bslstl_stringview
15/// @brief Provide a standard-compliant `basic_string_view` class template.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_stringview
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_stringview-purpose"> Purpose</a>
25/// * <a href="#bslstl_stringview-classes"> Classes </a>
26/// * <a href="#bslstl_stringview-description"> Description </a>
27/// * <a href="#bslstl_stringview-lexicographical-comparisons"> Lexicographical Comparisons </a>
28/// * <a href="#bslstl_stringview-operations"> Operations </a>
29/// * <a href="#bslstl_stringview-user-defined-literals"> User-defined literals </a>
30/// * <a href="#bslstl_stringview-usage"> Usage </a>
31/// * <a href="#bslstl_stringview-example-1-basic-syntax"> Example 1: Basic Syntax </a>
32///
33/// # Purpose {#bslstl_stringview-purpose}
34/// Provide a standard-compliant `basic_string_view` class template.
35///
36/// # Classes {#bslstl_stringview-classes}
37///
38/// - bsl::basic_string_view: C++ compliant `basic_string_view` implementation
39/// - bsl::string_view: `typedef` for `bsl::basic_string_view<char>`
40/// - bsl::wstring_view: `typedef` for `bsl::basic_string_view<wchar_t>`
41///
42/// **Canonical header:** bsl_string_view.h
43///
44/// @see ISO C++ Standard, bdlb_stringviewutil
45///
46/// # Description {#bslstl_stringview-description}
47/// This component defines a single class template
48/// `bsl::basic_string_view` and aliases for ordinary and wide character
49/// specializations `bsl::string_view` and `bsl::wstring_view` implementing
50/// standard containers, `std::string_view` and `std::wstring_view`, that can
51/// refer to a constant contiguous sequence of char-like objects with the first
52/// element of the sequence at position zero.
53///
54/// An instantiation of `basic_string_view` is a value-semantic type whose
55/// salient attribute is the sequence of characters it represents. The
56/// `basic_string_view` `class` is parameterized by the character type,
57/// `CHAR_TYPE` and that character type's traits, `CHAR_TRAITS`. The traits for
58/// each character type provide functions that assign, compare, and copy a
59/// sequence of those characters.
60///
61/// A `basic_string_view` meets the requirements of a sequential container with
62/// random access iterators as specified in the [basic.string_view] section of
63/// the C++ standard [24.4]. The `basic_string_view` implemented here adheres
64/// to the C++17 standard, except that it does not have template specializations
65/// `std::u16string_view` and `std::u32string_view`. Note that if compiler
66/// supports C++17 standard, then `stl` implementation of `basic_string_view` is
67/// used.
68///
69/// ## Lexicographical Comparisons {#bslstl_stringview-lexicographical-comparisons}
70///
71///
72/// Two `basic_string_view`s `lhs` and `rhs` are lexicographically compared by
73/// first determining `N`, the smaller of the lengths of `lhs` and `rhs`, and
74/// comparing characters at each position between 0 and `N - 1`, using
75/// `CHAR_TRAITS::compare` in lexicographical fashion. If
76/// `CHAR_TRAITS::compare` determines that string_views are non-equal (smaller
77/// or larger), then this is the result. Otherwise, the lengths of the
78/// string_views are compared and the shorter string_view is declared the
79/// smaller. Lexicographical comparison returns equality only when both
80/// string_views have the same length and the same character value in each
81/// respective position.
82///
83/// ## Operations {#bslstl_stringview-operations}
84///
85///
86/// This section describes the run-time complexity of operations on instances of
87/// `basic_string_view`:
88/// @code
89/// Legend
90/// ------
91/// 'V' - the 'CHAR_TYPE' template parameter type of the
92/// 'basic_string_view'
93/// 'a', 'b' - two distinct objects of type 'basic_string_view<V>'
94/// 'k' - an integral number
95/// 'p' - a pointer defining a sequence of 'CHAR_TYPE' characters
96///
97/// +----------------------------------------------+--------------------------+
98/// | Operation | Complexity |
99/// |==============================================+==========================|
100/// | basic_string_view<V> a (default construction)| O[1] |
101/// |----------------------------------------------+--------------------------|
102/// | basic_string_view<V> a(b) (copy construction)| O[1] |
103/// |----------------------------------------------+--------------------------|
104/// | basic_string_view<V> a(p) | O[n] |
105/// |----------------------------------------------+--------------------------|
106/// | basic_string_view<V> a(p, k) | O[1] |
107/// |----------------------------------------------+--------------------------|
108/// | a.~basic_string_view<V>() (destruction) | O[1] |
109/// |----------------------------------------------+--------------------------|
110/// | a.begin(), a.end(), | O[1] |
111/// | a.cbegin(), a.cend(), | |
112/// | a.rbegin(), a.rend(), | |
113/// | a.crbegin(), a.crend() | |
114/// |----------------------------------------------+--------------------------|
115/// | a.size() | O[1] |
116/// |----------------------------------------------+--------------------------|
117/// | a.max_size() | O[1] |
118/// |----------------------------------------------+--------------------------|
119/// | a.remove_prefix(k) | O[1] |
120/// | a.remove_suffix(k) | |
121/// |----------------------------------------------+--------------------------|
122/// | a[k] | O[1] |
123/// |----------------------------------------------+--------------------------|
124/// | a.at(k) | O[1] |
125/// |----------------------------------------------+--------------------------|
126/// | a.front() | O[1] |
127/// |----------------------------------------------+--------------------------|
128/// | a.back() | O[1] |
129/// |----------------------------------------------+--------------------------|
130/// | a.swap(b), swap(a, b) | O[1] |
131/// |----------------------------------------------+--------------------------|
132/// | a = b; (assignment) | O[1] |
133/// |----------------------------------------------+--------------------------|
134/// | a == b, a != b | O[n] |
135/// |----------------------------------------------+--------------------------|
136/// | a < b, a <= b, a > b, a >= b | O[n] |
137/// +----------------------------------------------+--------------------------+
138/// @endcode
139///
140/// ## User-defined literals {#bslstl_stringview-user-defined-literals}
141///
142///
143/// The user-defined literal operators are declared for the `bsl::string_view`
144/// and `bsl::wstring_view` types. The ud-suffix `_sv` is chosen to distinguish
145/// between the `bsl`-string_view's user-defined literal operators and the
146/// `std`-string_view's user-defined literal `operator ""sv` introduced in the
147/// C++14 standard and implemented in the standard library provided by the
148/// compiler vendor. Note that the `bsl`-string_view's `operator "" _sv`,
149/// unlike the `std`-string_view's `operator ""sv`, can be used in a client's
150/// code if the compiler supports the C++11 standard. Also note that if the
151/// compiler supports the C++17 standard then the `std`-string_view's
152/// `operator ""sv` can be used to initialize a `bsl`-string_view as follows:
153/// @code
154/// using namespace std::string_view_literals;
155/// bsl::string_view sv = "test"sv;
156/// @endcode
157///
158/// Also note that `bsl`-string_view's user-defined literal operators are
159/// declared in the `bsl::literals::string_view_literals` namespace, where
160/// `literals` and `string_view_literals` are inline namespaces. Access to
161/// these operators can be gained with either `using namespace bsl::literals`,
162/// `using namespace bsl::string_view_literals` or
163/// `using namespace bsl::literals::string_view_literals`. But we recommend
164/// `using namespace bsl::string_view_literals` to minimize the scope of the
165/// using declaration:
166/// @code
167/// using namespace bsl::string_view_literals;
168/// bsl::string_view svr = "test"_sv;
169/// @endcode
170///
171/// ## Usage {#bslstl_stringview-usage}
172///
173///
174/// In this section we show intended use of this component.
175///
176/// ### Example 1: Basic Syntax {#bslstl_stringview-example-1-basic-syntax}
177///
178///
179/// The `bsl::string_view` can be used as a lightweight replacement of the
180/// `bsl::string`, unless you need to modify the content. It takes up no more
181/// space and doesn't allocate memory:
182/// @code
183/// bslma::TestAllocator da("Default", veryVeryVeryVerbose);
184/// bslma::DefaultAllocatorGuard dag(&da);
185///
186/// bslma::TestAllocator sfa ("StringFootprint", veryVeryVeryVerbose);
187/// bslma::TestAllocator svfa("StringViewFootprint", veryVeryVeryVerbose);
188/// bslma::TestAllocator ssa ("StringSupplied", veryVeryVeryVerbose);
189///
190/// const char *LONG_STRING = "0123456789012345678901234567890123456789"
191/// "0123456789012345678901234567890123456789";
192///
193/// bsl::string *sPtr = new (sfa ) bsl::string(LONG_STRING, &ssa);
194/// bsl::string_view *svPtr = new (svfa) bsl::string_view(LONG_STRING);
195///
196/// assert(sfa.numBytesInUse() >= svfa.numBytesInUse());
197/// assert(0 < ssa.numBytesInUse());
198/// assert(0 == da.numBytesInUse());
199/// @endcode
200/// At the same time it supports all most used `access` operations of the
201/// `bsl::string`, using the same interfaces:
202/// @code
203/// const bsl::string& STR = *sPtr;
204/// const bsl::string_view& SV = *svPtr;
205///
206/// assert(STR.length() == SV.length());
207/// assert(STR.empty() == SV.empty());
208/// assert(STR.front() == SV.front());
209/// assert(STR.at(15) == SV.at(15));
210/// assert(STR.find("345") == SV.find("345"));
211/// assert(STR.find_last_not_of("578") == SV.find_last_not_of("578"));
212/// assert(STR.compare(0, 3, "012") == SV.compare(0, 3, "012"));
213/// @endcode
214/// However, using the `bsl::string_view`, you need to be especially attentive
215/// to the lifetime of the source character string, since the component
216/// explicitly refers to it:
217/// @code
218/// assert(LONG_STRING != STR.data());
219/// assert(LONG_STRING == SV.data());
220///
221/// sfa.deleteObject(sPtr);
222/// svfa.deleteObject(svPtr);
223/// @endcode
224/// @}
225/** @} */
226/** @} */
227
228/** @addtogroup bsl
229 * @{
230 */
231/** @addtogroup bslstl
232 * @{
233 */
234/** @addtogroup bslstl_stringview
235 * @{
236 */
237
238#include <bslscm_version.h>
239
240#include <bslstl_hash.h>
241#include <bslstl_iterator.h>
242#include <bslstl_stdexceptutil.h>
243
245
246#include <bslh_hash.h>
247
248#include <bslmf_addconst.h>
249#include <bslmf_addpointer.h>
250#include <bslmf_enableif.h>
251#include <bslmf_isconvertible.h>
254#include <bslmf_switch.h>
255
256#include <bsls_assert.h>
258#include <bsls_keyword.h>
259#include <bsls_libraryfeatures.h>
260#include <bsls_performancehint.h>
261#include <bsls_platform.h>
262
263#include <cstddef> // for 'std::size_t'
264#include <functional> // for 'std::less', 'std::greater_equal'
265#include <string> // for 'std::char_traits'
266
267#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
268# include <bsls_nativestd.h>
269#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
270
271#if defined(BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY) \
272&& !defined(BSLS_LIBRARYFEATURES_HAS_CPP20_BASELINE_LIBRARY)
273#define BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
274#endif
275
276// 'BDE_DISABLE_CPP17_ABI' is intended for CI builds only, to allow simulation
277// of Sun/AIX builds on Linux hosts. It is an error to define this symbol in
278// Bloomberg production builds.
279#ifndef BDE_DISABLE_CPP17_ABI
280# ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_BASELINE_LIBRARY
281
282# include <string_view>
283
284 namespace bsl {
285
286using std::basic_string_view;
287using std::string_view;
288using std::wstring_view;
289
290# if defined(BSLS_COMPILERFEATURES_SUPPORT_UTF8_CHAR_TYPE)
291using std::u8string_view;
292# endif
293
294using std::u16string_view;
295using std::u32string_view;
296
297using std::swap;
298
299using std::operator==;
300using std::operator!=;
301using std::operator<;
302using std::operator<=;
303using std::operator>;
304using std::operator>=;
305
306}
307# define BSLSTL_STRING_VIEW_IS_ALIASED
308# endif // BSLS_LIBRARYFEATURES_HAS_CPP20_BASELINE_LIBRARY
309#endif // BDE_DISABLE_CPP17_ABI
310
311#ifndef BSLSTL_STRING_VIEW_IS_ALIASED
312
313#if defined(BSLS_PLATFORM_OS_WINDOWS) || \
314 (defined(BSLS_PLATFORM_CMP_SUN) && BSLS_PLATFORM_CMP_VERSION < 0x5130) || \
315 (defined(BSLS_PLATFORM_CMP_SUN) && BSLS_PLATFORM_CMP_VERSION == 0x5150)
316 // Windows or Sun CC before version 5.12.4 or Sun CC version 5.12.6
317
318# define BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER 1
319#else
320# define BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER 0
321#endif
322
323
324namespace bslstl {
325
326 // ===========================
327 // struct 'StringView_Identity
328 // ===========================
329
330template <class TYPE>
332#if BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER
333 // See 'Implementation Notes' in the implementation .cpp file.
334
335 // TYPES
336 struct type {
337 // DATA
338 TYPE d_value;
339
340 // CREATOR
341
342 /// Initialize `d_value` from the specified `argument`, of the
343 /// specified `ARG_TYPE`, where `ARG_TYPE` can be any type that is
344 /// convertible to the specified `TYPE`.
345 template <class ARG_TYPE>
346 type(const ARG_TYPE& argument,
347 typename
349 int>::type = 0);
350
351 type(const type&) = default;
352
353 // MANIPULATORS
354
355 type& operator=(const type&) = default;
356
357 /// Assign the specified `rhs` of type `TYPE` to this object, and
358 /// return a reference providing modifiable access to the `TYPE`
359 /// object held by this object.
360 TYPE& operator=(const TYPE& rhs);
361
362 /// Return a reference providing modifiable access to the `TYPE`
363 /// object held by this object.
364 operator TYPE&();
365
366 // ACCESSOR
367
368 /// Return a const reference to the `TYPE` object held by this
369 /// object.
370 operator const TYPE&() const;
371 };
372#else
373 // TYPES
374 typedef TYPE type;
375#endif
376};
377
378} // close package namespace
379
380
381namespace bsl {
382
383 // ===========================================
384 // struct BasicStringView_IsCompatibleIterator
385 // ===========================================
386
387/// `value` is 1 if (template parameter) type `CONTG_ITER` is convertible to
388/// `const CHAR_TYPE *` (i.e., convertible to `d_start_p` of
389/// `basic_string_view`); otherwise, `value` is 0.
390template <class CHAR_TYPE, class CONTG_ITER>
392 CONTG_ITER,
393 typename bsl::add_pointer<
394 typename bsl::add_const<CHAR_TYPE>::type
395 >::type>
396{
397};
398
399 // ===========================================
400 // struct BasicStringView_IsCompatibleSentinel
401 // ===========================================
402
403/// `value` is 1 if (template parameter) type `SENTINEL> is *not*
404/// convertible to `size_type`, and 0 otherwise.
405template <class SENTINEL>
408 ! bsl::is_convertible<SENTINEL, std::size_t>::value>
409{
410};
411
412// Import @ref char_traits into the 'bsl' namespace so that 'basic_string_view'
413// and @ref char_traits are always in the same namespace.
414
415using std::char_traits;
416
417 // =======================
418 // class basic_string_view
419 // =======================
420
421/// This class template provides an STL-compliant @ref string_view . This
422/// implementation offers strong exception guarantees (see below), with the
423/// general rule that any method that attempts to access a position outside
424/// the valid range of a string_view throws `std::out_of_range`.
425///
426/// Note that the search methods, such as `find`, `rfind`, etc, do *not*
427/// actually access invalid positions, so they do *not* throw exceptions.
428///
429/// More generally, this class supports an almost complete set of *in-core*
430/// *value* *semantic* operations, including copy construction, assignment,
431/// equality comparison (but excluding `ostream` printing since this
432/// component is below STL). A precise operational definition of when two
433/// objects have the same value can be found in the description of
434/// `operator==` for the class. This class is *exception* *neutral* with
435/// full guarantee of rollback: if an exception is thrown during the
436/// invocation of a method on a pre-existing object, the object is left
437/// unchanged. In no event is memory leaked.
438///
439/// See @ref bslstl_stringview
440template <class CHAR_TYPE, class CHAR_TRAITS = char_traits<CHAR_TYPE> >
442
443 public:
444 // TYPES
445 typedef CHAR_TRAITS traits_type;
446 typedef CHAR_TYPE value_type;
448 typedef const value_type *const_pointer;
453
454 typedef bsl::reverse_iterator<iterator> reverse_iterator;
455 typedef bsl::reverse_iterator<const_iterator> const_reverse_iterator;
456
457 typedef std::size_t size_type;
458 typedef std::ptrdiff_t difference_type;
459
460 public:
461 // CLASS DATA
462
463 /// Value used to denote "not-a-position", guaranteed to be outside the
464 /// range `[0 .. max_size()]`.
465 static const size_type npos = ~size_type(0);
466
467 private:
468 // DATA
469 const CHAR_TYPE *d_start_p; // pointer to the data
470 size_type d_length; // length of the view
471
472 // PRIVATE ACCESSORS
473
474 /// Lexicographically compare the substring of this string starting at
475 /// the specified `lhsPosition` of length `lhsNumChars` with the
476 /// specified initial `otherNumChars` characters in the specified
477 /// `other` string, and return a negative value if the indicated
478 /// substring of this string is less than `other`, a positive value if
479 /// it is greater than `other`, and 0 in case of equality. The behavior
480 /// is undefined unless `lhsPosition <= length()`,
481 /// `lhsNumChars <= length()`, and
482 /// `lhsPosition <= length() - lhsNumChars`.
484 int privateCompareRaw(size_type lhsPosition,
485 size_type lhsNumChars,
486 const CHAR_TYPE *other,
487 size_type otherNumChars) const;
488
489 public:
490 // TRAITS
493
494 // CREATORS
495
496 /// Create an empty view.
499
500 /// Create a view that has the same value as the specified `original`
501 /// object.
502 basic_string_view(const basic_string_view& original) = default;
503
504 /// Create a view of the specified null-terminated `characterString` (of
505 /// length `CHAR_TRAITS::length(characterString)`).
507 basic_string_view(const CHAR_TYPE *characterString); // IMPLICIT
508
509 /// Create a view that has the same value as the subview of the
510 /// optionally specified `numChars` length starting at the beginning of
511 /// the specified `characterString`. The behavior is undefined unless
512 /// `characterString || (numChars == 0)` and `numChars <= max_size()`.
514 basic_string_view(const CHAR_TYPE *characterString,
515 size_type numChars);
516
517 /// Create a view from of characters in the range starting at the
518 /// specified `first`, a contiguous iterator, to the position
519 /// immediately before the specified `end`, a sentinel type. The
520 /// behavior is undefined unless:
521 /// * `[first, last)` is a contiguous valid range,
522 /// *o if `first` is 0, then `0 == last - first`, and
523 /// *o the `SENTINEL` type is *not* convertible to `std::size_t`.
524 /// Note that contiguous iterator types also provide random access.
525 /// Also note that pointers to `CHAR_TYPE` can be used as iterator and
526 /// sentinel types.
527 template <class CONTG_ITER, class SENTINEL>
529 basic_string_view(CONTG_ITER first,
530 SENTINEL last,
531 typename
532 bsl::enable_if<
534 CONTG_ITER>::value
535 && BasicStringView_IsCompatibleSentinel<SENTINEL >::value
536 >::type * = 0);
537
538 /// Create a view of the specified `string`.
539 template <class ALLOCATOR>
541 const std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& str);
542 // IMPLICIT
543
544#ifdef BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
545 /// Create a view identical to the specified `view`.
548 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& view);
549 // IMPLICIT
550
551#endif // BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
552
553 /// Destroy this object.
555
556 // MANIPULATORS
557
558 /// Assign to this view the value of the specified `rhs` object, and
559 /// return a reference providing modifiable access to this view.
561
562 /// Assign to this view the value of the specified `rhs` object, and
563 /// return a reference providing modifiable access to this view.
564 template <class ALLOCATOR>
567 const std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& rhs)
569
570 /// Move the start of this view forward by the specified `numChars`.
571 /// The behavior is undefined unless `numChars <= length()`.
573 void remove_prefix(size_type numChars);
574
575 /// Move the end of this view back by the specified `numChars`. The
576 /// behavior is undefined unless `numChars <= length()`.
578 void remove_suffix(size_type numChars);
579
580 /// Exchange the value of this view with the value of the specified
581 /// `other` object.
583
584 // ACCESSORS
585
586 // *** iterator support ***
587
588 /// Return an iterator providing non-modifiable access to the first
589 /// character of this view (or the past-the-end iterator if this view is
590 /// empty).
595
596 /// Return the past-the-end iterator for this view.
601
602 /// Return a reverse iterator providing non-modifiable access to the
603 /// last character of this view (or the past-the-end reverse iterator if
604 /// this view is empty).
609
610 /// Return the past-the-end reverse iterator for this view.
615
616 // *** capacity ***
617
618 /// Return the length of this view.
621
622 /// Return the length of this view.
625
626 /// Return the maximal possible length of this view. Note that requests
627 /// to create a view longer than this number of characters are
628 /// guaranteed to raise an `std::length_error` exception.
631
632 /// Return `true` if this view has length 0, and `false` otherwise.
634 bool empty() const BSLS_KEYWORD_NOEXCEPT;
635
636 // *** element access ***
637
638 /// Return a reference providing non-modifiable access to the character
639 /// at the specified `position` in this view. The behavior is undefined
640 /// unless `position < length()`.
642 const_reference operator[](size_type position) const;
643
644 /// Return a reference providing non-modifiable access to the character
645 /// at the specified `position` in this view. Throw `std::out_of_range`
646 /// if `position >= length()`.
648 const_reference at(size_type position) const;
649
650 /// Return a reference providing non-modifiable access to the character
651 /// at the first position in this view. The behavior is undefined if
652 /// this view is empty.
654 const_reference front() const;
655
656 /// Return a reference providing non-modifiable access to the character
657 /// at the last position in this view. The behavior is undefined if
658 /// this view is empty. Note that the last position is `length() - 1`.
660 const_reference back() const;
661
662 /// Return an address providing non-modifiable access to the underlying
663 /// character array. Note that this array may be not null-terminated.
666
667 // *** string operations ***
668
669 /// Copy from this view, starting from the optionally specified
670 /// `position`, the specified `numChars` or `length() - position`
671 /// characters, whichever is smaller, into the specified
672 /// `characterString` buffer, and return the number of characters
673 /// copied. If `position` is not specified, 0 is used. Throw
674 /// `std::out_of_range` if `position > length()`. Note that the output
675 /// `characterString` is *not* null-terminated. The behavior is
676 /// undefined unless `characterString` has enough room to hold at least
677 /// `numChars` or `length() - position`, whichever is smaller, and the
678 /// `characterString` does not lie within the source range to be copied.
679 size_type copy(CHAR_TYPE *characterString,
680 size_type numChars,
681 size_type position = 0) const;
682
683 /// Return a view whose value is the subview starting at the optionally
684 /// specified `position` in this view, of length the optionally
685 /// specified `numChars` or `length() - position`, whichever is smaller.
686 /// If `position` is not specified, 0 is used (i.e., the subview is from
687 /// the beginning of this view). If `numChars` is not specified, `npos`
688 /// is used (i.e., the entire suffix from `position` to the end of the
689 /// view is returned). Throw `std::out_of_range` if
690 /// `position > length()`.
693 size_type numChars = npos) const;
694
695 /// Lexicographically compare this view with the specified `other` view,
696 /// and return a negative value if this view is less than `other`, a
697 /// positive value if it is greater than `other`, and 0 in case of
698 /// equality. See {Lexicographical Comparisons}.
701
702 /// Lexicographically compare the subview of this view of the specified
703 /// `numChars` length starting at the specified `position` (or the
704 /// suffix of this view starting at `position` if
705 /// `position + numChars > length()`) with the specified `other` view,
706 /// and return a negative value if the indicated subview of this view is
707 /// less than `other`, a positive value if it is greater than `other`,
708 /// and 0 in case of equality. Throw `std::out_of_range` if
709 /// `position > length()`. See {Lexicographical Comparisons}.
711 int compare(size_type position,
712 size_type numChars,
713 basic_string_view other) const;
714
715 /// Lexicographically compare the subview of this view of the specified
716 /// `lhsNumChars` length starting at the specified `lhsPosition` (or the
717 /// suffix of this view starting at `lhsPosition` if
718 /// `lhsPosition + lhsNumChars > length()`) with the subview of the
719 /// specified `other` view of the specified `otherNumChars` length
720 /// starting at the specified `otherPosition` (or the suffix of `other`
721 /// starting at `otherPosition` if
722 /// `otherPosition + otherNumChars > other.length()`). Return a
723 /// negative value if the indicated subview of this view is less than
724 /// the indicated subview of `other`, a positive value if it is greater
725 /// than the indicated subview of `other`, and 0 in case of equality.
726 /// Throw `std::out_of_range` if `lhsPosition > length()` or
727 /// `otherPosition > other.length()`. See {Lexicographical
728 /// Comparisons}.
730 int compare(size_type lhsPosition,
731 size_type lhsNumChars,
732 basic_string_view other,
733 size_type otherPosition,
734 size_type otherNumChars) const;
735
736 /// Lexicographically compare this view with the specified
737 /// null-terminated `other` string (of length
738 /// `CHAR_TRAITS::length(other)`), and return a negative value if this
739 /// view is less than `other`, a positive value if it is greater than
740 /// `other`, and 0 in case of equality. The behavior is undefined
741 /// unless `other` is a null-terminated string.
743 int compare(const CHAR_TYPE *other) const;
744
745 /// Lexicographically compare the subview of this view of the specified
746 /// `lhsNumChars` length starting at the specified `lhsPosition` (or the
747 /// suffix of this view starting at `lhsPosition` if
748 /// `lhsPosition + lhsNumChars > length()`) with the specified
749 /// null-terminated `other` string (of length
750 /// `CHAR_TRAITS::length(other)`), and return a negative value if the
751 /// indicated subview of this view is less than `other`, a positive
752 /// value if it is greater than `other`, and 0 in case of equality.
753 /// Throw `std::out_of_range` if `lhsPosition > length()`.
755 int compare(size_type lhsPosition,
756 size_type lhsNumChars,
757 const CHAR_TYPE *other) const;
758
759 /// Lexicographically compare the subview of this view of the specified
760 /// `lhsNumChars` length starting at the specified `lhsPosition` (or the
761 /// suffix of this view starting at `lhsPosition` if
762 /// `lhsPosition + lhsNumChars > length()`) with the specified `other`
763 /// string of the specified `otherNumChars` length, and return a
764 /// negative value if the indicated subview of this view is less than
765 /// `other`, a positive value if it is greater than `other`, and 0 in
766 /// case of equality. `CHAR_TRAITS::lt` is used to compare characters.
767 /// Throw `std::out_of_range` if `lhsPosition > length()`. The behavior
768 /// is undefined unless `other || 0 == otherNumChars`.
770 int compare(size_type lhsPosition,
771 size_type lhsNumChars,
772 const CHAR_TYPE *other,
773 size_type otherNumChars) const;
774
775 /// Return `true` if this view starts with the specified `subview`, and
776 /// `false` otherwise. See {Lexicographical Comparisons}.
779
780 /// Return `true` if this view starts with the specified `character`,
781 /// and `false` otherwise.
783 bool starts_with(CHAR_TYPE character) const BSLS_KEYWORD_NOEXCEPT;
784
785 /// Return `true` if this view starts with the specified
786 /// `characterString`, and `false` otherwise.
788 bool starts_with(const CHAR_TYPE* characterString) const;
789
790 /// Return `true` if this view ends with the specified `subview`, and
791 /// `false` otherwise. See {Lexicographical Comparisons}.
794
795 // Return `true` if this view ends with the specified `character`, and
796 // `false` otherwise.
798 bool ends_with(CHAR_TYPE character) const BSLS_KEYWORD_NOEXCEPT;
799
800 /// Return `true` if this view ends with the specified
801 /// `characterString`, and `false` otherwise.
803 bool ends_with(const CHAR_TYPE* characterString) const;
804
805 /// Return the starting position of the *first* occurrence of the
806 /// specified `subview`, if it can be found in this view (on or *after*
807 /// the optionally specified `position`) using `CHAR_TRAITS::eq` to
808 /// compare characters, and return `npos` otherwise.
810 size_type find(basic_string_view subview,
811 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
812
813 /// Return the starting position of the *first* occurrence of the
814 /// specified `characterString` of the specified `numChars` length, if
815 /// such a string can be found in this view (on or *after* the specified
816 /// `position`) using `CHAR_TRAITS::eq` to compare characters, and
817 /// return `npos` otherwise. The behavior is undefined unless
818 /// `characterString || (numChars == 0)`.
820 size_type find(const CHAR_TYPE *characterString,
821 size_type position,
822 size_type numChars) const;
823
824 /// Return the starting position of the *first* occurrence of the
825 /// specified null-terminated `characterString`, if such a string can be
826 /// found in this view (on or *after* the optionally specified
827 /// `position`) using `CHAR_TRAITS::eq` to compare characters, and
828 /// return `npos` otherwise.
830 size_type find(const CHAR_TYPE *characterString,
831 size_type position = 0) const;
832
833 /// Return the position of the *first* occurrence of the specified
834 /// `character`, if such an occurrence can be found in this view (on or
835 /// *after* the optionally specified `position` if such a `position` is
836 /// specified), and return `npos` otherwise.
838 size_type find(CHAR_TYPE character,
839 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
840
841 /// Return the starting position of the *last* occurrence of the
842 /// specified `subview` within this view, if such a sequence can be
843 /// found in this view (on or *before* the optionally specified
844 /// `position` if such a `position` is specified) using
845 /// `CHAR_TRAITS::eq` to compare characters, and return `npos`
846 /// otherwise.
849 basic_string_view subview,
850 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
851
852 /// Return the starting position of the *last* occurrence of the
853 /// specified `characterString` of the specified `numChars` length, if
854 /// such a string can be found in this view (on or *after* the specified
855 /// `position`) using `CHAR_TRAITS::eq` to compare characters, and
856 /// return `npos` otherwise. The behavior is undefined unless
857 /// `characterString || (numChars == 0)`.
859 size_type rfind(const CHAR_TYPE *characterString,
860 size_type position,
861 size_type numChars) const;
862
863 /// Return the starting position of the *last* occurrence of the
864 /// specified null-terminated `characterString`, if such a string can be
865 /// found in this view (on or *after* the optionally specified
866 /// `position`) using `CHAR_TRAITS::eq` to compare characters, and
867 /// return `npos` otherwise.
869 size_type rfind(const CHAR_TYPE *characterString,
870 size_type position = npos) const;
871
872 /// Return the position of the *last* occurrence of the specified
873 /// `character`, if such an occurrence can be found in this view (on or
874 /// *before* the optionally specified `position` if such a `position` is
875 /// specified), and return `npos` otherwise.
877 size_type rfind(CHAR_TYPE character,
878 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
879
880 /// Return the position of the *first* occurrence of a character
881 /// belonging to the specified `subview`, if such an occurrence can be
882 /// found in this view (on or *after* the optionally specified
883 /// `position` if such a `position` is specified), and return `npos`
884 /// otherwise.
886 size_type find_first_of(
887 basic_string_view subview,
888 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
889
890 /// Return the position of the *first* occurrence of a character
891 /// belonging to the specified `characterString` of the specified
892 /// `numChars` length, if such a string can be found in this view (on or
893 /// *after* the specified `position`) using `CHAR_TRAITS::eq` to compare
894 /// characters, and return `npos` otherwise. The behavior is undefined
895 /// unless `characterString || (numChars == 0)`.
897 size_type find_first_of(const CHAR_TYPE *characterString,
898 size_type position,
899 size_type numChars) const;
900
901 /// Return the position of the *first* occurrence of a character
902 /// belonging to the specified `characterString`, if such an occurrence
903 /// can be found in this view (on or *after* the optionally specified
904 /// `position`), and return `npos` otherwise.
906 size_type find_first_of(const CHAR_TYPE *characterString,
907 size_type position = 0) const;
908
909 /// Return the position of the *first* occurrence of the specified
910 /// `character`, if such an occurrence can be found in this view (on or
911 /// *after* the optionally specified `position` if such a `position` is
912 /// specified), and return `npos` otherwise.
914 size_type find_first_of(
915 CHAR_TYPE character,
916 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
917
918 /// Return the position of the *last* occurrence of a character
919 /// belonging to the specified `subview`, if such an occurrence can be
920 /// found in this view (on or *before* the optionally specified
921 /// `position` if such a `position` is specified), and return `npos`
922 /// otherwise.
925 basic_string_view subview,
926 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
927
928 /// Return the position of the *last* occurrence of a character
929 /// belonging to the specified `characterString` of the specified
930 /// `numChars` length, if such a string can be found in this view (on or
931 /// *after* the specified `position`) using `CHAR_TRAITS::eq` to compare
932 /// characters, and return `npos` otherwise. The behavior is undefined
933 /// unless `characterString || (numChars == 0)`.
935 size_type find_last_of(const CHAR_TYPE *characterString,
936 size_type position,
937 size_type numChars) const;
938
939 /// Return the position of the *last* occurrence of a character
940 /// belonging to the specified `characterString`, if such an occurrence
941 /// can be found in this view (on or *after* the optionally specified
942 /// `position`), and return `npos` otherwise.
944 size_type find_last_of(const CHAR_TYPE *characterString,
945 size_type position = npos) const;
946
947 /// Return the position of the *last* occurrence of the specified
948 /// `character`, if such an occurrence can be found in this view (on or
949 /// *before* the optionally specified `position` if such a `position` is
950 /// specified), and return `npos` otherwise.
953 CHAR_TYPE character,
954 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
955
956 /// Return the position of the *first* occurrence of a character *not*
957 /// belonging to the specified `subview`, if such an occurrence can be
958 /// found in this view (on or *after* the optionally specified
959 /// `position` if such a `position` is specified), and return `npos`
960 /// otherwise.
963 basic_string_view subview,
964 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
965
966 /// Return the position of the *first* occurrence of a character *not*
967 /// belonging to the specified `characterString` of the specified
968 /// `numChars` length, if such an occurrence can be found in this view
969 /// (on or *after* the specified `position`) using `CHAR_TRAITS::eq` to
970 /// compare characters, and return `npos` otherwise. The behavior is
971 /// undefined unless `characterString || (numChars == 0)`.
973 size_type find_first_not_of(const CHAR_TYPE *characterString,
974 size_type position,
975 size_type numChars) const;
976
977 /// Return the position of the *first* occurrence of a character *not*
978 /// belonging to the specified `characterString`, if such an occurrence
979 /// can be found in this view (on or *after* the optionally specified
980 /// `position`), and return `npos` otherwise.
982 size_type find_first_not_of(const CHAR_TYPE *characterString,
983 size_type position = 0) const;
984
985 /// Return the position of the *first* occurrence of a character
986 /// *different* from the specified `character`, if such an occurrence
987 /// can be found in this view (on or *after* the optionally specified
988 /// `position` if such a `position` is specified), and return `npos`
989 /// otherwise.
992 CHAR_TYPE character,
993 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
994
995 /// Return the position of the *last* occurrence of a character *not*
996 /// belonging to the specified `subview`, if such an occurrence can be
997 /// found in this view (on or *before* the optionally specified
998 /// `position` if such a `position` is specified), and return `npos`
999 /// otherwise.
1002 basic_string_view subview,
1003 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
1004
1005 /// Return the position of the *last* occurrence of a character *not*
1006 /// belonging to the specified `characterString` of the specified
1007 /// `numChars` length, if such an occurrence can be found in this view
1008 /// (on or *after* the specified `position`) using `CHAR_TRAITS::eq` to
1009 /// compare characters, and return `npos` otherwise. The behavior is
1010 /// undefined unless `characterString || (numChars == 0)`.
1012 size_type find_last_not_of(const CHAR_TYPE *characterString,
1013 size_type position,
1014 size_type numChars) const;
1015
1016 /// Return the position of the *last* occurrence of a character *not*
1017 /// belonging to the specified `characterString`, if such an occurrence
1018 /// can be found in this view (on or *after* the optionally specified
1019 /// `position`), and return `npos` otherwise.
1021 size_type find_last_not_of(const CHAR_TYPE *characterString,
1022 size_type position = npos) const;
1023
1024 /// Return the position of the *last* occurrence of a character
1025 /// *different* from the specified `character`, if such an occurrence
1026 /// can be found in this view (on or *before* the optionally specified
1027 /// `position` if such a `position` is specified), and return `npos`
1028 /// otherwise.
1031 CHAR_TYPE character,
1032 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
1033
1034 // *** BDE compatibility with platform libraries: ***
1035
1036 /// Convert this `const` object to a string type native to the
1037 /// compiler`s library, instantiated with the same character type and
1038 /// traits type. The return string will contain the same sequence of
1039 /// characters as this object and will have a default-constructed
1040 /// allocator.
1041 template <class ALLOCATOR>
1043 operator std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>()
1044 const
1045 {
1046 // See {DRQS 131792157} for why this is inline.
1047 return std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>(d_start_p,
1048 d_length);
1049 }
1050};
1051
1052// TYPEDEFS
1055
1056#if defined(BSLS_COMPILERFEATURES_SUPPORT_UTF8_CHAR_TYPE)
1057typedef basic_string_view<char8_t> u8string_view;
1058#endif
1059
1060#if defined(BSLS_COMPILERFEATURES_SUPPORT_UNICODE_CHAR_TYPES)
1061typedef basic_string_view<char16_t> u16string_view;
1062typedef basic_string_view<char32_t> u32string_view;
1063#endif
1064
1065// FREE FUNCTIONS
1066
1067/// Exchange the value of the specified `a` object with the value of the
1068/// specified `b` object.
1069template <class CHAR_TYPE, class CHAR_TRAITS>
1072
1073} // close namespace bsl
1074
1075
1077
1078 // =============================
1079 // struct StringView_CompareUtil
1080 // =============================
1081
1082/// This component-private utility `struct` contains functions for comparing
1083/// two @ref string_view objects. This functionality is needed to implement
1084/// the comparison operators operating on string_view objects without
1085/// resorting to code duplication or delegating directly between different
1086/// overloads of the same operator. The need to avoid delegation to
1087/// overloads stems from a bug in xlC 12 on AIX leading to incorrect
1088/// overload resolution and infinite recursion.
1089template <class CHAR_TYPE, class CHAR_TRAITS>
1091
1092 // TYPES
1094
1095 // CLASS METHODS
1096
1097 /// Return `true` if `lhs == rhs` and `false` otherwise.
1098 static
1101
1102 /// Return `true` if `lhs < rhs` and `false` otherwise.
1103 static
1106};
1107
1108// FREE OPERATORS
1109
1110/// Return `true` if the specified `lhs` view has the same value as the
1111/// specified `rhs` view, and `false` otherwise. Two views have the same
1112/// value if they have the same length, and the characters at each
1113/// respective position have the same value according to `CHAR_TRAITS::eq`.
1114template <class CHAR_TYPE, class CHAR_TRAITS>
1119template <class CHAR_TYPE, class CHAR_TRAITS>
1121bool operator==(
1122 typename BloombergLP::bslstl::StringView_Identity<
1126template <class CHAR_TYPE, class CHAR_TRAITS>
1128bool operator==(
1130 typename BloombergLP::bslstl::StringView_Identity<
1133
1134/// Return `true` if the specified `lhs` view has a different value from the
1135/// specified `rhs` view, and `false` otherwise. Two views have the same
1136/// value if they have the same length, and the characters at each
1137/// respective position have the same value according to `CHAR_TRAITS::eq`.
1138template <class CHAR_TYPE, class CHAR_TRAITS>
1143template <class CHAR_TYPE, class CHAR_TRAITS>
1145bool operator!=(
1146 typename BloombergLP::bslstl::StringView_Identity<
1150template <class CHAR_TYPE, class CHAR_TRAITS>
1152bool operator!=(
1154 typename BloombergLP::bslstl::StringView_Identity<
1157
1158/// Return `true` if the specified `lhs` view has a lexicographically
1159/// smaller value than the specified `rhs` view, and `false` otherwise. See
1160/// {Lexicographical Comparisons}.
1161template <class CHAR_TYPE, class CHAR_TRAITS>
1166template <class CHAR_TYPE, class CHAR_TRAITS>
1168bool operator<(
1169 typename BloombergLP::bslstl::StringView_Identity<
1173template <class CHAR_TYPE, class CHAR_TRAITS>
1175bool operator<(
1177 typename BloombergLP::bslstl::StringView_Identity<
1180
1181/// Return `true` if the specified `lhs` view has a lexicographically larger
1182/// value than the specified `rhs` view, and `false` otherwise. See
1183/// {Lexicographical Comparisons}.
1184template <class CHAR_TYPE, class CHAR_TRAITS>
1189template <class CHAR_TYPE, class CHAR_TRAITS>
1191bool operator>(
1192 typename BloombergLP::bslstl::StringView_Identity<
1196template <class CHAR_TYPE, class CHAR_TRAITS>
1198bool operator>(
1200 typename BloombergLP::bslstl::StringView_Identity<
1203
1204/// Return `true` if the specified `lhs` view has a value lexicographically
1205/// smaller than or or equal to the specified `rhs` view, and `false`
1206/// otherwise. See {Lexicographical Comparisons}.
1207template <class CHAR_TYPE, class CHAR_TRAITS>
1212template <class CHAR_TYPE, class CHAR_TRAITS>
1214bool operator<=(
1215 typename BloombergLP::bslstl::StringView_Identity<
1219template <class CHAR_TYPE, class CHAR_TRAITS>
1221bool operator<=(
1223 typename BloombergLP::bslstl::StringView_Identity<
1226
1227/// Return `true` if the specified `lhs` view has a value lexicographically
1228/// larger than or equal to the specified `rhs` view, and `false` otherwise.
1229/// See {Lexicographical Comparisons}.
1230template <class CHAR_TYPE, class CHAR_TRAITS>
1235template <class CHAR_TYPE, class CHAR_TRAITS>
1237bool operator>=(
1238 typename BloombergLP::bslstl::StringView_Identity<
1242template <class CHAR_TYPE, class CHAR_TRAITS>
1244bool operator>=(
1246 typename BloombergLP::bslstl::StringView_Identity<
1249
1250} // close namespace bslstl_stringview_relops
1251
1252
1253namespace bsl {
1254
1255/// Write the value of the string bound to the specified `stringView` to the
1256/// specified output `stream` and return a reference to the modifiable
1257/// `stream`.
1258template <class CHAR_TYPE, class CHAR_TRAITS>
1259std::basic_ostream<CHAR_TYPE>&
1260operator<<(std::basic_ostream<CHAR_TYPE>& stream,
1261 basic_string_view<CHAR_TYPE, CHAR_TRAITS> stringView);
1262
1263// HASH SPECIALIZATIONS
1264
1265/// Pass the specified `input` string to the specified `hashAlg` hashing
1266/// algorithm of the (template parameter) type `HASHALG`.
1267template <class HASHALG, class CHAR_TYPE, class CHAR_TRAITS>
1268void hashAppend(HASHALG& hashAlg,
1270
1271/// Specialize `bsl::hash` for strings, including an overload for pointers
1272/// to allow character arrays to be hashed without converting them first.
1273template <class CHAR_TYPE, class CHAR_TRAITS>
1274struct hash<basic_string_view<CHAR_TYPE, CHAR_TRAITS> >
1275 : ::BloombergLP::bslh::Hash<>
1276{
1277 // PUBLIC ACCESSORS
1278
1279 /// Compute and return the hash value of the specified `input`.
1280 std::size_t operator()(
1282
1283 /// Compute and return the hash value of the contents of the specified
1284 /// null-terminated `input`. This value will be the same as the hash
1285 /// value of a `basic_string_view` constructed from `input`.
1286 std::size_t operator()(const CHAR_TYPE *input) const;
1287};
1288
1289#if defined(BSLS_PLATFORM_CMP_SUN) // {DRQS 132030795}
1290
1291// Sun CC 12.3 has trouble with the partial specializations above in certain
1292// circumstances (see {DRQS 132030795}). Adding these explicit specializations
1293// for @ref string_view and @ref wstring_view makes the problematic cases work.
1294
1295template <>
1296struct hash<string_view> : ::BloombergLP::bslh::Hash<>
1297{
1298 // PUBLIC ACCESSORS
1299
1300 /// Compute and return the hash value of the specified `input`.
1301 std::size_t operator()(const string_view& input) const;
1302
1303 /// Compute and return the hash value of the contents of the specified
1304 /// null-terminated `input`. This value will be the same as the hash
1305 /// value of a `basic_string_view` constructed from `input`.
1306 std::size_t operator()(const char *input) const;
1307};
1308
1309template <>
1310struct hash<wstring_view> : ::BloombergLP::bslh::Hash<>
1311{
1312 // PUBLIC ACCESSORS
1313
1314 /// Compute and return the hash value of the specified `input`.
1315 std::size_t operator()(const wstring_view& input) const;
1316
1317 /// Compute and return the hash value of the contents of the specified
1318 /// null-terminated `input`. This value will be the same as the hash
1319 /// value of a `basic_string_view` constructed from `input`.
1320 std::size_t operator()(const wchar_t *input) const;
1321};
1322
1323#endif // defined(BSLS_PLATFORM_CMP_SUN)
1324
1325} // close namespace bsl
1326
1327#endif // BSLSTL_STRING_VIEW_IS_ALIASED
1328
1329#if defined (BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY) && \
1330 defined (BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE)
1331namespace bsl {
1332inline namespace literals {
1333inline namespace string_view_literals {
1334
1335// FREE OPERATORS
1336
1337/// Convert a character sequence of the specified `length` excluding the
1338/// terminating null character starting at the beginning of the specified
1339/// `characterString` to a string_view object of the indicated return type.
1340/// (See the "User-Defined Literals" section in the component-level
1341/// documentation.)
1342///
1343/// Example:
1344/// @code
1345/// using namespace bsl::string_view_literals;
1346/// bsl::string_view sv1 = "123\0abc";
1347/// bsl::string_view sv2 = "123\0abc"_sv;
1348/// assert(3 == sv1.size());
1349/// assert(7 == sv2.size());
1350///
1351/// bsl::wstring_view sv3 = L"123\0abc"_sv;
1352/// assert(7 == sv3.size());
1353/// @endcode
1354 string_view operator ""_sv(const char *characterString,
1355 std::size_t length);
1356wstring_view operator ""_sv(const wchar_t *characterString,
1357 std::size_t length);
1358
1359} // close namespace string_view_literals
1360} // close namespace literals
1361} // close namespace bsl
1362#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY &&
1363 // BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE
1364
1365#ifdef BSLSTL_STRING_VIEW_IS_ALIASED
1366
1367namespace bslh {
1368
1369/// Pass the specified `input` string to the specified `hashAlg` hashing
1370/// algorithm of the (template parameter) type `HASHALG`. Note that this
1371/// function violates the BDE coding standard, adding a function for a
1372/// namespace for a different package, and none of the function parameters
1373/// are from this package either. This is necessary in order to provide an
1374/// implementation of `bslh::hashAppend` for the (native) standard library
1375/// @ref string_view type as we are not allowed to add overloads directly into
1376/// namespace `std`, and this component essentially provides the interface
1377/// between `bsl` and `std` string types.
1378template <class HASHALG, class CHAR_TYPE, class CHAR_TRAITS>
1380void hashAppend(HASHALG& hashAlg,
1381 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& input);
1382
1383} // close namespace bslh
1384
1385#endif // BSLSTL_STRING_VIEW_IS_ALIASED
1386
1387// ============================================================================
1388// INLINE FUNCTION DEFINITIONS
1389// ============================================================================
1390
1391#ifndef BSLSTL_STRING_VIEW_IS_ALIASED
1392
1393#if BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER
1394
1395
1396namespace bslstl {
1397
1398template <class TYPE>
1399template <class ARG_TYPE>
1400inline
1401StringView_Identity<TYPE>::type::type(
1402 const ARG_TYPE& argument,
1404 int>::type)
1405: d_value(argument)
1406{}
1407
1408// MANIPULATORS
1409template <class TYPE>
1410inline
1411TYPE& StringView_Identity<TYPE>::type::operator=(const TYPE& rhs)
1412{
1413 d_value = rhs;
1414
1415 return d_value;
1416}
1417
1418template <class TYPE>
1419inline
1420StringView_Identity<TYPE>::type::operator TYPE&()
1421{
1422 return d_value;
1423}
1424
1425// ACCESSOR
1426template <class TYPE>
1427inline
1428StringView_Identity<TYPE>::type::operator const TYPE&() const
1429{
1430 return d_value;
1431}
1432
1433} // close package namespace
1434
1435
1436#endif
1437
1438namespace bsl {
1439
1440 // -----------------------
1441 // class basic_string_view
1442 // -----------------------
1443
1444// CLASS DATA
1445template <class CHAR_TYPE, class CHAR_TRAITS>
1448
1449// PRIVATE ACCESSORS
1450template <class CHAR_TYPE, class CHAR_TRAITS>
1452int basic_string_view<CHAR_TYPE,CHAR_TRAITS>::privateCompareRaw(
1453 size_type lhsPosition,
1454 size_type lhsNumChars,
1455 const CHAR_TYPE *other,
1456 size_type otherNumChars) const
1457{
1458 BSLS_ASSERT_SAFE(lhsPosition <= length());
1459
1460 size_type numChars = lhsNumChars < otherNumChars ? lhsNumChars
1461 : otherNumChars;
1462 int cmpResult = CHAR_TRAITS::compare(data() + lhsPosition,
1463 other,
1464 numChars);
1465 if (cmpResult) {
1466 return cmpResult; // RETURN
1467 }
1468 if (lhsNumChars < otherNumChars) {
1469 return -1; // RETURN
1470 }
1471 if (lhsNumChars > otherNumChars) {
1472 return 1; // RETURN
1473 }
1474 return 0;
1475}
1476
1477// CREATORS
1478template <class CHAR_TYPE, class CHAR_TRAITS>
1479inline
1486
1487template <class CHAR_TYPE, class CHAR_TRAITS>
1491 const CHAR_TYPE *characterString)
1492: d_start_p(characterString)
1493, d_length(characterString ? CHAR_TRAITS::length(characterString) : 0)
1494{
1495 BSLS_ASSERT_SAFE(characterString);
1496 BSLS_ASSERT_SAFE(d_length <= max_size());
1497}
1498
1499template <class CHAR_TYPE, class CHAR_TRAITS>
1503 const CHAR_TYPE *characterString,
1504 size_type numChars)
1505: d_start_p(characterString)
1506, d_length(numChars)
1507{
1508 BSLS_ASSERT_SAFE(characterString || (numChars == 0));
1509 BSLS_ASSERT_SAFE(numChars <= max_size());
1510}
1511
1512template <class CHAR_TYPE, class CHAR_TRAITS>
1513template <class CONTG_ITER, class SENTINEL>
1517 CONTG_ITER first,
1518 SENTINEL last,
1519 typename
1522 CONTG_ITER>::value
1524 >::type *)
1525: d_start_p(first)
1526, d_length(last - first)
1527{
1528 BSLS_ASSERT_SAFE(first || last - first == 0);
1529 BSLS_ASSERT_SAFE( last - first >= 0);
1530}
1531
1532template <class CHAR_TYPE, class CHAR_TRAITS>
1533template <class ALLOCATOR>
1536 const std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& str)
1537: d_start_p(str.data())
1538, d_length(str.size())
1539{
1540}
1541
1542#ifdef BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
1543template <class CHAR_TYPE, class CHAR_TRAITS>
1547 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& view)
1548: d_start_p(view.data())
1549, d_length (view.size())
1550{
1551}
1552#endif // BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
1553
1554// MANIPULATORS
1555template <class CHAR_TYPE, class CHAR_TRAITS>
1556template <class ALLOCATOR>
1559basic_string_view<CHAR_TYPE, CHAR_TRAITS>&
1561 const std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& rhs)
1563{
1564 d_start_p = rhs.data();
1565 d_length = rhs.size();
1566 return *this;
1567}
1568
1569template <class CHAR_TYPE, class CHAR_TRAITS>
1571void
1573{
1574 BSLS_ASSERT_SAFE(d_length >= numChars);
1575 d_start_p += numChars;
1576 d_length -= numChars;
1577}
1578
1579template <class CHAR_TYPE, class CHAR_TRAITS>
1581void
1583{
1584 BSLS_ASSERT_SAFE(d_length >= numChars);
1585 d_length -= numChars;
1586}
1587
1588template <class CHAR_TYPE, class CHAR_TRAITS>
1589void
1592{
1593 BloombergLP::bslalg::ScalarPrimitives::swap(d_length, other.d_length);
1594 BloombergLP::bslalg::ScalarPrimitives::swap(d_start_p, other.d_start_p);
1595}
1596
1597// ACCESSORS
1598template <class CHAR_TYPE, class CHAR_TRAITS>
1599inline
1606
1607template <class CHAR_TYPE, class CHAR_TRAITS>
1608inline
1615
1616template <class CHAR_TYPE, class CHAR_TRAITS>
1617inline
1622{
1623 return begin() + d_length;
1624}
1625
1626template <class CHAR_TYPE, class CHAR_TRAITS>
1627inline
1634
1635template <class CHAR_TYPE, class CHAR_TRAITS>
1636inline
1643
1644template <class CHAR_TYPE, class CHAR_TRAITS>
1645inline
1653
1654template <class CHAR_TYPE, class CHAR_TRAITS>
1662
1663template <class CHAR_TYPE, class CHAR_TRAITS>
1671
1672template <class CHAR_TYPE, class CHAR_TRAITS>
1673inline
1680
1681template <class CHAR_TYPE, class CHAR_TRAITS>
1682inline
1689
1690template <class CHAR_TYPE, class CHAR_TRAITS>
1691inline
1696{
1697 return (npos - 1) / sizeof(CHAR_TYPE);
1698}
1699
1700template <class CHAR_TYPE, class CHAR_TRAITS>
1701inline
1705{
1706 return (0 == d_length);
1707}
1708
1709template <class CHAR_TYPE, class CHAR_TRAITS>
1710inline
1714{
1715 BSLS_ASSERT_SAFE(position < length());
1716
1717 return *(begin() + position);
1718}
1719
1720template <class CHAR_TYPE, class CHAR_TRAITS>
1725{
1726 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(position >= length())) {
1728 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1729 "string_view::at(n): invalid position");
1730 }
1731 return *(begin() + position);
1732}
1733
1734template <class CHAR_TYPE, class CHAR_TRAITS>
1735inline
1739{
1741
1742 return *begin();
1743}
1744
1745template <class CHAR_TYPE, class CHAR_TRAITS>
1746inline
1750{
1752
1753 return *(end() - 1);
1754}
1755
1756template <class CHAR_TYPE, class CHAR_TRAITS>
1757inline
1764
1765template <class CHAR_TYPE, class CHAR_TRAITS>
1768 size_type numChars,
1769 size_type position) const
1770{
1771
1772 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(position > length())) {
1774 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1775 "string_view::copy(str,pos,n): invalid position");
1776 }
1777
1778 BSLS_ASSERT_SAFE(characterString);
1779
1780 if (numChars > length() - position) {
1781 numChars = length() - position;
1782 }
1783
1784 // Check that the destination buffer start is not within the source.
1785 BSLS_ASSERT_SAFE(std::less<const CHAR_TYPE *>()(
1786 characterString, d_start_p + position) ||
1787 std::greater_equal<const CHAR_TYPE *>()(
1788 characterString, d_start_p + position + numChars));
1789
1790 CHAR_TRAITS::move(characterString, d_start_p + position, numChars);
1791
1792 return numChars;
1793}
1794
1795template <class CHAR_TYPE, class CHAR_TRAITS>
1800 size_type numChars) const
1801{
1802 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(position > length())) {
1804 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1805 "string_view::substr(pos,n): invalid position");
1806 }
1807
1808 const size_type maxLen = length() - position;
1809
1811 data() + position,
1812 numChars < maxLen ? numChars : maxLen);
1813}
1814
1815template <class CHAR_TYPE, class CHAR_TRAITS>
1820{
1821 return privateCompareRaw(size_type(0),
1822 length(),
1823 other.data(),
1824 other.length());
1825}
1826
1827template <class CHAR_TYPE, class CHAR_TRAITS>
1831 size_type position,
1832 size_type numChars,
1833 basic_string_view other) const
1834{
1835 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(length() < position)) {
1837 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1838 "const string_view<...>::compare(pos,n, other): invalid position");
1839 }
1840
1841 if (numChars > length() - position) {
1842 numChars = length() - position;
1843 }
1844 return privateCompareRaw(position, numChars, other.data(), other.length());
1845}
1846
1847template <class CHAR_TYPE, class CHAR_TRAITS>
1851 size_type lhsPosition,
1852 size_type lhsNumChars,
1853 basic_string_view other,
1854 size_type otherPosition,
1855 size_type otherNumChars) const
1856{
1857 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(length() < lhsPosition)) {
1859 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1860 "const string_view<...>::compare(pos,n,other,other_pos,other_n)"
1861 ": invalid lhs position");
1862 }
1863
1864 if (lhsNumChars > length() - lhsPosition) {
1865 lhsNumChars = length() - lhsPosition;
1866 }
1867
1869 other.length() < otherPosition)) {
1871 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1872 "const string_view<...>::compare(pos,n,other,other_pos,other_n)"
1873 ": invalid rhs position");
1874 }
1875
1876 if (otherNumChars > other.length() - otherPosition) {
1877 otherNumChars = other.length() - otherPosition;
1878 }
1879 return privateCompareRaw(lhsPosition,
1880 lhsNumChars,
1881 other.data() + otherPosition,
1882 otherNumChars);
1883}
1884
1885template <class CHAR_TYPE, class CHAR_TRAITS>
1889 const CHAR_TYPE *other) const
1890{
1891 BSLS_ASSERT_SAFE(other);
1892
1893 size_type otherLength = CHAR_TRAITS::length(other);
1894
1895 return privateCompareRaw(size_type(0),
1896 length(),
1897 other,
1898 otherLength);
1899}
1900
1901template <class CHAR_TYPE, class CHAR_TRAITS>
1905 size_type lhsPosition,
1906 size_type lhsNumChars,
1907 const CHAR_TYPE *other) const
1908{
1909 BSLS_ASSERT_SAFE(other);
1910
1911 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(length() < lhsPosition)) {
1913 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1914 "const string_view<...>::compare(pos,n,other): invalid position");
1915 }
1916
1917 size_type otherLength = CHAR_TRAITS::length(other);
1918
1919 if (lhsNumChars > length() - lhsPosition) {
1920 lhsNumChars = length() - lhsPosition;
1921 }
1922
1923 return compare(lhsPosition,
1924 lhsNumChars,
1925 other,
1926 otherLength);
1927}
1928
1929template <class CHAR_TYPE, class CHAR_TRAITS>
1933 size_type lhsPosition,
1934 size_type lhsNumChars,
1935 const CHAR_TYPE *other,
1936 size_type otherNumChars) const
1937{
1938 BSLS_ASSERT_SAFE(other || 0 == otherNumChars);
1939
1940 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(length() < lhsPosition)) {
1942 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1943 "const string_view<...>::compare(pos,n,other,other_pos)"
1944 ": invalid position");
1945 }
1946
1947 if (lhsNumChars > length() - lhsPosition) {
1948 lhsNumChars = length() - lhsPosition;
1949 }
1950 return privateCompareRaw(lhsPosition,
1951 lhsNumChars,
1952 other,
1953 otherNumChars);
1954}
1955
1956template <class CHAR_TYPE, class CHAR_TRAITS>
1961{
1962 return (size() >= subview.size() &&
1963 0 == compare(0, subview.size(), subview));
1964}
1965
1966template <class CHAR_TYPE, class CHAR_TRAITS>
1970 CHAR_TYPE character) const BSLS_KEYWORD_NOEXCEPT
1971{
1972 return (!empty() && CHAR_TRAITS::eq(front(), character));
1973}
1974
1975template <class CHAR_TYPE, class CHAR_TRAITS>
1979 const CHAR_TYPE* characterString) const
1980{
1981 BSLS_ASSERT_SAFE(characterString);
1982 for (size_type i = 0; i < d_length; ++i) {
1983 if (characterString[i] == 0) {
1984 // Ran out of characterString, so is prefix.
1985 return true; // RETURN
1986 }
1987 if (d_start_p[i] != characterString[i]) {
1988 // Mismatch.
1989 return false; // RETURN
1990 }
1991 }
1992 // Ran out of string_view, so check characterString is not longer.
1993 return characterString[d_length] == 0;
1994}
1995
1996template <class CHAR_TYPE, class CHAR_TRAITS>
2001{
2002 return (size() >= subview.size() &&
2003 0 == compare(size() - subview.size(), npos, subview));
2004}
2005
2006template <class CHAR_TYPE, class CHAR_TRAITS>
2010 CHAR_TYPE character) const BSLS_KEYWORD_NOEXCEPT
2011{
2012 return (!empty() && CHAR_TRAITS::eq(back(), character));
2013}
2014
2015template <class CHAR_TYPE, class CHAR_TRAITS>
2019 const CHAR_TYPE* characterString) const
2020{
2021 return ends_with(basic_string_view(characterString));
2022}
2023
2024template <class CHAR_TYPE, class CHAR_TRAITS>
2029 basic_string_view subview,
2030 size_type position) const BSLS_KEYWORD_NOEXCEPT
2031{
2032 return find(subview.data(), position, subview.length());
2033}
2034
2035template <class CHAR_TYPE, class CHAR_TRAITS>
2040 const CHAR_TYPE *substring,
2041 size_type position,
2042 size_type numChars) const
2043{
2044 BSLS_ASSERT_SAFE(substring || (numChars == 0));
2045
2046 size_type remChars = length() - position;
2047 if (position > length() || numChars > remChars) {
2048 return npos; // RETURN
2049 }
2050 if (0 == numChars) {
2051 return position; // RETURN
2052 }
2053 const CHAR_TYPE *thisString = data() + position;
2054 const CHAR_TYPE *nextString = 0;
2055 for (remChars -= numChars - 1;
2056 0 !=
2057 (nextString = CHAR_TRAITS::find(thisString, remChars, *substring));
2058 remChars -= ++nextString - thisString, thisString = nextString) {
2059 if (0 == CHAR_TRAITS::compare(nextString, substring, numChars)) {
2060 return nextString - data(); // RETURN
2061 }
2062 }
2063
2064 return npos;
2065}
2066
2067template <class CHAR_TYPE, class CHAR_TRAITS>
2072 const CHAR_TYPE *characterString,
2073 size_type position) const
2074{
2075 BSLS_ASSERT_SAFE(characterString);
2076
2077 return find(characterString,
2078 position,
2079 CHAR_TRAITS::length(characterString));
2080}
2081
2082template <class CHAR_TYPE, class CHAR_TRAITS>
2087 CHAR_TYPE character,
2088 size_type position) const BSLS_KEYWORD_NOEXCEPT
2089{
2090 if (position >= length()) {
2091 return npos; // RETURN
2092 }
2093 const CHAR_TYPE *result = CHAR_TRAITS::find(data() + position,
2094 length() - position,
2095 character);
2096 return result ? result - data() : npos;
2097}
2098
2099template <class CHAR_TYPE, class CHAR_TRAITS>
2104 basic_string_view subview,
2105 size_type position) const BSLS_KEYWORD_NOEXCEPT
2106{
2107 return rfind(subview.data(), position, subview.length());
2108}
2109
2110template <class CHAR_TYPE, class CHAR_TRAITS>
2115 const CHAR_TYPE *characterString,
2116 size_type position,
2117 size_type numChars) const
2118{
2119 BSLS_ASSERT_SAFE(characterString || 0 == numChars);
2120
2121 if (0 == numChars) {
2122 return position > length() ? length() : position; // RETURN
2123 }
2124 if (numChars <= length()) {
2125 if (position > length() - numChars) {
2126 position = length() - numChars;
2127 }
2128 const CHAR_TYPE *thisString = data() + position;
2129 for (; position != npos; --thisString, --position) {
2130 if (0 == CHAR_TRAITS::compare(thisString,
2131 characterString,
2132 numChars)) {
2133 return position; // RETURN
2134 }
2135 }
2136 }
2137 return npos;
2138}
2139
2140template <class CHAR_TYPE, class CHAR_TRAITS>
2145 const CHAR_TYPE *characterString,
2146 size_type position) const
2147{
2148 BSLS_ASSERT_SAFE(characterString);
2149
2150 return rfind(characterString,
2151 position,
2152 CHAR_TRAITS::length(characterString));
2153}
2154
2155template <class CHAR_TYPE, class CHAR_TRAITS>
2160 CHAR_TYPE character,
2161 size_type position) const BSLS_KEYWORD_NOEXCEPT
2162{
2163 return rfind(&character, position, size_type(1));
2164}
2165
2166template <class CHAR_TYPE, class CHAR_TRAITS>
2171 basic_string_view subview,
2172 size_type position) const BSLS_KEYWORD_NOEXCEPT
2173{
2174 return find_first_of(subview.data(), position, subview.length());
2175}
2176
2177template <class CHAR_TYPE, class CHAR_TRAITS>
2182 const CHAR_TYPE *characterString,
2183 size_type position) const
2184{
2185 BSLS_ASSERT_SAFE(characterString);
2186
2187 return find_first_of(characterString,
2188 position,
2189 CHAR_TRAITS::length(characterString));
2190}
2191
2192template <class CHAR_TYPE, class CHAR_TRAITS>
2197 const CHAR_TYPE *characterString,
2198 size_type position,
2199 size_type numChars) const
2200{
2201 BSLS_ASSERT_SAFE(characterString || 0 == numChars);
2202
2203 if (0 < numChars && position < length()) {
2204 for (const CHAR_TYPE *current = data() + position;
2205 current != end();
2206 ++current)
2207 {
2208 if (CHAR_TRAITS::find(characterString, numChars, *current) != 0) {
2209 return current - data(); // RETURN
2210 }
2211 }
2212 }
2213 return npos;
2214}
2215
2216template <class CHAR_TYPE, class CHAR_TRAITS>
2221 CHAR_TYPE character,
2222 size_type position) const BSLS_KEYWORD_NOEXCEPT
2223{
2224 return find_first_of(&character, position, size_type(1));
2225}
2226
2227template <class CHAR_TYPE, class CHAR_TRAITS>
2232 basic_string_view subview,
2233 size_type position) const BSLS_KEYWORD_NOEXCEPT
2234{
2235 return find_last_of(subview.data(), position, subview.length());
2236}
2237
2238template <class CHAR_TYPE, class CHAR_TRAITS>
2243 const CHAR_TYPE *characterString,
2244 size_type position) const
2245{
2246 BSLS_ASSERT_SAFE(characterString);
2247
2248 return find_last_of(characterString,
2249 position,
2250 CHAR_TRAITS::length(characterString));
2251}
2252
2253template <class CHAR_TYPE, class CHAR_TRAITS>
2258 const CHAR_TYPE *characterString,
2259 size_type position,
2260 size_type numChars) const
2261{
2262 BSLS_ASSERT_SAFE(characterString || 0 == numChars);
2263
2264 if (0 < numChars && 0 < length()) {
2265 size_type remChars = position < length() ? position : length() - 1;
2266 for (const CHAR_TYPE *current = data() + remChars;
2267 current >= data();
2268 --current)
2269 {
2270 if (CHAR_TRAITS::find(characterString, numChars, *current)) {
2271 return current - data(); // RETURN
2272 }
2273 }
2274 }
2275 return npos;
2276}
2277
2278template <class CHAR_TYPE, class CHAR_TRAITS>
2283 CHAR_TYPE character,
2284 size_type position) const BSLS_KEYWORD_NOEXCEPT
2285{
2286 return find_last_of(&character, position, size_type(1));
2287}
2288
2289template <class CHAR_TYPE, class CHAR_TRAITS>
2294 basic_string_view subview,
2295 size_type position) const BSLS_KEYWORD_NOEXCEPT
2296{
2297 return find_first_not_of(subview.data(), position, subview.length());
2298}
2299
2300template <class CHAR_TYPE, class CHAR_TRAITS>
2305 const CHAR_TYPE *characterString,
2306 size_type position) const
2307{
2308 BSLS_ASSERT_SAFE(characterString);
2309
2310 return find_first_not_of(characterString,
2311 position,
2312 CHAR_TRAITS::length(characterString));
2313}
2314
2315template <class CHAR_TYPE, class CHAR_TRAITS>
2320 const CHAR_TYPE *characterString,
2321 size_type position,
2322 size_type numChars) const
2323{
2324 BSLS_ASSERT_SAFE(characterString || 0 == numChars);
2325
2326 if (position < length()) {
2327 for (const CHAR_TYPE *current = data() + position;
2328 current != end();
2329 ++current)
2330 {
2331 if (!CHAR_TRAITS::find(characterString, numChars, *current)) {
2332 return current - data(); // RETURN
2333 }
2334 }
2335 }
2336 return npos;
2337}
2338
2339template <class CHAR_TYPE, class CHAR_TRAITS>
2344 CHAR_TYPE character,
2345 size_type position) const BSLS_KEYWORD_NOEXCEPT
2346{
2347 return find_first_not_of(&character, position, size_type(1));
2348}
2349
2350template <class CHAR_TYPE, class CHAR_TRAITS>
2355 basic_string_view subview,
2356 size_type position) const BSLS_KEYWORD_NOEXCEPT
2357{
2358 return find_last_not_of(subview.data(), position, subview.length());
2359}
2360
2361template <class CHAR_TYPE, class CHAR_TRAITS>
2366 const CHAR_TYPE *characterString,
2367 size_type position) const
2368{
2369 BSLS_ASSERT_SAFE(characterString);
2370
2371 return find_last_not_of(characterString,
2372 position,
2373 CHAR_TRAITS::length(characterString));
2374}
2375
2376template <class CHAR_TYPE, class CHAR_TRAITS>
2381 const CHAR_TYPE *characterString,
2382 size_type position,
2383 size_type numChars) const
2384{
2385 BSLS_ASSERT_SAFE(characterString || 0 == numChars);
2386
2387 if (0 < length()) {
2388 size_type remChars = position < length() ? position : length() - 1;
2389 for (const CHAR_TYPE *current = data() + remChars;
2390 current >= data();
2391 --current)
2392 {
2393 if (!CHAR_TRAITS::find(characterString, numChars, *current)) {
2394 return current - data(); // RETURN
2395 }
2396 }
2397 }
2398 return npos;
2399}
2400
2401template <class CHAR_TYPE, class CHAR_TRAITS>
2406 CHAR_TYPE character,
2407 size_type position) const BSLS_KEYWORD_NOEXCEPT
2408{
2409 return find_last_not_of(&character, position, size_type(1));
2410}
2411
2412// PUBLIC ACCESSORS
2413template <class CHAR_TYPE, class CHAR_TRAITS>
2416operator()(const basic_string_view<CHAR_TYPE, CHAR_TRAITS>& input) const
2417{
2418 using ::BloombergLP::bslh::hashAppend;
2419 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2420 hashAlg(input.data(), sizeof(CHAR_TYPE) * input.size());
2421 hashAppend(hashAlg, input.size());
2422 return static_cast<std::size_t>(hashAlg.computeHash());
2423}
2424
2425template <class CHAR_TYPE, class CHAR_TRAITS>
2428operator()(const CHAR_TYPE *input) const
2429{
2430 BSLS_ASSERT_SAFE(input);
2431 using ::BloombergLP::bslh::hashAppend;
2432 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2433
2434 std::size_t length = CHAR_TRAITS::length(input);
2435
2436 hashAlg(input, sizeof(CHAR_TYPE) * length);
2437 hashAppend(hashAlg, length);
2438 return static_cast<std::size_t>(hashAlg.computeHash());
2439}
2440
2441#if defined(BSLS_PLATFORM_CMP_SUN) // {DRQS 132030795}
2442
2443inline
2444std::size_t hash<string_view>::operator()(const string_view& input) const
2445{
2446 using ::BloombergLP::bslh::hashAppend;
2447 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2448 hashAlg(input.data(), input.size());
2449 hashAppend(hashAlg, input.size());
2450 return static_cast<std::size_t>(hashAlg.computeHash());
2451}
2452
2453inline
2454std::size_t hash<string_view>::operator()(const char *input) const
2455{
2456 BSLS_ASSERT_SAFE(input);
2457 using ::BloombergLP::bslh::hashAppend;
2458 std::size_t length = char_traits<char>::length(input);
2459 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2460 hashAlg(input, length);
2461 hashAppend(hashAlg, length);
2462 return static_cast<std::size_t>(hashAlg.computeHash());
2463}
2464
2465inline
2466std::size_t hash<wstring_view>::operator()(const wstring_view& input) const
2467{
2468 using ::BloombergLP::bslh::hashAppend;
2469 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2470 hashAlg(input.data(), sizeof(wchar_t) * input.size());
2471 hashAppend(hashAlg, input.size());
2472 return static_cast<std::size_t>(hashAlg.computeHash());
2473}
2474
2475inline
2476std::size_t hash<wstring_view>::operator()(const wchar_t *input) const
2477{
2478 BSLS_ASSERT_SAFE(input);
2479 using ::BloombergLP::bslh::hashAppend;
2480 std::size_t length = char_traits<wchar_t>::length(input);
2481 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2482 hashAlg(input, sizeof(wchar_t) * length);
2483 hashAppend(hashAlg, length);
2484 return static_cast<std::size_t>(hashAlg.computeHash());
2485}
2486
2487#endif
2488
2489} // close namespace bsl
2490
2491
2492namespace bslstl_stringview_relops {
2493
2494 // ----------------------
2495 // StringView_CompareUtil
2496 // ----------------------
2497
2498template <class CHAR_TYPE, class CHAR_TRAITS>
2499inline
2503{
2504 return lhs.size() == rhs.size()
2505 && 0 == CHAR_TRAITS::compare(lhs.data(), rhs.data(), lhs.size());
2506}
2507
2508template <class CHAR_TYPE, class CHAR_TRAITS>
2509inline
2513{
2514 const std::size_t minLen = lhs.length() < rhs.length()
2515 ? lhs.length() : rhs.length();
2516
2517 int ret = CHAR_TRAITS::compare(lhs.data(), rhs.data(), minLen);
2518 if (0 == ret) {
2519 return lhs.length() < rhs.length(); // RETURN
2520 }
2521 return (ret < 0);
2522}
2523
2524} // close namespace bslstl_stringview_relops
2525
2526
2527// FREE FUNCTIONS
2528template <class CHAR_TYPE, class CHAR_TRAITS>
2529inline
2530void bsl::swap(
2531 basic_string_view<CHAR_TYPE, CHAR_TRAITS>& a,
2532 basic_string_view<CHAR_TYPE, CHAR_TRAITS>& b) BSLS_KEYWORD_NOEXCEPT
2533{
2534 a.swap(b);
2535}
2536
2537// FREE OPERATORS
2538template <class CHAR_TYPE, class CHAR_TRAITS>
2539inline
2541bool BloombergLP::bslstl_stringview_relops::
2545{
2546 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2547}
2548
2549template <class CHAR_TYPE, class CHAR_TRAITS>
2550inline
2552bool BloombergLP::bslstl_stringview_relops::
2553operator==(typename BloombergLP::bslstl::StringView_Identity<
2557{
2558 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2559}
2560
2561template <class CHAR_TYPE, class CHAR_TRAITS>
2562inline
2564bool BloombergLP::bslstl_stringview_relops::
2566 typename BloombergLP::bslstl::StringView_Identity<
2569{
2570 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2571}
2572
2573template <class CHAR_TYPE, class CHAR_TRAITS>
2574inline
2576bool BloombergLP::bslstl_stringview_relops::
2580{
2581 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2582}
2583
2584template <class CHAR_TYPE, class CHAR_TRAITS>
2585inline
2587bool BloombergLP::bslstl_stringview_relops::
2588operator!=(typename BloombergLP::bslstl::StringView_Identity<
2592{
2593 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2594}
2595
2596template <class CHAR_TYPE, class CHAR_TRAITS>
2597inline
2599bool BloombergLP::bslstl_stringview_relops::
2601 typename BloombergLP::bslstl::StringView_Identity<
2604{
2605 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2606}
2607
2608template <class CHAR_TYPE, class CHAR_TRAITS>
2609inline
2611bool BloombergLP::bslstl_stringview_relops::
2615{
2616 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2617}
2618
2619template <class CHAR_TYPE, class CHAR_TRAITS>
2620inline
2622bool BloombergLP::bslstl_stringview_relops::
2623operator<(typename BloombergLP::bslstl::StringView_Identity<
2627{
2628 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2629}
2630
2631template <class CHAR_TYPE, class CHAR_TRAITS>
2632inline
2634bool BloombergLP::bslstl_stringview_relops::
2636 typename BloombergLP::bslstl::StringView_Identity<
2639{
2640 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2641}
2642
2643template <class CHAR_TYPE, class CHAR_TRAITS>
2644inline
2646bool BloombergLP::bslstl_stringview_relops::
2650{
2651 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2652}
2653
2654template <class CHAR_TYPE, class CHAR_TRAITS>
2655inline
2657bool BloombergLP::bslstl_stringview_relops::
2658operator>(typename BloombergLP::bslstl::StringView_Identity<
2662{
2663 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2664}
2665
2666template <class CHAR_TYPE, class CHAR_TRAITS>
2667inline
2669bool BloombergLP::bslstl_stringview_relops::
2671 typename BloombergLP::bslstl::StringView_Identity<
2674{
2675 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2676}
2677
2678template <class CHAR_TYPE, class CHAR_TRAITS>
2679inline
2681bool BloombergLP::bslstl_stringview_relops::
2685{
2686 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2687}
2688
2689template <class CHAR_TYPE, class CHAR_TRAITS>
2690inline
2692bool BloombergLP::bslstl_stringview_relops::
2693operator<=(typename BloombergLP::bslstl::StringView_Identity<
2697{
2698 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2699}
2700
2701template <class CHAR_TYPE, class CHAR_TRAITS>
2702inline
2704bool BloombergLP::bslstl_stringview_relops::
2706 typename BloombergLP::bslstl::StringView_Identity<
2709{
2710 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2711}
2712
2713template <class CHAR_TYPE, class CHAR_TRAITS>
2714inline
2716bool BloombergLP::bslstl_stringview_relops::
2720{
2721 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2722}
2723
2724template <class CHAR_TYPE, class CHAR_TRAITS>
2725inline
2727bool BloombergLP::bslstl_stringview_relops::
2728operator>=(typename BloombergLP::bslstl::StringView_Identity<
2732{
2733 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2734}
2735
2736template <class CHAR_TYPE, class CHAR_TRAITS>
2737inline
2739bool BloombergLP::bslstl_stringview_relops::
2741 typename BloombergLP::bslstl::StringView_Identity<
2744{
2745 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2746}
2747
2748namespace bsl {
2749
2750using BloombergLP::bslstl_stringview_relops::operator==;
2751using BloombergLP::bslstl_stringview_relops::operator!=;
2752using BloombergLP::bslstl_stringview_relops::operator<;
2753using BloombergLP::bslstl_stringview_relops::operator>;
2754using BloombergLP::bslstl_stringview_relops::operator<=;
2755using BloombergLP::bslstl_stringview_relops::operator>=;
2756
2757} // close namespace bsl
2758
2759template <class CHAR_TYPE, class CHAR_TRAITS>
2760std::basic_ostream<CHAR_TYPE>&
2761bsl::operator<<(std::basic_ostream<CHAR_TYPE>& stream,
2762 basic_string_view<CHAR_TYPE, CHAR_TRAITS> stringView)
2763{
2764 typedef CHAR_TYPE char_type;
2765 typedef typename std::basic_ostream<char_type>::ios_base ios_base;
2766 typedef typename basic_string_view<CHAR_TYPE, CHAR_TRAITS>::size_type
2767 size_type;
2768
2769 size_type width = static_cast<size_type>(stream.width());
2770 size_type len = stringView.length();
2771
2772 if (len < width) {
2773 bool leftAdjusted =
2774 (stream.flags() & ios_base::adjustfield) == ios_base::left;
2775
2776 char_type fillChar = stream.fill();
2777
2778 if (leftAdjusted) {
2779 if (stringView.data()) {
2780 stream.write(stringView.data(), stringView.length());
2781 }
2782 }
2783
2784 for (size_type n = 0; n != width - len; ++n) {
2785 stream.put(fillChar);
2786 }
2787
2788 if (!leftAdjusted) {
2789 if (stringView.data()) {
2790 stream.write(stringView.data(), stringView.length());
2791 }
2792 }
2793 }
2794 else {
2795 if (stringView.data()) {
2796 stream.write(stringView.data(), stringView.length());
2797 }
2798 }
2799
2800 stream.width(0);
2801
2802 return stream;
2803}
2804
2805// HASH SPECIALIZATIONS
2806template <class HASHALG, class CHAR_TYPE, class CHAR_TRAITS>
2807inline
2808void bsl::hashAppend(HASHALG& hashAlg,
2809 const basic_string_view<CHAR_TYPE, CHAR_TRAITS>& input)
2810{
2811 using ::BloombergLP::bslh::hashAppend;
2812 hashAlg(input.data(), sizeof(CHAR_TYPE)*input.size());
2813 hashAppend(hashAlg, input.size());
2814}
2815
2816#endif // BSLSTL_STRING_VIEW_IS_ALIASED
2817
2818#ifdef BSLSTL_STRING_VIEW_IS_ALIASED
2819
2820
2821template <class HASHALG, class CHAR_TYPE, class CHAR_TRAITS>
2823void bslh::hashAppend(
2824 HASHALG& hashAlg,
2825 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& input)
2826{
2827 hashAlg(input.data(), sizeof(CHAR_TYPE)*input.size());
2828 hashAppend(hashAlg, input.size());
2829}
2830
2831
2832#endif // BSLSTL_STRING_VIEW_IS_ALIASED
2833
2834#undef BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
2835
2836#endif
2837
2838// ----------------------------------------------------------------------------
2839// Copyright 2019 Bloomberg Finance L.P.
2840//
2841// Licensed under the Apache License, Version 2.0 (the "License");
2842// you may not use this file except in compliance with the License.
2843// You may obtain a copy of the License at
2844//
2845// http://www.apache.org/licenses/LICENSE-2.0
2846//
2847// Unless required by applicable law or agreed to in writing, software
2848// distributed under the License is distributed on an "AS IS" BASIS,
2849// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2850// See the License for the specific language governing permissions and
2851// limitations under the License.
2852// ----------------------------- END-OF-FILE ----------------------------------
2853
2854/** @} */
2855/** @} */
2856/** @} */
Definition bslstl_stringview.h:441
std::ptrdiff_t difference_type
Definition bslstl_stringview.h:458
std::size_t size_type
Definition bslstl_stringview.h:457
BSLS_KEYWORD_CONSTEXPR const_iterator end() const BSLS_KEYWORD_NOEXCEPT
Return the past-the-end iterator for this view.
Definition bslstl_stringview.h:1620
BSLS_KEYWORD_CONSTEXPR size_type max_size() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1694
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type find(basic_string_view subview, size_type position=0) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2028
BSLMF_NESTED_TRAIT_DECLARATION(basic_string_view, bsl::is_trivially_copyable)
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type find_first_of(basic_string_view subview, size_type position=0) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2170
BSLS_KEYWORD_CONSTEXPR_CPP17 const_reverse_iterator rend() const BSLS_KEYWORD_NOEXCEPT
Return the past-the-end reverse iterator for this view.
Definition bslstl_stringview.h:1658
BSLS_KEYWORD_CONSTEXPR_CPP14 void remove_suffix(size_type numChars)
Definition bslstl_stringview.h:1582
const value_type & const_reference
Definition bslstl_stringview.h:450
const_iterator iterator
Definition bslstl_stringview.h:452
basic_string_view & operator=(const basic_string_view &rhs)=default
const value_type * const_pointer
Definition bslstl_stringview.h:448
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type find_last_not_of(basic_string_view subview, size_type position=npos) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2354
CHAR_TRAITS traits_type
Definition bslstl_stringview.h:445
BSLS_KEYWORD_CONSTEXPR size_type length() const BSLS_KEYWORD_NOEXCEPT
Return the length of this view.
Definition bslstl_stringview.h:1685
CHAR_TYPE value_type
Definition bslstl_stringview.h:446
size_type copy(CHAR_TYPE *characterString, size_type numChars, size_type position=0) const
Definition bslstl_stringview.h:1767
BSLS_KEYWORD_CONSTEXPR const_iterator cbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1611
BSLS_KEYWORD_CONSTEXPR const_pointer data() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1760
BSLS_KEYWORD_CONSTEXPR_CPP17 bool starts_with(basic_string_view subview) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1959
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type find_last_of(basic_string_view subview, size_type position=npos) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2231
BSLS_KEYWORD_CONSTEXPR_CPP14 basic_string_view substr(size_type position=0, size_type numChars=npos) const
Definition bslstl_stringview.h:1799
value_type * pointer
Definition bslstl_stringview.h:447
BSLS_KEYWORD_CONSTEXPR const_iterator cend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1630
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference back() const
Definition bslstl_stringview.h:1749
bsl::reverse_iterator< const_iterator > const_reverse_iterator
Definition bslstl_stringview.h:455
BSLS_KEYWORD_CONSTEXPR_CPP17 const_reverse_iterator rbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1639
bsl::reverse_iterator< iterator > reverse_iterator
Definition bslstl_stringview.h:454
BSLS_KEYWORD_CONSTEXPR size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the length of this view.
Definition bslstl_stringview.h:1676
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type find_first_not_of(basic_string_view subview, size_type position=0) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2293
BSLS_KEYWORD_CONSTEXPR_CPP17 bool ends_with(basic_string_view subview) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1999
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type rfind(basic_string_view subview, size_type position=npos) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2103
value_type & reference
Definition bslstl_stringview.h:449
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference front() const
Definition bslstl_stringview.h:1738
BSLS_KEYWORD_CONSTEXPR_CPP17 int compare(basic_string_view other) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1818
void swap(basic_string_view &other) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1590
BSLS_KEYWORD_CONSTEXPR basic_string_view() BSLS_KEYWORD_NOEXCEPT
Create an empty view.
Definition bslstl_stringview.h:1481
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference at(size_type position) const
Definition bslstl_stringview.h:1724
static const size_type npos
Definition bslstl_stringview.h:465
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference operator[](size_type position) const
Definition bslstl_stringview.h:1713
const value_type * const_iterator
Definition bslstl_stringview.h:451
BSLS_KEYWORD_CONSTEXPR_CPP17 const_reverse_iterator crend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1667
~basic_string_view()=default
Destroy this object.
BSLS_KEYWORD_CONSTEXPR const_iterator begin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1602
BSLS_KEYWORD_CONSTEXPR_CPP17 const_reverse_iterator crbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1648
BSLS_KEYWORD_CONSTEXPR_CPP14 basic_string_view & operator=(const std::basic_string< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR > &rhs) BSLS_KEYWORD_NOEXCEPT
BSLS_KEYWORD_CONSTEXPR_CPP14 void remove_prefix(size_type numChars)
Definition bslstl_stringview.h:1572
BSLS_KEYWORD_CONSTEXPR bool empty() const BSLS_KEYWORD_NOEXCEPT
Return true if this view has length 0, and false otherwise.
Definition bslstl_stringview.h:1703
Definition bslstl_string.h:1281
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_CONSTEXPR_CPP14
Definition bsls_keyword.h:595
#define BSLS_KEYWORD_CONSTEXPR_CPP17
Definition bsls_keyword.h:603
#define BSLS_KEYWORD_EXPLICIT
Definition bsls_keyword.h:641
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:588
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
#define BSLS_PERFORMANCEHINT_UNLIKELY_HINT
Definition bsls_performancehint.h:484
#define BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(expr)
Definition bsls_performancehint.h:452
#define BSLS_PLATFORM_AGGRESSIVE_INLINE
Definition bsls_platform.h:836
void hashAppend(HASH_ALGORITHM &hashAlg, const baljsn::EncoderTestAddress &object)
Definition baljsn_encoder_testtypes.h:9236
Definition bdlb_printmethods.h:283
void hashAppend(HASH_ALGORITHM &hashAlgorithm, const array< TYPE, SIZE > &input)
Pass the specified input to the specified hashAlgorithm
Definition bslstl_array.h:950
basic_string_view< char > string_view
Definition bslstl_stringview.h:1053
T::iterator begin(T &container)
Definition bslstl_iterator.h:1495
std::basic_ostream< CHAR_TYPE, TRAITS > & operator<<(std::basic_ostream< CHAR_TYPE, TRAITS > &os, const bitset< N > &x)
Definition bslstl_bitset.h:1402
BSLS_KEYWORD_CONSTEXPR size_t size(const TYPE(&)[DIMENSION]) BSLS_KEYWORD_NOEXCEPT
Return the dimension of the specified array argument.
Definition bslstl_iterator.h:1331
T::iterator end(T &container)
Definition bslstl_iterator.h:1523
basic_string_view< wchar_t > wstring_view
Definition bslstl_stringview.h:1054
BSLS_KEYWORD_CONSTEXPR CONTAINER::value_type * data(CONTAINER &container)
Definition bslstl_iterator.h:1231
BSLS_KEYWORD_CONSTEXPR bool empty(const CONTAINER &container)
Definition bslstl_iterator.h:1279
Definition bslh_defaulthashalgorithm.h:339
bsl::enable_if<(bsl::is_integral< TYPE >::value||bsl::is_pointer< TYPE >::value||bsl::is_enum< TYPE >::value)&&!bsl::is_same< TYPE, bool >::value >::type hashAppend(HASH_ALGORITHM &hashAlg, TYPE input)
Definition bslh_hash.h:638
Definition bslstl_stringview.h:1076
Definition bslstl_algorithm.h:82
Definition bdldfp_decimal.h:5188
void swap(TYPE &a, TYPE &b)
Definition bslstl_stringview.h:396
Definition bslstl_stringview.h:409
Definition bslmf_enableif.h:525
Definition bslstl_hash.h:498
std::size_t operator()(const TYPE &value) const
Definition bslstl_hash.h:1031
Definition bslmf_integralconstant.h:244
Definition bslmf_isconvertible.h:867
Definition bslmf_istriviallycopyable.h:329
Definition bslstl_stringview.h:331
TYPE type
Definition bslstl_stringview.h:374
Definition bslstl_stringview.h:1090
bsl::basic_string_view< CHAR_TYPE, CHAR_TRAITS > StringView
Definition bslstl_stringview.h:1093
static BSLS_KEYWORD_CONSTEXPR_CPP17 bool equals(StringView lhs, StringView rhs) BSLS_KEYWORD_NOEXCEPT
Return true if lhs == rhs and false otherwise.
Definition bslstl_stringview.h:2501
static BSLS_KEYWORD_CONSTEXPR_CPP17 bool lessThan(StringView lhs, StringView rhs) BSLS_KEYWORD_NOEXCEPT
Return true if lhs < rhs and false otherwise.
Definition bslstl_stringview.h:2511