Title
std::string{}.insert(3, "ABCDE", 0, 1) is ambiguous
Status
resolved
Section
[string.insert]
Submitter
Marshall Clow

Created on 2016-07-30.00:00:00 last changed 98 months ago

Messages

Date: 2016-10-10.20:46:47

Proposed resolution:

This issue is resolved by the proposed wording for LWG 2758.

Date: 2017-02-02.00:41:18

[ 2016-10 Telecon ]

Ville's wording for 2758 has been implemented in libstdc++ and libc++. Move 2758 to Tentatively Ready and this one to Tentatively Resolved

Date: 2016-09-09.00:00:00

[ 2016-09-09 Issues Resolution Telecon ]

Since 2758 has been moved back to Open, move this one, too

Date: 2016-08-06.21:12:20

[ 08-2016, Chicago ]

Fri PM: Move to Tentatively Ready (along with 2758).

Date: 2016-08-15.00:00:00

[ 2016-08-04, Chicago, Robert Douglas comments ]

For the sake of simplicity, the previous wording suggestion has been merged into the proposed wording of LWG 2758.

Date: 2016-08-15.00:00:00

[ 2016-08-03, Chicago, Robert Douglas provides wording ]

Previous resolution [SUPERSEDED]:

This wording is relative to N4606.

  1. In [basic.string] modify the synopsis for basic_string as follows:

    namespace std {
      template<class charT, class traits = char_traits<charT>,
        class Allocator = allocator<charT>>
      class basic_string {
      public:
        […]
        template<class T>
        basic_string& insert(size_type pos1, basic_string_view<charT, traits>T sv,
                             size_type pos2, size_type n = npos);
        […]
      };
    }
    
  2. In [string.insert], modify basic_string_view overload as follows:

    template<class T>
    basic_string& insert(size_type pos1, basic_string_view<charT, traits>T sv,
                         size_type pos2, size_type n = npos);
    

    […]

    -?- Remarks: This function shall not participate in overload resolution unless is_same_v<T, basic_string_view<charT, traits>> is true.

Date: 2016-07-30.19:12:58

Before C++17, we had the following signature to std::basic_string:

basic_string&
  insert(size_type pos1, const basic_string& str, size_type pos2, size_type n = npos);

Unlike most of the other member functions on std::basic_string, there were not corresponding versions that take a charT* or (charT *, size).

In p0254r2, we added:

basic_string&
  insert(size_type pos1, basic_string_view<charT, traits> sv, size_type pos2, size_type n = npos);

which made the code above ambiguous. There are two conversions from "const charT*", one to basic_string, and the other to basic_string_view, and they're both equally good (in the view of the compiler).

This ambiguity also occurs with the calls

assign(const basic_string& str,             size_type pos, size_type n = npos);
assign(basic_string_view<charT, traits> sv, size_type pos, size_type n = npos);

but I will file a separate issue (2758) for that.

A solution is to add even more overloads to insert, to make it match all the other member functions of basic_string, which come in fours (string, pointer, pointer + size, string_view).

History
Date User Action Args
2016-10-10 20:46:47adminsetmessages: + msg8552
2016-10-10 20:46:47adminsetstatus: open -> resolved
2016-09-12 04:46:33adminsetmessages: + msg8518
2016-09-12 04:46:33adminsetstatus: ready -> open
2016-08-06 21:12:20adminsetmessages: + msg8449
2016-08-06 21:12:20adminsetstatus: new -> ready
2016-08-05 16:56:25adminsetmessages: + msg8425
2016-08-03 22:01:08adminsetmessages: + msg8378
2016-07-30 16:06:49adminsetmessages: + msg8270
2016-07-30 00:00:00admincreate