Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: FAQ 34.3

Reply
Thread Tools

Re: FAQ 34.3

 
 
Peter van Merkerk
Guest
Posts: n/a
 
      07-23-2003
"Agent Mulder" <(E-Mail Removed)> wrote in message
news:bfn3mm$v93$(E-Mail Removed)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



 
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
FAQ or not FAQ? =?ISO-8859-15?Q?Juli=E1n?= Albo C++ 28 01-15-2007 04:33 AM
FAQ/FAQ notes site makeover Peter Michaux Javascript 22 11-27-2006 01:55 AM
FAQ - How do I direct someone to this FAQ? FAQ server Javascript 1 08-04-2006 10:13 PM
Upgrading to high speed, FAQ? David Wireless Networking 4 11-09-2004 08:43 PM
[de] Update of FAQ in German/FAQ auf Deutsch ueberarbeitet Josef 'Jupp' Schugt Ruby 0 09-22-2003 08:56 PM



Advertisments