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 7754109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:13:31+00:00 2026-06-01T12:13:31+00:00

std::vector<const int> vci; vci.push_back(1); vci[0] = 2; With the element type being const int

  • 0
std::vector<const int> vci;
vci.push_back(1);
vci[0] = 2;

With the element type being const int, shouldn’t the assignment statement be assigning to a const int&? This does not compile with LLVM 3.0. Why does VC++ allow it?

  • 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-06-01T12:13:32+00:00Added an answer on June 1, 2026 at 12:13 pm

    While it is Undefined Behavior and basically anything can happen including what you are seeing, I have tracked this to what seems to be an incompatibility of the library with the standard. In particular the standard allocator defined in the VS2010 library does not conform with the standard.

    The standard dictates that std::vector<T,Allocator>::value_type is a typedef to Allocator::value_type. Now the default allocator (if none is provided) is std::allocator<T> for which value_type, according to Table 28 must be Identical to T. Now the implementation of the standard allocator in VS2010 drops the const qualifier from the type argument, so std::allocator<const T>::value_type is T, and not const T.

    It is important to note that the compiler is not non-conformant for accepting the code that you provided per-se, since it is Undefined Behavior and the compiler is free to do as it pleases. But on the other hand, there is a non-conformity in the std::allocator implementation.

    You have already answered the question yourself: It is Undefined Behavior. The compiler does not need to provide a diagnostic, and the result of the operation can be anything. It is a case of quality of implementation to detect that the type is not assignable and provide a meaningful error message (or not)

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

Sidebar

Related Questions

struct G{ G&operator()(const int**a) { v<<a; std::copy(v.begin(),v.end(),std::ostream_iterator<int>(std::cout, )); return *this; } friend std::vector<int>&operator<<(std::vector<int>&v,const int**
Given std::vector<CMyClass> objects; CMyClass list[MAX_OBJECT_COUNT]; Is it wise to do this? for(unsigned int i
I have a simple class like this: class A { public: void f(const int&
template<class T> struct broker { typedef T typeBroker; static std::vector<std::string> extractListBroker(const std::string& broker) {
Based on http://www.cplusplus.com/reference/stl/vector/vector/ explicit vector ( const Allocator& = Allocator() ); This vector constructor
I'd like to do the following: const int someInt; const std::vector<int> someIntList; const std::vector<std::vector<int>>
I'll start with the code: typedef std::vector<unsigned char> CharBuf; static const int RCV_BUF_SIZE =
Is there an elegant way to create and initialize a const std::vector<const T> like
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I need to find an element position in an std::vector to use it for

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.