Title
Broken Effects of some basic_string::compare functions in terms of basic_string_view
Status
c++17
Section
[string.compare]
Submitter
Daniel Krügler

Created on 2016-09-05.00:00:00 last changed 90 months ago

Messages

Date: 2016-10-10.20:46:47

Proposed resolution:

This wording is relative to N4606.

[Drafting note: The wording changes below are for the same part of the standard as 2758. However, they do not conflict. This one changes the "Effects" of the routine, while the other changes the definition. — end drafting note]

  1. Change [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));
    
Date: 2017-02-02.00:41:18

[ 2016-10 Issues Resolution Telecon ]

Marshall reports that P/R is better. Status to Tentatively Ready

Date: 2016-09-09.00:00:00

[ 2016-09-09 Issues Resolution Telecon ]

Marshall to investigate using P/R vs. adding the missing constructor.

Date: 2016-09-05.00:00:00

Some basic_string::compare functions are specified in terms of a non-existing basic_string_view constructor, namely [string.compare] p3,

return basic_string_view<charT, traits>(this.data(), pos1, n1).compare(sv);

and [string.compare] p4:

return basic_string_view<charT, traits>(this.data(), pos1, n1).compare(sv, pos2, n2);

because there doesn't exist a basic_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, that basic_string doesn't provide this constructor either.

Another problem is related to the specification of [string.compare] p4, which attempts to call a non-existing basic_string_view::compare overload that would match the signature:

constexpr int compare(basic_string_view str, size_type pos1, size_type n1) const;
History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2016-11-14 03:59:28adminsetstatus: pending -> wp
2016-11-14 03:55:22adminsetstatus: ready -> pending
2016-10-10 20:46:47adminsetmessages: + msg8556
2016-10-10 20:46:47adminsetstatus: new -> ready
2016-09-12 04:36:33adminsetmessages: + msg8512
2016-09-06 19:38:50adminsetmessages: + msg8501
2016-09-05 00:00:00admincreate