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.

2585.forward_list::resize(size_type, const value_type&) effects incorrect

Section: 23.3.7.5[forward.list.modifiers]Status:C++17Submitter: Tim SongOpened: 2016-01-14Last modified: 2023-02-07

Priority:0

View all otherissues in [forward.list.modifiers].

View all issues withC++17 status.

Discussion:

[forwardlist.modifiers]/29 says that the effects offorward_list::resize(size_type sz, const value_type& c) are:

Effects: Ifsz < distance(begin(), end()), erases the lastdistance(begin(), end()) - sz elementsfrom the list. Otherwise, insertssz - distance(begin(), end()) elements at the end ofthe list such that each new element,e, is initialized by a method equivalent to callingallocator_traits<allocator_type>::construct(get_allocator(), std::addressof(e), c).

In light of LWG2218(i), the use ofallocator_traits<allocator_type>::construct is incorrect, as a rebound allocator may be used. There's no need to repeat this information, in any event — no other specification ofresize() does it.

[2016-02, Issues Telecon]

P0; move to Tentatively Ready.

[2016-02-11, Alisdair requests reopening]

I believe the standard is correct as written, and that by removing the clear directionto make the copy with uses-allocator-construction, we open ourselves to disputingthis very point again at some point in the future.

The issue seems to be complaining that a rebound allocator may be used instead ofthe allocator returned byget_allocator() call, and nailing us down to exactly whichinstantiation ofallocator_traits is used. Given the requirements on allocators beingconstructible from within the same template "family" though, and specifically thatcopies compare equal and can allocate/deallocate on each other's behalf, this shouldclearly fall under existing as-if freedom. The construct call is even more clear, asthere is no requirement that the allocator to construct be of a kind that can allocatethe specific type being constructed — a freedom granted precisely so this kind of codecan be written, and be correct, regardless of internal node type of any container andthe actual rebound allocator used internally.

I think the new wording is less clear than the current wording, and would prefer toresolve as NAD.

Proposed resolution:

This wording is relative to N4567.

  1. Edit [forwardlist.modifiers]/29 as indicated:

    [Drafting note: "copies ofc" is the phrase used byvector::resize anddeque::resize.]

    void resize(size_type sz, const value_type& c);

    -29-Effects: Ifsz < distance(begin(), end()), erases the lastdistance(begin(), end()) - sz elementsfrom the list. Otherwise, insertssz - distance(begin(), end())elementscopies ofc at the end of the listsuch that each new element,e, is initialized by a method equivalent to callingallocator_traits<allocator_type>::construct(get_allocator(), std::addressof(e), c).


[8]ページ先頭

©2009-2026 Movatter.jp