[#bsl-basic_string-0f3-2constructor-0d] = xref:bsl.adoc[bsl]::xref:bsl/basic_string-0f3.adoc[basic_string<char32_t>]::basic_string :relfileprefix: ../../ :mrdocs: Constructors == Synopses Declared in `<bslstl_string.h>` Create an empty string using a default‐constructed allocator. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-0c0.adoc[basic_string]() noexcept; ---- [.small]#xref:bsl/basic_string-0f3/2constructor-0c0.adoc[_» more..._]# A string cannot be constructed from a `nullptr` or from a literal `0`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-01.adoc[basic_string](xref:bsl/nullptr_t-08.adoc[bsl::nullptr_t]) = delete; ---- [.small]#xref:bsl/basic_string-0f3/2constructor-01.adoc[_» more..._]# Create a string that has the same value as the specified `original` string by moving (in constant time) the contents of `original` to the new string. The allocator associated with `original` is propagated for use in the newly‐created string. `original` is left in a valid but unspecified state. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-0e4.adoc[basic_string](xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef<basic_string<char32_t>>] original) noexcept; ---- [.small]#xref:bsl/basic_string-0f3/2constructor-0e4.adoc[_» more..._]# Create an empty string. Optionally specify the `basicAllocator` used to supply memory. If `basicAllocator` is not specified, a default‐constructed allocator is used. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- explicit xref:bsl/basic_string-0f3/2constructor-0c5.adoc[basic_string](xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator) noexcept; ---- [.small]#xref:bsl/basic_string-0f3/2constructor-0c5.adoc[_» more..._]# Create a string that has the same value as the specified `original` string. Use the allocator returned by 'bsl::allocator_traits<ALLOCATOR>:: select_on_container_copy_construction(original.get_allocator())' to supply memory. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-0ed.adoc[basic_string](xref:bsl/basic_string-0faf.adoc[basic_string<char32_t>] const& original); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-0ed.adoc[_» more..._]# Create a string that has the same value as the specified `object`. Optionally specify a `basicAllocator` used to supply memory. If `basicAllocator` is not specified, then a default‐constructed allocator is used. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class STRING_VIEW_LIKE_TYPE> explicit xref:bsl/basic_string-0f3/2constructor-05.adoc[basic_string](STRING_VIEW_LIKE_TYPE const& object); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-05.adoc[_» more..._]# Create a string that has the same value as the specified `original` string that uses the specified `basicAllocator` to supply memory. The contents of `original` are moved (in constant time) to the new string if `basicAllocator == original.get_allocator()`, and are copied (in linear time) using `basicAllocator` otherwise. `original` is left in a valid but unspecified state. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-0f.adoc[basic_string]( xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef<basic_string<char32_t>>] original, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-0f.adoc[_» more..._]# Create a string and insert (in order) each `CHAR_TYPE` object in the specified `values` initializer list. Optionally specify a `basicAllocator` used to supply memory. If `basicAllocator` is not specified, then a default‐constructed allocator is used. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-00a.adoc[basic_string]( std::initializer_list<char32_t> values, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-00a.adoc[_» more..._]# Create a string that has the same value as the specified `strRef` string. The resulting string will contain the same sequence of characters as `strRef`. Optionally specify a `basicAllocator` used to supply memory. If `basicAllocator` is not specified, then a default‐constructed allocator is used. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-07.adoc[basic_string]( xref:BloombergLP/bslstl/StringRefData-04.adoc[BloombergLP::bslstl::StringRefData<char32_t>] const& strRef, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-07.adoc[_» more..._]# Create a string that has the same value as the specified `original` string and uses the specified `basicAllocator` to supply memory. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-06f.adoc[basic_string]( xref:bsl/basic_string-0faf.adoc[basic_string<char32_t>] const& original, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-06f.adoc[_» more..._]# Create a string that has the same value as the specified `original` string, where the type `original` is the string type native to the compiler's library, instantiated with the same character type and traits type, but not necessarily the same allocator type. The resulting string will contain the same sequence of characters as `original`. Optionally specify a `basicAllocator` used to supply memory. If `basicAllocator` is not specified, then a default‐constructed allocator is used. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class ALLOC2> xref:bsl/basic_string-0f3/2constructor-009.adoc[basic_string]( std::basic_string<char32_t, char_traits<char32_t>, ALLOC2> const& original, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-009.adoc[_» more..._]# Same as the constructor taking `const CHAR_TYPE *`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class = void> requires bsl::IsStdAllocator<ALLOCATOR>::value xref:bsl/basic_string-0f3/2constructor-0b.adoc[basic_string]( char32_t const* characterString, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-0b.adoc[_» more..._]# Create a string that has the same value as the substring starting at the specified `position` in the specified `original` string. Optionally specify the `basicAllocator` used to supply memory. If `basicAllocator` is not specified, a default‐constructed allocator is used. The contents of `original` are moved (in constant time) to the new string if `basicAllocator == original.get_allocator()`, and are copied (in linear time) using `basicAllocator` otherwise. `original` is left in a valid but unspecified state. Throw `out_of_range` if `position > original.length()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-0e3.adoc[basic_string]( xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef<basic_string<char32_t>>] original, xref:bsl/basic_string-0f3/size_type.adoc[size_type] position, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-0e3.adoc[_» more..._]# Create a string that has the same value as the substring of the specified `numChars` length starting at the specified `position` in the specified `original` string. Optionally specify the `basicAllocator` used to supply memory. If `basicAllocator` is not specified, a default‐constructed allocator is used. Throw `out_of_range` if `position > original.length()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-03e.adoc[basic_string]( xref:bsl/basic_string-0faf.adoc[basic_string<char32_t>] const& original, xref:bsl/basic_string-0f3/size_type.adoc[size_type] position, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-03e.adoc[_» more..._]# Create a string that has the same value as the substring of the optionally specified `numChars` length starting at the beginning of the specified `characterString`. If `numChars` is not specified, `CHAR_TRAITS::length(characterString)` is used. Optionally specify the `basicAllocator` used to supply memory. If `basicAllocator` is not specified, a default‐constructed allocator is used. Throw `out_of_range` if `numChars >= npos`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-02.adoc[basic_string]( char32_t const* characterString, xref:bsl/basic_string-0f3/size_type.adoc[size_type] numChars, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-02.adoc[_» more..._]# Create a string from the characters in the range starting at the specified `first` iterator and ending right before the specified `last` iterator of the (template parameter) type `INPUT_ITER`. Optionally specify a `basicAllocator` used to supply memory. If `basicAllocator` is not specified, a default‐constructed allocator is used. The behavior is undefined unless `first` and `last` refer to a sequence of valid values where `first` is at a position at or before `last`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class INPUT_ITER> xref:bsl/basic_string-0f3/2constructor-06b.adoc[basic_string]( INPUT_ITER first, INPUT_ITER last, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-06b.adoc[_» more..._]# Create a string that containing the characters from the specified `range`. Optionally specify a `basicAllocator` used to supply memory. If `basicAllocator` is not specified, a default‐constructed allocator is used. Note that `range` must meet the requirements of an input range and the values from `range` must have a type matching or convertible to (template parameter) `CHAR_TYPE`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class RANGE> xref:bsl/basic_string-0f3/2constructor-0ea.adoc[basic_string]( std::from_range_t, RANGE&& range, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-0ea.adoc[_» more..._]# Same as the constructor taking `(numChars, character)`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class = void> requires bsl::IsStdAllocator<ALLOCATOR>::value xref:bsl/basic_string-0f3/2constructor-03d.adoc[basic_string]( xref:bsl/basic_string-0f3/size_type.adoc[size_type] numChars, char32_t character, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-03d.adoc[_» more..._]# Create a string that has the same value as the substring of the specified `numChars` length starting at the specified `position` in the specified `original` string. If `numChars` is more than the available string length, then the remaining length of the string is used (i.e., `numChars` is set to `original.length() ‐ position`). Optionally specify the `basicAllocator` used to supply memory. If `basicAllocator` is not specified, a default‐constructed allocator is used. The contents of `original` are moved (in constant time) to the new string if `basicAllocator == original.get_allocator()`, and are copied (in linear time) using `basicAllocator` otherwise. `original` is left in a valid but unspecified state. Throw `out_of_range` if `position > original.length()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-0c8.adoc[basic_string]( xref:BloombergLP/bslmf/MovableRef.adoc[BloombergLP::bslmf::MovableRef<basic_string<char32_t>>] original, xref:bsl/basic_string-0f3/size_type.adoc[size_type] position, xref:bsl/basic_string-0f3/size_type.adoc[size_type] numChars, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-0c8.adoc[_» more..._]# Create a string that has the same value as the substring of the specified `numChars` length starting at the specified `position` in the specified `original` string. If `numChars` equals `npos`, then the remaining length of the string is used (i.e., `numChars` is set to `original.length() ‐ position`). Optionally specify the `basicAllocator` used to supply memory. If `basicAllocator` is not specified, a default‐constructed allocator is used. Throw `out_of_range` if `position > original.length()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- xref:bsl/basic_string-0f3/2constructor-06e.adoc[basic_string]( xref:bsl/basic_string-0faf.adoc[basic_string<char32_t>] const& original, xref:bsl/basic_string-0f3/size_type.adoc[size_type] position, xref:bsl/basic_string-0f3/size_type.adoc[size_type] numChars, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-06e.adoc[_» more..._]# Create a string that has the same value as the substring of the specified `numChars` length starting at the specified `position` in the specified `object`. Optionally specify a `basicAllocator` used to supply memory. If the `basicAllocator` is not specified, a default‐constructed allocator is used. Throw `out_of_range` if `position > original.object()`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class STRING_VIEW_LIKE_TYPE> xref:bsl/basic_string-0f3/2constructor-0a.adoc[basic_string]( STRING_VIEW_LIKE_TYPE const& object, xref:bsl/basic_string-0f3/size_type.adoc[size_type] position, xref:bsl/basic_string-0f3/size_type.adoc[size_type] numChars, xref:bsl/allocator-0df.adoc[allocator<char32_t>] const& basicAllocator = ALLOCATOR()); ---- [.small]#xref:bsl/basic_string-0f3/2constructor-0a.adoc[_» more..._]# [.small]#Created with https://www.mrdocs.com[MrDocs]#