]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/doc/html/manual/bk01pt08ch19.html
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / doc / html / manual / bk01pt08ch19.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Chapter 19. Predefined</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      library&#10;    " /><link rel="start" href="../spine.html" title="The GNU C++ Library Documentation" /><link rel="up" href="iterators.html" title="Part VIII. Iterators" /><link rel="prev" href="iterators.html" title="Part VIII. Iterators" /><link rel="next" href="bk01pt08ch19s02.html" title="One Past the End" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 19. Predefined</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="iterators.html">Prev</a> </td><th width="60%" align="center">Part VIII. Iterators</th><td width="20%" align="right"> <a accesskey="n" href="bk01pt08ch19s02.html">Next</a></td></tr></table><hr /></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="manual.iterators.predefined"></a>Chapter 19. Predefined</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="bk01pt08ch19.html#iterators.predefined.vs_pointers">Iterators vs. Pointers</a></span></dt><dt><span class="sect1"><a href="bk01pt08ch19s02.html">One Past the End</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="iterators.predefined.vs_pointers"></a>Iterators vs. Pointers</h2></div></div></div><p><a class="ulink" href="../faq/index.html#5_1" target="_top">FAQ 5.1</a> points out that iterators
4       are not implemented as pointers.  They are a generalization of
5       pointers, but they are implemented in libstdc++ as separate classes.
6    </p><p>Keeping that simple fact in mind as you design your code will
7       prevent a whole lot of difficult-to-understand bugs.
8    </p><p>You can think of it the other way 'round, even.  Since iterators
9       are a generalization, that means that <span class="emphasis"><em>pointers</em></span> are
10       <span class="emphasis"><em>iterators</em></span>, and that pointers can be used whenever an
11       iterator would be.  All those functions in the Algorithms chapter
12       of the Standard will work just as well on plain arrays and their
13       pointers.
14    </p><p>That doesn't mean that when you pass in a pointer, it gets wrapped
15       into some special delegating iterator-to-pointer class with a layer
16       of overhead.  (If you think that's the case anywhere, you don't
17       understand templates to begin with...)  Oh, no; if you pass
18       in a pointer, then the compiler will instantiate that template
19       using T* as a type, and good old high-speed pointer arithmetic as
20       its operations, so the resulting code will be doing exactly the same
21       things as it would be doing if you had hand-coded it yourself (for
22       the 273rd time).
23    </p><p>How much overhead <span class="emphasis"><em>is</em></span> there when using an iterator class?
24       Very little.  Most of the layering classes contain nothing but
25       typedefs, and typedefs are "meta-information" that simply
26       tell the compiler some nicknames; they don't create code.  That
27       information gets passed down through inheritance, so while the
28       compiler has to do work looking up all the names, your runtime code
29       does not.  (This has been a prime concern from the beginning.)
30    </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="iterators.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="iterators.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk01pt08ch19s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Part VIII. Iterators </td><td width="20%" align="center"><a accesskey="h" href="../spine.html">Home</a></td><td width="40%" align="right" valign="top"> One Past the End</td></tr></table></div></body></html>