2777. basic_string_view::copy should use char_traits::copy

Section: 27.3.3.8 [string.view.ops], 27.4.3.7.7 [string.copy] Status: C++17 Submitter: Billy Robert O'Neal III Opened: 2016-09-27 Last modified: 2017-07-30

Priority: 0

View all other issues in [string.view.ops].

View all issues with C++17 status.

Discussion:

basic_string_view::copy is inconsistent with basic_string::copy, in that the former uses copy_n and the latter uses traits::copy. We should have this handling be consistent.

Moreover, the basic_string::copy description is excessively roundabout due to copy-on-write era wording.

[Issues processing Telecon 2016-10-7]

P0; set to Tentatively Ready

Removed "Note to project editor", since the issue there has been fixed in the current draft.

Proposed resolution:

This wording is relative to N4606.

  1. Change 27.4.3.7.7 [string.copy] as indicated:

    size_type copy(charT* s, size_type n, size_type pos = 0) const;
    

    -?- Let rlen be the smaller of n and size() - pos.

    -2- Throws: out_of_range if pos > size().

    -?- Requires: [s, s + rlen) is a valid range.

    -3- Effects: Determines the effective length rlen of the string to copy as the smaller of n and size() - pos. s shall designate an array of at least rlen elements.Equivalent to: traits::copy(s, data() + pos, rlen). [Note: This does not terminate s with a null object. — end note]

    The function then replaces the string designated by s with a string of length rlen whose elements are a copy of the string controlled by *this beginning at position pos.

    The function does not append a null object to the string designated by s.

    -4- Returns: rlen.

  2. Change 27.3.3.8 [string.view.ops] as indicated:

    size_type copy(charT* s, size_type n, size_type pos = 0) const;
    

    -1- Let rlen be the smaller of n and size() - pos.

    -2- Throws: out_of_range if pos > size().

    -3- Requires: [s, s + rlen) is a valid range.

    -4- Effects: Equivalent to: copy_n(begin() + pos, rlen, s)traits::copy(s, data() + pos, rlen)

    -5- Returns: rlen.

    -6- Complexity: 𝒪(rlen).