BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_stringstream.h
Go to the documentation of this file.
1/// @file bslstl_stringstream.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_stringstream.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_STRINGSTREAM
9#define INCLUDED_BSLSTL_STRINGSTREAM
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_stringstream bslstl_stringstream
15/// @brief Provide a C++03-compatible `stringstream` class.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_stringstream
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_stringstream-purpose"> Purpose</a>
25/// * <a href="#bslstl_stringstream-classes"> Classes </a>
26/// * <a href="#bslstl_stringstream-canonical-header"> Canonical Header </a>
27/// * <a href="#bslstl_stringstream-description"> Description </a>
28/// * <a href="#bslstl_stringstream-memory-allocation"> Memory Allocation </a>
29/// * <a href="#bslstl_stringstream-bslma-style-allocators"> bslma-Style Allocators </a>
30/// * <a href="#bslstl_stringstream-usage"> Usage </a>
31/// * <a href="#bslstl_stringstream-example-1-basic-input-and-output-operations"> Example 1: Basic Input and Output Operations </a>
32///
33/// # Purpose {#bslstl_stringstream-purpose}
34/// Provide a C++03-compatible `stringstream` class.
35///
36/// # Classes {#bslstl_stringstream-classes}
37///
38/// - bsl::stringstream: C++03-compatible `stringstream` class
39///
40/// # Canonical Header {#bslstl_stringstream-canonical-header}
41/// bsl_sstream.h
42///
43/// @see
44///
45/// # Description {#bslstl_stringstream-description}
46/// This component is for internal use only. Please include
47/// `<bsl_sstream.h>` instead.
48///
49/// This component defines a class template, `bsl::basic_stringstream`,
50/// implementing a standard stream that provides a constructor and manipulator
51/// (`str`) that allow clients to directly set the internal sequence of
52/// characters that is accessed (or modified) by the stream, as well as an
53/// accessor (`str`) for obtaining a string having the same sequence of
54/// characters to which the stream currently refers (see 27.8.5 [stringstream]
55/// of the C++11 standard). This component also defines two standard aliases,
56/// `bsl::stringstream` and `bsl::wstringstream`, that refer to specializations
57/// of the `bsl::basic_stringstream` template for `char` and `wchar_t` types,
58/// respectively. The `bsl::basic_stringstream` template has three parameters,
59/// `CHAR_TYPE`, `CHAR_TRAITS`, and `ALLOCATOR`. The `CHAR_TYPE` and
60/// `CHAR_TRAITS` parameters respectively define the character type for the
61/// string-stream and a type providing a set of operations the string-stream
62/// will use to manipulate characters of that type, which must meet the
63/// character traits requirements defined by the C++11 standard, 21.2
64/// [char.traits]. The `ALLOCATOR` template parameter is described in the
65/// "Memory Allocation" section below.
66///
67/// ## Memory Allocation {#bslstl_stringstream-memory-allocation}
68///
69///
70/// The type supplied as a string-stream's `ALLOCATOR` template parameter
71/// determines how that string-stream will allocate memory. The
72/// @ref basic_stringstream template supports allocators meeting the requirements
73/// of the C++11 standard, 17.6.3.5 [allocator.requirements]; in addition, it
74/// supports scoped-allocators derived from the `bslma::Allocator` memory
75/// allocation protocol. Clients intending to use `bslma`-style allocators
76/// should use `bsl::allocator`, which provides a C++11 standard-compatible
77/// adapter for a `bslma::Allocator` object. Note that the standard aliases
78/// `bsl::stringstream` and `bsl::wstringstream` both use `bsl::allocator`.
79///
80/// ### bslma-Style Allocators {#bslstl_stringstream-bslma-style-allocators}
81///
82///
83/// If the type supplied for the `ALLOCATOR` template parameter of an
84/// `stringstream` instantiation is `bsl::allocator`, then objects of that
85/// string-stream type will conform to the standard behavior of a
86/// `bslma`-allocator-enabled type. Such a string-stream accepts an optional
87/// `bslma::Allocator` argument at construction. If the address of a
88/// `bslma::Allocator` object is explicitly supplied at construction, it will be
89/// used to supply memory for the string-stream throughout its lifetime;
90/// otherwise, the string-stream will use the default allocator installed at the
91/// time of the string-stream's construction (see @ref bslma_default ).
92///
93/// ## Usage {#bslstl_stringstream-usage}
94///
95///
96/// This section illustrates intended use of this component.
97///
98/// ### Example 1: Basic Input and Output Operations {#bslstl_stringstream-example-1-basic-input-and-output-operations}
99///
100///
101/// The following example demonstrates the use of `bsl::stringstream` to read
102/// and write data of various types to a `bsl::string` object.
103///
104/// Suppose we want to implement a simplified converter between a pair of
105/// generic types, `TYPE1` and `TYPE2`. We use `bsl::stringstream` to implement
106/// the `lexicalCast` function. We write the data of type `TYPE1` into the
107/// stream with `operator<<` and then read it back as the data of `TYPE2` with
108/// `operator>>`:
109/// @code
110/// template <class TYPE2, class TYPE1>
111/// TYPE2 lexicalCast(const TYPE1& what)
112/// {
113/// bsl::stringstream converter;
114/// converter << what;
115///
116/// TYPE2 val;
117/// converter >> val;
118/// return val;
119/// }
120/// @endcode
121/// Finally, we verify that the `lexicalCast` function works on some simple test
122/// cases:
123/// @code
124/// assert(lexicalCast<int>("1234") == 1234);
125///
126/// assert(lexicalCast<short>("-5") == -5);
127///
128/// assert(lexicalCast<bsl::string>("abc") == "abc");
129///
130/// assert(lexicalCast<bsl::string>(1234) == "1234");
131///
132/// assert(lexicalCast<short>(-5) == -5);
133/// @endcode
134/// @}
135/** @} */
136/** @} */
137
138/** @addtogroup bsl
139 * @{
140 */
141/** @addtogroup bslstl
142 * @{
143 */
144/** @addtogroup bslstl_stringstream
145 * @{
146 */
147
148#include <bslscm_version.h>
149
150#include <bslma_isstdallocator.h>
152
153#include <bslmf_enableif.h>
154#include <bslmf_issame.h>
155#include <bslmf_movableref.h>
156
158#include <bsls_keyword.h>
159#include <bsls_libraryfeatures.h>
160#include <bsls_platform.h>
161
162#include <bslstl_string.h>
163#include <bslstl_stringbuf.h>
164#include <bslstl_stringview.h>
166
167#include <ios>
168
169#include <iostream>
170
171#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
172# include <utility>
173#endif
174
175namespace bsl {
176
177 // ========================
178 // class basic_stringstream
179 // ========================
180
181/// This class implements a standard stream providing operations using
182/// `bsl::basic_string` for modifying or accessing the sequence of
183/// characters read from, or written to, the stream.
184template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
186 : private StringBufContainer<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>
187 , public std::basic_iostream<CHAR_TYPE, CHAR_TRAITS> {
188
189 private:
190 // PRIVATE TYPES
193 BaseType;
196 typedef std::basic_iostream<CHAR_TYPE, CHAR_TRAITS> BaseStream;
197 typedef std::ios_base ios_base;
198
199 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
200
201 private:
202 // NOT IMPLEMENTED
203 basic_stringstream(const basic_stringstream&); // = delete
204 basic_stringstream& operator=(const basic_stringstream&); // = delete
205
206 public:
207 // TYPES
208 typedef CHAR_TYPE char_type;
210 typedef ALLOCATOR allocator_type;
211 typedef typename traits_type::int_type int_type;
212 typedef typename traits_type::off_type off_type;
213 typedef typename traits_type::pos_type pos_type;
214
215 // CREATORS
216
217 /// Create a @ref basic_stringstream object. Optionally specify a
218 /// `modeBitMask` indicating whether the underlying stream-buffer may be
219 /// read from, written to, or both (`rdbuf` is created using
220 /// `modeBitMask`). If `modeBitMask` is not supplied, `rdbuf` will be
221 /// created using `ios_base::in | ios_base::out`. Optionally specify an
222 /// `initialString` indicating the initial sequence of characters that
223 /// this stream may access or manipulate. If `initialString` is not
224 /// supplied, the initial sequence of characters will be empty.
225 /// Optionally specify the `allocator` used to supply memory. If
226 /// `allocator` is not supplied, a default-constructed object of the
227 /// (template parameter) `ALLOCATOR` type is used. If the `ALLOCATOR`
228 /// argument is of type `bsl::allocator` (the default), then
229 /// `allocator`, if supplied, shall be convertible to
230 /// `bslma::Allocator *`. If the `ALLOCATOR` argument is of type
231 /// `bsl::allocator` and `allocator` is not supplied, the currently
232 /// installed default allocator will be used to supply memory. If
233 /// `initialString` is passed by `MovableRef`, it is left in a valid but
234 /// unspecified state.
235 explicit
237 explicit
238 basic_stringstream(ios_base::openmode modeBitMask,
240 explicit
241 basic_stringstream(const StringType& initialString,
243 basic_stringstream(const StringType& initialString,
244 ios_base::openmode modeBitMask,
246
247 /// Create a @ref basic_stringstream object. Use the specified
248 /// `initialString` indicating the initial sequence of characters that
249 /// this buffer will access or manipulate. Optionally specify a
250 /// `modeBitMask` indicating whether this buffer may be read from,
251 /// written to, or both. If `modeBitMask` is not supplied, this buffer
252 /// is created with `ios_base::in | ios_base::out`. Optionally specify
253 /// the `allocator` used to supply memory. If `allocator` is not
254 /// supplied, the allocator in `initialString` is used. `initialString`
255 /// is left in a valid but unspecified state.
256 explicit
258 BloombergLP::bslmf::MovableRef<StringType> initialString);
260 BloombergLP::bslmf::MovableRef<StringType> initialString,
263 BloombergLP::bslmf::MovableRef<StringType> initialString,
264 ios_base::openmode modeBitMask);
266 BloombergLP::bslmf::MovableRef<StringType> initialString,
267 ios_base::openmode modeBitMask,
269
270 /// Create a @ref basic_stringstream object. Use the specified
271 /// `initialString` indicating the initial sequence of characters that
272 /// this stream will access or manipulate. `rdbuf` is created using
273 /// `ios_base::in | ios_base::out`. Optionally specify the `allocator`
274 /// used to supply memory. If `allocator` is not supplied, a
275 /// default-constructed object of the (template parameter) `ALLOCATOR`
276 /// type is used. If the `ALLOCATOR` argument is of type
277 /// `bsl::allocator` (the default), then `allocator`, if supplied, shall
278 /// be convertible to `bslma::Allocator *`. If the `ALLOCATOR` argument
279 /// is of type `bsl::allocator` and `allocator` is not supplied, the
280 /// currently installed default allocator will be used to supply memory.
281 template <class SALLOC>
282 explicit
285 initialString,
287 typename bsl::enable_if<
288 !bsl::is_same<ALLOCATOR, SALLOC>::value, void *>::type = 0)
289 : BaseType(initialString.begin(),
290 initialString.end(),
291 ios_base::in | ios_base::out,
292 allocator)
293 , BaseStream(BaseType::rdbuf())
294 {
295 // Note: implemented inline due to Sun CC compilation error.
296 }
297
298 /// Create a @ref basic_stringstream object. Use the specified
299 /// `initialString` indicating the initial sequence of characters that
300 /// this stream will access or manipulate. Use the specified
301 /// `modeBitMask` to indicate whether this stream may be read from,
302 /// written to, or both. Optionally specify the `allocator` used to
303 /// supply memory. If `allocator` is not supplied, a
304 /// default-constructed object of the (template parameter) `ALLOCATOR`
305 /// type is used. If the `ALLOCATOR` argument is of type
306 /// `bsl::allocator` (the default), then `allocator`, if supplied, shall
307 /// be convertible to `bslma::Allocator *`. If the `ALLOCATOR` argument
308 /// is of type `bsl::allocator` and `allocator` is not supplied, the
309 /// currently installed default allocator will be used to supply memory.
310 template <class SALLOC>
313 initialString,
314 ios_base::openmode modeBitMask,
316 typename bsl::enable_if<
317 !bsl::is_same<ALLOCATOR, SALLOC>::value, void *>::type = 0)
318 : BaseType(initialString.begin(),
319 initialString.end(),
320 modeBitMask,
321 allocator)
322 , BaseStream(BaseType::rdbuf())
323 {
324 // Note: implemented inline due to Sun CC compilation error.
325 }
326
327 /// Create a @ref basic_stringstream object. Use the specified
328 /// `initialString` (of a type convertible to
329 /// `basic_string_view<CHAR_TYPE, CHAR_TRAITS>` but not to
330 /// `const CHAR_TYPE *`) indicating the initial sequence of characters
331 /// that this stream will access or manipulate. `rdbuf` is created using
332 /// `ios_base::in | ios_base::out`. Optionally specify the `allocator`
333 /// used to supply memory. If `allocator` is not supplied, a
334 /// default-constructed object of the (template parameter) `ALLOCATOR`
335 /// type is used. If the `ALLOCATOR` argument is of type
336 /// `bsl::allocator` (the default), then `allocator`, if supplied, shall
337 /// be convertible to `bslma::Allocator *`. If the `ALLOCATOR` argument
338 /// is of type `bsl::allocator` and `allocator` is not supplied, the
339 /// currently installed default allocator will be used to supply memory.
340 template <class STRING_VIEW_LIKE_TYPE>
341 explicit
343 const STRING_VIEW_LIKE_TYPE& initialString,
346 : BaseType(initialString, ios_base::in | ios_base::out, allocator)
347 , BaseStream(BaseType::rdbuf())
348 {
349 // Note: implemented inline due to Sun CC compilation error.
350 }
351
352 /// Create a @ref basic_stringstream object. Use the specified
353 /// `initialString` (of a type convertible to
354 /// `basic_string_view<CHAR_TYPE, CHAR_TRAITS>` but not to
355 /// `const CHAR_TYPE *`) indicating the initial sequence of characters
356 /// that this stream will access or manipulate. Use the specified
357 /// `modeBitMask` to indicate whether this stream may be read from,
358 /// written to, or both. Optionally specify the `allocator` used to
359 /// supply memory. If `allocator` is not supplied, a
360 /// default-constructed object of the (template parameter) `ALLOCATOR`
361 /// type is used. If the `ALLOCATOR` argument is of type
362 /// `bsl::allocator` (the default), then `allocator`, if supplied, shall
363 /// be convertible to `bslma::Allocator *`. If the `ALLOCATOR` argument
364 /// is of type `bsl::allocator` and `allocator` is not supplied, the
365 /// currently installed default allocator will be used to supply memory.
366 template <class STRING_VIEW_LIKE_TYPE>
368 const STRING_VIEW_LIKE_TYPE& initialString,
369 ios_base::openmode modeBitMask,
372 : BaseType(initialString, modeBitMask, allocator)
373 , BaseStream(BaseType::rdbuf())
374 {
375 // Note: implemented inline due to Sun CC compilation error.
376 }
377
378
379#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
380 /// Create a @ref basic_stringstream object having the same value as the
381 /// specified `original` object by moving the contents of `original` to
382 /// the newly-created object. `original` is left in a valid but
383 /// unspecified state.
384// NOLINTNEXTLINE(performance-noexcept-move-constructor)
386#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
387
388 /// Destroy this object.
390
391 // MANIPULATORS
392
393#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
394 /// Assign to this object the value of the specified `rhs`, and return a
395 /// reference providing modifiable access to this object. The contents
396 /// of `rhs` are move-assigned to this object. `rhs` is left in a valid
397 /// but unspecified state.
398// NOLINTNEXTLINE(performance-noexcept-move-constructor)
400#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
401
402 /// Reset the internally buffered sequence of characters maintained by
403 /// this stream to the specified `value`. If `value` is passed by
404 /// `MovableRef`, it is left in a valid but unspecified state.
405 void str(const StringType& value);
406 void str(BloombergLP::bslmf::MovableRef<StringType> value);
407 template <class SALLOC>
408 typename
411 {
412 // Note: implemented inline due to Sun CC compilation error.
413 return this->rdbuf()->str(value);
414 }
415
416 /// Reset the internally buffered sequence of characters maintained by
417 /// this stream to the specified `value` (of a type convertible to
418 /// `basic_string_view<CHAR_TYPE, CHAR_TRAITS>` but not to
419 /// `const CHAR_TYPE *`).
420 template <class STRING_VIEW_LIKE_TYPE>
422 str(const STRING_VIEW_LIKE_TYPE& value)
423 {
424 // Note: implemented inline due to Sun CC compilation error.
425 this->rdbuf()->str(value);
426 }
427
428#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
429 /// Return the internally buffered sequence of characters maintained by
430 /// this stream, leaving the stream empty.
431 StringType str() &&;
432#endif // BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
433
434#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
435 /// Efficiently exchange the value of this object with the value of the
436 /// specified `other` object. This method provides the no-throw
437 /// exception-safety guarantee if `*this` and `other` allocators compare equal.
438 ///
439 /// \pre The behavior is undefined unless either `*this` and `other`
440 /// allocators compare equal or @ref propagate_on_container_swap is `true`.
441 ///
442 /// \note Note that this function is only available for C++11 (and later)
443 /// language standards because it requires that `swap` be provided on
444 /// the (platform supplied) base class for this type.
445// NOLINTNEXTLINE(performance-noexcept-swap)
446 void swap(basic_stringstream& other);
447#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
448
449 // ACCESSORS
450
451 /// Return an address providing modifiable access to the
452 /// @ref basic_stringbuf object that is internally used by this stream
453 /// object to buffer unformatted characters.
454 StreamBufType *rdbuf() const;
455
456 /// Return the internally buffered sequence of characters maintained by
457 /// this stream object.
458#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
459 StringType str() const &;
460#else
461 StringType str() const;
462#endif
463
464#ifndef BSLS_PLATFORM_CMP_SUN
465 // To be enabled once DRQS 168075157 is resolved
466
467 /// Return a copy of the internally buffered sequence of characters
468 /// maintained by this stream object in a @ref basic_string that uses the
469 /// specified `allocator`.
470 template <class SALLOC>
471 typename bsl::enable_if<
472 bsl::IsStdAllocator<SALLOC>::value,
474 str(const SALLOC& allocator) const
475 {
476 // Note: implemented inline due to Sun CC compilation error.
477 return this->rdbuf()->str(allocator);
478 }
479#endif // BSLS_PLATFORM_CMP_SUN
480
481 /// Return a view of the internally buffered sequence of characters
482 /// maintained by this stream object.
483 ViewType view() const BSLS_KEYWORD_NOEXCEPT;
484};
485
486// FREE FUNCTIONS
487#if defined(BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY) \
488 && defined(BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE)
489/// Efficiently exchange the values of the specified `a` and `b` objects.
490/// This method provides the no-throw exception-safety guarantee if `a` and `b` allocators compare equal.
491///
492/// \note Note that this function is only available
493/// for C++11 (and later) language standards.
494template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
495// NOLINTNEXTLINE(performance-noexcept-swap)
498#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY && CPP11_STREAM_MOVE
499
500// STANDARD TYPEDEFS
505
506} // close namespace bsl
507
508// TYPE TRAITS
509
510namespace bslma {
511
512template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
514 bsl::basic_stringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR> >
516{};
517
518} // close namespace bslma
519
520
521namespace bsl {
522
523// ============================================================================
524// TEMPLATE FUNCTION DEFINITIONS
525// ============================================================================
526
527 // ------------------------
528 // class basic_stringstream
529 // ------------------------
530
531// CREATORS
532template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
533inline
536: BaseType(ios_base::in | ios_base::out, allocator)
537, BaseStream(BaseType::rdbuf())
538{
539}
540
541template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
542inline
544 basic_stringstream(ios_base::openmode modeBitMask,
546: BaseType(modeBitMask, allocator)
547, BaseStream(BaseType::rdbuf())
548{
549}
550
551template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
552inline
554basic_stringstream(const StringType& initialString,
556: BaseType(initialString, ios_base::in | ios_base::out, allocator)
557, BaseStream(BaseType::rdbuf())
558{
559}
560
561template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
562inline
564basic_stringstream(const StringType& initialString,
565 ios_base::openmode modeBitMask,
567: BaseType(initialString, modeBitMask, allocator)
568, BaseStream(BaseType::rdbuf())
569{
570}
571
572template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
573inline
575basic_stringstream(BloombergLP::bslmf::MovableRef<StringType> initialString)
576: BaseType(MoveUtil::move(initialString), ios_base::in | ios_base::out)
577, BaseStream(BaseType::rdbuf())
578{
579}
580
581template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
582inline
584basic_stringstream(BloombergLP::bslmf::MovableRef<StringType> initialString,
586: BaseType(MoveUtil::move(initialString),
587 ios_base::in | ios_base::out,
588 allocator)
589, BaseStream(BaseType::rdbuf())
590{
591}
592
593template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
594inline
596basic_stringstream(BloombergLP::bslmf::MovableRef<StringType> initialString,
597 ios_base::openmode modeBitMask)
598: BaseType(MoveUtil::move(initialString), modeBitMask)
599, BaseStream(BaseType::rdbuf())
600{
601}
602
603template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
604inline
606basic_stringstream(BloombergLP::bslmf::MovableRef<StringType> initialString,
607 ios_base::openmode modeBitMask,
609: BaseType(MoveUtil::move(initialString), modeBitMask, allocator)
610, BaseStream(BaseType::rdbuf())
611{
612}
613
614#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
615template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
616inline
618// NOLINTNEXTLINE(performance-noexcept-move-constructor)
620: BaseType(std::move(original))
621, BaseStream(std::move(original))
622{
623 BaseStream::set_rdbuf(BaseType::rdbuf());
624}
625#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
626
627// MANIPULATORS
628#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
629template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
630inline
631basic_stringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>&
632basic_stringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::
633// NOLINTNEXTLINE(performance-noexcept-move-constructor)
634operator=(basic_stringstream&& rhs)
635{
636 this->BaseType::operator=(std::move(rhs));
637 this->BaseStream::operator=(std::move(rhs));
638
639 return *this;
640}
641#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE
642
643#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
644template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
645inline
646// NOLINTNEXTLINE(performance-noexcept-swap)
647void basic_stringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::swap(
648 basic_stringstream& other)
649{
650#ifdef BSLS_PLATFORM_CMP_GNU
651# pragma GCC diagnostic push
652# pragma GCC diagnostic ignored "-Wstringop-overflow"
653#endif
656 || this->rdbuf()->get_allocator()
657 == other.rdbuf()->get_allocator());
658 this->BaseType::swap(other);
659 this->BaseStream::swap(other);
660#ifdef BSLS_PLATFORM_CMP_GNU
661# pragma GCC diagnostic pop
662#endif
663}
664#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
665
666template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
667inline
669 const StringType& value)
670{
671 this->rdbuf()->str(value);
672}
673
674template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
675inline
677 BloombergLP::bslmf::MovableRef<StringType> value)
678{
679 this->rdbuf()->str(MoveUtil::move(value));
680}
681
682#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
683template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
684inline
687{
688 return std::move(*this->rdbuf()).str();
689}
690#endif // BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
691
692// ACCESSORS
693template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
694inline
695typename basic_stringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::StreamBufType *
697{
698 return this->BaseType::rdbuf();
699}
700
701#ifdef BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
702template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
703inline
706{
707 return this->rdbuf()->str();
708}
709#else // BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
710template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
711inline
712typename basic_stringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::StringType
714{
715 return this->rdbuf()->str();
716}
717#endif // else BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS
718
719template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
720inline
721typename basic_stringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>::ViewType
724{
725 return this->rdbuf()->view();
726}
727
728} // close namespace bsl
729
730// FREE FUNCTIONS
731#if defined(BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY) \
732 && defined(BSLS_LIBRARYFEATURES_HAS_CPP11_STREAM_MOVE)
733template <class CHAR_TYPE, class CHAR_TRAITS, class ALLOCATOR>
734// NOLINTNEXTLINE(performance-noexcept-swap)
735void bsl::swap(basic_stringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& a,
736 basic_stringstream<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& b)
737{
738 a.swap(b);
739}
740#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY && CPP11_STREAM_MOVE
741
742#endif // INCLUDED_BSLSTL_STRINGSTREAM
743
744// ----------------------------------------------------------------------------
745// Copyright 2013 Bloomberg Finance L.P.
746//
747// Licensed under the Apache License, Version 2.0 (the "License");
748// you may not use this file except in compliance with the License.
749// You may obtain a copy of the License at
750//
751// http://www.apache.org/licenses/LICENSE-2.0
752//
753// Unless required by applicable law or agreed to in writing, software
754// distributed under the License is distributed on an "AS IS" BASIS,
755// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
756// See the License for the specific language governing permissions and
757// limitations under the License.
758// ----------------------------- END-OF-FILE ----------------------------------
759
760/** @} */
761/** @} */
762/** @} */
Definition bslstl_stringbuf.h:835
Definition bslma_bslallocator.h:588
Definition bslstl_stringview.h:471
Definition bslstl_string.h:1252
Definition bslstl_stringbuf.h:248
Definition bslstl_stringstream.h:187
CHAR_TRAITS traits_type
Definition bslstl_stringstream.h:209
basic_stringstream(const STRING_VIEW_LIKE_TYPE &initialString, ios_base::openmode modeBitMask, allocator=allocator_type())
Definition bslstl_stringstream.h:367
traits_type::pos_type pos_type
Definition bslstl_stringstream.h:213
StringType str() const
Definition bslstl_stringstream.h:713
traits_type::int_type int_type
Definition bslstl_stringstream.h:211
basic_stringstream(const bsl::basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > &initialString, const allocator_type &allocator=allocator_type(), typename bsl::enable_if< !bsl::is_same< ALLOCATOR, SALLOC >::value, void * >::type=0)
Definition bslstl_stringstream.h:283
basic_stringstream(const STRING_VIEW_LIKE_TYPE &initialString, allocator=allocator_type())
Definition bslstl_stringstream.h:342
bsl::enable_if< bsl::IsStdAllocator< SALLOC >::value, basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > >::type str(const SALLOC &allocator) const
Definition bslstl_stringstream.h:474
traits_type::off_type off_type
Definition bslstl_stringstream.h:212
~basic_stringstream()=default
Destroy this object.
bsl::enable_if<!bsl::is_same< ALLOCATOR, SALLOC >::value, void >::type str(const basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > &value)
Definition bslstl_stringstream.h:410
CHAR_TYPE char_type
Definition bslstl_stringstream.h:208
StreamBufType * rdbuf() const
Definition bslstl_stringstream.h:696
ALLOCATOR allocator_type
Definition bslstl_stringstream.h:210
ViewType view() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringstream.h:722
basic_stringstream(const bsl::basic_string< CHAR_TYPE, CHAR_TRAITS, SALLOC > &initialString, ios_base::openmode modeBitMask, const allocator_type &allocator=allocator_type(), typename bsl::enable_if< !bsl::is_same< ALLOCATOR, SALLOC >::value, void * >::type=0)
Definition bslstl_stringstream.h:311
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
#define BSLSTL_STRINGVIEWLIKEPARAM_ONLY_ENABLE_IF_T(...)
Definition bslstl_stringviewlikeparam.h:159
Definition bdlat_valuetypefunctions.h:939
basic_stringstream< wchar_t, char_traits< wchar_t >, allocator< wchar_t > > wstringstream
Definition bslstl_iosfwd.h:108
basic_stringstream< char, char_traits< char >, allocator< char > > stringstream
Definition bslstl_iosfwd.h:99
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
T::iterator begin(T &container)
Definition bslstl_iterator.h:1593
CHAR_TRAITS
Definition bslstl_string.h:3917
T::iterator end(T &container)
Definition bslstl_iterator.h:1621
Definition baljsn_encoder_testtypes.h:76
Definition bdldfp_decimal.h:5549
Definition bslma_allocatortraits.h:1089
Definition bslmf_enableif.h:530
Definition bslmf_issame.h:146
Definition bslma_usesbslmaallocator.h:344