Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6218057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:32:19+00:00 2026-05-24T07:32:19+00:00

Container requirements have changed from C++03 to C++11. While C++03 had blanket requirements (e.g.

  • 0

Container requirements have changed from C++03 to C++11. While C++03 had blanket requirements (e.g. copy constructibility and assignability for vector), C++11 defines fine-grained requirements on each container operation (section 23.2).

As a result, you can e.g. store a type that is copy-constructible but not assignable – such as a structure with a const member – in a vector as long as you only perform certain operations that do not require assignment (construction and push_back are such operations; insert is not).

What I’m wondering is: does this mean the standard now allows vector<const T>? I don’t see any reason it shouldn’t – const T, just like a structure with a const member, is a type that is copy constructible but not assignable – but I may have missed something.

(Part of what makes me think I may have missed something, is that gcc trunk crashes and burns if you try to instantiate vector<const T>, but it’s fine with vector<T> where T has a const member).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:32:20+00:00Added an answer on May 24, 2026 at 7:32 am

    No, I believe the allocator requirements say that T can be a “non-const, non-reference object type”.

    You wouldn’t be able to do much with a vector of constant objects. And a const vector<T> would be almost the same anyway.


    Many years later this quick-and-dirty answer still seems to be attracting comments and votes. Not always up. 🙂

    So to add some proper references:

    For the C++03 standard, which I have on paper, Table 31 in section [lib.allocator.requirements] says:

    T, U any type

    Not that any type actually worked.

    So, the next standard, C++11, says in a close draft in [allocator.requirements] and now Table 27:

    T, U, C any non-const, non-reference object type

    which is extremely close to what I originally wrote above from memory. This is also what the question was about.

    However, in C++14 (draft N4296) Table 27 now says:

    T, U, C any non-const object type

    Possibly because a reference perhaps isn’t an object type after all?

    And now in C++17 (draft N4659) it is Table 30 that says:

    T, U, C any cv-unqualified object type (6.9)

    So not only is const ruled out, but also volatile. Probably old news anyway, and just a clarification.


    Please also see Howard Hinnant’s first-hand info, currently right below.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have requirements from our client where we basically have to 'parse' PDF files
$(.container).hover( function(){ $(.child-1).hide(0); $(.child-2).show(0); },function(){ $(.child-1).show(0); $(.child-2).hide(0); }); A project I have requires that
I have a container div with a fixed width and height , with overflow:
I have a container div that holds two internal divs; both should take 100%
I have a div container and have defined its style as follows: div#tbl-container {
I have these ViewModels: RecordViewModel, ComponentViewModel where RecordViewModel essentially is a container for several
I have a model for a User generated by EF from an existing database:
I have been using LINQ to SQL for the last year and have had
My application is currently displaying negative numbers as -1. The users have changed the
I have a process that bulk inserts into a table from a CSV. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.