Re: FAQ 34.3

Discussion in 'C++' started by Peter van Merkerk, Jul 24, 2003.

  1. "Agent Mulder" <> wrote in message
    news:bfn3mm$v93$1.nb.home.nl...
    > Hi group,
    >
    > In FAQ 34.3 I read the following:
    >
    > In general, (...) you are guaranteed that &v[0] + n == &v[n], where v is a
    > std::vector<T> and n is an integer in the range 0 .. v.size()-1.
    >
    > However v.begin() is not guaranteed to be a T*, which means v.begin() is

    not
    > guaranteed to be the same as &v[0]:
    >
    > My question is, why is v.begin() not guaranteed to be of T* ?


    Because vector<T>::begin() returns an iterator, which may or may not be T*.
    Whether vector<T>::iterator is an alias for T* or not depends on which
    Standard Library implementation you are using and possibly on the compile
    settings (eg. debug builds or release builds). The advantage of an iterator
    object is that it may do some checking, for example to see if it is still
    valid when it is being dereferenced. A possible advantage of returning raw
    pointers is efficiency.

    --
    Peter van Merkerk
    peter.van.merkerk(at)dse.nl
    Peter van Merkerk, Jul 24, 2003
    #1
    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. Anand N [MVP]

    C# FAQ 1

    Anand N [MVP], Sep 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    628
    Anand N [MVP]
    Sep 19, 2004
  2. =?ISO-8859-15?Q?Juli=E1n?= Albo

    FAQ or not FAQ?

    =?ISO-8859-15?Q?Juli=E1n?= Albo, Jan 8, 2007, in forum: C++
    Replies:
    28
    Views:
    836
    Grizlyk
    Jan 15, 2007
  3. Josef 'Jupp' Schugt
    Replies:
    0
    Views:
    184
    Josef 'Jupp' Schugt
    Sep 22, 2003
  4. FAQ server

    FAQ - How do I direct someone to this FAQ?

    FAQ server, Aug 4, 2006, in forum: Javascript
    Replies:
    1
    Views:
    145
    Dr John Stockton
    Aug 4, 2006
  5. Peter Michaux

    FAQ/FAQ notes site makeover

    Peter Michaux, Nov 22, 2006, in forum: Javascript
    Replies:
    22
    Views:
    329
    Randy Webb
    Nov 27, 2006
Loading...

Share This Page