Constructors

Synopses

Declared in <bslstl_string.h>

Create an empty string using a default‐constructed allocator.

basic_string() noexcept;

A string cannot be constructed from a nullptr or from a literal 0.

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.

Create an empty string. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, a default‐constructed allocator is used.

explicit
basic_string(allocator<char16_t> const& basicAllocator) noexcept;

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.

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.

template<class STRING_VIEW_LIKE_TYPE>
explicit
basic_string(STRING_VIEW_LIKE_TYPE const& object);

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.

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.

basic_string(
    std::initializer_list<char16_t> values,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

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.

basic_string(
    BloombergLP::bslstl::StringRefData<char16_t> const& strRef,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

Create a string that has the same value as the specified original string and uses the specified basicAllocator to supply memory.

basic_string(
    basic_string<char16_t> const& original,
    allocator<char16_t> const& basicAllocator);

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.

template<class ALLOC2>
basic_string(
    std::basic_string<char16_t, char_traits<char16_t>, ALLOC2> const& original,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

Same as the constructor taking const CHAR_TYPE *.

template<class = void>
requires bsl::IsStdAllocator<ALLOCATOR>::value
basic_string(
    char16_t const* characterString,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

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().

basic_string(
    BloombergLP::bslmf::MovableRef<basic_string<char16_t>> original,
    size_type position,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

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().

basic_string(
    basic_string<char16_t> const& original,
    size_type position,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

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.

basic_string(
    char16_t const* characterString,
    size_type numChars,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

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.

template<class INPUT_ITER>
basic_string(
    INPUT_ITER first,
    INPUT_ITER last,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

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.

template<class RANGE>
basic_string(
    std::from_range_t,
    RANGE&& range,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

Same as the constructor taking (numChars, character).

template<class = void>
requires bsl::IsStdAllocator<ALLOCATOR>::value
basic_string(
    size_type numChars,
    char16_t character,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

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().

basic_string(
    BloombergLP::bslmf::MovableRef<basic_string<char16_t>> original,
    size_type position,
    size_type numChars,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

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().

basic_string(
    basic_string<char16_t> const& original,
    size_type position,
    size_type numChars,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

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().

template<class STRING_VIEW_LIKE_TYPE>
basic_string(
    STRING_VIEW_LIKE_TYPE const& object,
    size_type position,
    size_type numChars,
    allocator<char16_t> const& basicAllocator = ALLOCATOR());

Created with MrDocs