Skip to content

[vector.capacity] p14 The precondition use "and" but should use "or" #5776

@xmh0511

Description

@xmh0511

[vector.capacity] p14 says

constexpr void resize(size_type sz);

Preconditions: T is Cpp17MoveInsertable and Cpp17DefaultInsertable into *this.

Cpp17MoveInsertable is defined in [containers.container.alloc.reqmts] p2.3

T is Cpp17MoveInsertable into X means that the following expression is well-formed:

  • allocator_traits::construct(m, p, RV)

[containers.container.alloc.reqmts] p2 says

given an lvalue m of type A, a pointer p of type T*, an expression v of type (possibly const) T, and an rvalue rv of type T,

Consider this example:

struct A{
   A() = default;
   A(A const&) = default;
   A(A&&) = delete;
};
int main(){
   std::vector<A> vec{};
   vec.resize(10); // ok
}

However, A is not Cpp17MoveInsertable since allocator_traits<A>::construct(m, p, RV) is ill-formed for A.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions