Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > const vector<const MyType> Vs const vector<MyType>

Reply
Thread Tools

const vector<const MyType> Vs const vector<MyType>

 
 
magnus.moraberg@gmail.com
Guest
Posts: n/a
 
      01-15-2009
Hi there,

what is the difference between const vector<const MyType> and const
vector<MyType>?

Thanks,

Barry
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      01-15-2009
wrote:

> Hi there,
>
> what is the difference between const vector<const MyType> and const
> vector<MyType>?


A vector< MyType const > (const or not) invokes undefined behavior since
MyType const does not satisfy the Assignable requirement for containers. On
the other hand, vector<MyType> has this problem only if MyType does not
satisfy the requirements. If you have a good STL implementation, something
like vector< MyType const > might not even compile since concept checks
would fail.

As for const vector<X>, well, it's const: you can only call const methods on
it, which implies that you cannot change the contents of the vector after
construction (which leaves the constructor taking a range of two iterators
as the only interesting way of creating such a critter).


Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
 
Andrew Koenig
Guest
Posts: n/a
 
      02-09-2009
<> wrote in message
news:b1eb5062-2bae-4df3-9b4a-...

> what is the difference between const vector<const MyType> and const
> vector<MyType>?


For one thing, const vector<const MyType> is not legal because the element
type is not assignable.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
is const necessary in eg int compar(const void *, const void *) lovecreatesbeauty@gmail.c0m C Programming 26 11-10-2008 09:47 PM
const correctness - should C++ prefer const member over non-const? fungus C++ 13 10-31-2008 05:33 AM
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Casting int'** to 'const int * const * const' dosn't work, why? Jonas.Holmsten@gmail.com C Programming 11 07-01-2007 06:16 PM
const references -- how to document intent of const qualification Andrew R. Thomas-Cramer Java 8 07-11-2003 05:01 PM



Advertisments