Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++17 status.

2771. BrokenEffects of somebasic_string::compare functions in terms ofbasic_string_view

Section: 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.

Albeit this can be easily fixed by a proper combination of the existing constructor

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.

Another problem is related to the specification of 27.4.3.8.4[string.compare] p4, which attempts tocall a non-existingbasic_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]

  1. 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));

[8]ページ先頭

©2009-2026 Movatter.jp