This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++17 status.
basic_string::compare functions in terms ofbasic_string_viewSection: 27.4.3.8.4[string.compare]Status:C++17Submitter: Daniel KrüglerOpened: 2016-09-05Last modified: 2017-07-30
Priority:1
View all issues withC++17 status.
Discussion:
Somebasic_string::compare functions are specified in terms of a non-existingbasic_string_viewconstructor, namely 27.4.3.8.4[string.compare] p3,
return basic_string_view<charT, traits>(this.data(), pos1, n1).compare(sv);
and 27.4.3.8.4[string.compare] p4:
return basic_string_view<charT, traits>(this.data(), pos1, n1).compare(sv, pos2, n2);
because there doesn't exist abasic_string_view constructor with three arguments.
constexpr basic_string_view(const charT* str, size_type len);
with the additional member function
constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
it should be decided whether adding the seemingly natural constructor
constexpr basic_string_view(const charT* str, size_type pos, size_type n);
could simplify matters. A counter argument for this addition might be, thatbasic_stringdoesn't provide this constructor either.
basic_string_view::compare overload that would match the signature:constexpr int compare(basic_string_view str, size_type pos1, size_type n1) const;
[2016-09-09 Issues Resolution Telecon]
Marshall to investigate using P/R vs. adding the missing constructor.
[2016-10 Issues Resolution Telecon]
Marshall reports that P/R is better. Status to Tentatively Ready
Proposed resolution:
This wording is relative to N4606.
[Drafting note: The wording changes below are for the same part of the standard as2758(i). However, they do not conflict. This one changes the "Effects" of the routine, while the other changes the definition.—end drafting note]
Change 27.4.3.8.4[string.compare] as indicated:
int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;-3-Effects: Equivalent to:
return basic_string_view<charT, traits>(this.data(),size()).substr(pos1, n1).compare(sv);int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv, size_type pos2, size_type n2 = npos) const;-4-Effects: Equivalent to:
return basic_string_view<charT, traits>(this.data(),size()).substr(pos1, n1).compare(sv,.substr(pos2, n2));