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

Discussion in 'C++' started by magnus.moraberg@gmail.com, Jan 15, 2009.

  1. Guest

    Hi there,

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

    Thanks,

    Barry
    , Jan 15, 2009
    #1
    1. Advertising

  2. Kai-Uwe Bux Guest

    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
    Kai-Uwe Bux, Jan 15, 2009
    #2
    1. Advertising

  3. <> wrote in message
    news:...

    > 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.
    Andrew Koenig, Feb 9, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lynn
    Replies:
    11
    Views:
    653
    Default User
    Dec 15, 2004
  2. Replies:
    8
    Views:
    1,914
    Csaba
    Feb 18, 2006
  3. Javier
    Replies:
    2
    Views:
    559
    James Kanze
    Sep 4, 2007
  4. Replies:
    4
    Views:
    363
  5. daniele.g
    Replies:
    4
    Views:
    478
    Joe Pfeiffer
    Jul 15, 2011
Loading...

Share This Page