Home > Backend Development > C++ > Can C 11 Vectors Hold `const T` Elements?

Can C 11 Vectors Hold `const T` Elements?

Patricia Arquette
Release: 2025-01-02 21:17:39
Original
259 people have browsed it

Can C  11 Vectors Hold `const T` Elements?

Does C 11 Permit vector?

In C 11, container requirements have undergone significant revisions. Unlike C 03, which imposed blanket requirements on containers, C 11 specifies finely-grained requirements for each container operation.

This change allows types that are copy-constructible but not assignable—such as structures with const members—to be stored in vectors, provided that only certain operations are performed.

However, does this imply that C 11 permits vector?

Answer

No. Despite similarities to structures with const members, const T is not a permissible element type according to the allocator requirements, which stipulate "non-const, non-reference object type."

Implication

Creating a vector of constant objects would be impractical, and a const vector would offer similar functionality.

The above is the detailed content of Can C 11 Vectors Hold `const T` Elements?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template