Movatterモバイル変換


[0]ホーム

URL:



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

42. String ctors specify wrong default allocator

Section: 27.4.3[basic.string]Status:TC1Submitter: Nathan MyersOpened: 1998-08-06Last modified: 2016-01-28

Priority:Not Prioritized

View otheractive issues in [basic.string].

View all otherissues in [basic.string].

View all issues withTC1 status.

Discussion:

The basic_string<> copy constructor:

basic_string(const basic_string& str, size_type pos = 0,             size_type n = npos, const Allocator& a = Allocator());

specifies an Allocator argument default value that iscounter-intuitive. The natural choice for a the allocator to copy fromis str.get_allocator(). Though this cannot be expressed indefault-argument notation, overloading suffices.

Alternatively, the other containers in Clause 23 (deque, list,vector) do not have this form of constructor, so it is inconsistent,and an evident source of confusion, for basic_string<> to haveit, so it might better be removed.

Proposed resolution:

In 27.4.3[basic.string], replace the declaration of the copyconstructor as follows:

basic_string(const basic_string& str);basic_string(const basic_string& str, size_type pos, size_type n = npos,             const Allocator& a = Allocator());

In 27.4.3.2[string.require], replace the copy constructor declarationas above. Add to paragraph 5, Effects:

In the first form, the Allocator value used is copied fromstr.get_allocator().

Rationale:

The LWG believes the constructor is actually broken, rather thanjust an unfortunate design choice.

The LWG considered two other possible resolutions:

A. In 27.4.3[basic.string], replace the declaration of the copyconstructor as follows:

basic_string(const basic_string& str, size_type pos = 0,             size_type n = npos);basic_string(const basic_string& str, size_type pos,             size_type n, const Allocator& a);

In 27.4.3.2[string.require], replace the copy constructor declarationas above. Add to paragraph 5, Effects:

When noAllocator argument is provided, the string is constructed using the valuestr.get_allocator().

B. In 27.4.3[basic.string], and also in 27.4.3.2[string.require], replacethe declaration of the copy constructor as follows:

basic_string(const basic_string& str, size_type pos = 0,             size_type n = npos);

The proposed resolution reflects the original intent of the LWG. Itwas also noted by Pete Becker that this fix "will causea small amount of existing code to now work correctly."

[Kona: issue editing snafu fixed - the proposed resolution now correctlyreflects the LWG consensus.]


[8]ページ先頭

©2009-2026 Movatter.jp