aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/docs/html/ext/howto.html
blob: 33128726bbebd9e8b11c7083abe07b73f7db0513 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="AUTHOR" CONTENT="pme@sources.redhat.com (Phil Edwards)">
   <META NAME="KEYWORDS" CONTENT="HOWTO, libstdc++, GCC, g++, libg++, STL">
   <META NAME="DESCRIPTION" CONTENT="Notes for the libstdc++ extensions.">
   <META NAME="GENERATOR" CONTENT="vi and eight fingers">
   <TITLE>libstdc++-v3 HOWTO:  Extensions</TITLE>
<LINK REL=StyleSheet HREF="../lib3styles.css">
<!-- $Id: howto.html,v 1.1.4.1 2001/05/14 19:48:58 bkoz Exp $ -->
</HEAD>
<BODY>

<H1 CLASS="centered"><A NAME="top">Extensions</A></H1>

<P>Here we will make an attempt at describing the non-Standard extensions to
   the library.  Some of these are from SGI's STL, some of these are GNU's,
   and some just seemed to appear on the doorstep.
</P>
<P><B>Before you leap in and use these</B>, be aware of two things:
   <OL>
    <LI>Non-Standard means exactly that.  The behavior, and the very
        existence, of these extensions may change with little or no
        warning.  (Ideally, the really good ones will appear in the next
        revision of C++.)  Also, other platforms, other compilers, other
        versions of g++ or libstdc++-v3 may not recognize these names, or
        treat them differently, or...
    <LI>You should know how to <A HREF="../faq/index.html#5_4">access
        these headers properly</A>.
   </OL>
</P>


<!-- ####################################################### -->
<HR>
<H1>Contents</H1>
<UL>
   <LI><A HREF="#1">Ropes and trees and hashes, oh my!</A>
   <LI><A HREF="#2">Added members</A>
   <LI><A HREF="#3">Allocators</A>
   <LI><A HREF="#4">Compile-time checks</A>
</UL>

<HR>

<!-- ####################################################### -->

<H2><A NAME="1">Ropes and trees and hashes, oh my!</A></H2>
   <P>The SGI headers
     <PRE>
     &lt;bvector&gt;
     &lt;hash_map&gt;
     &lt;hash_set&gt;
     &lt;rope&gt;
     &lt;slist&gt;
     &lt;tree&gt;
     </PRE> are all here; <TT>&lt;bvector&gt;</TT> exposes the old bit_vector
      class that was used before specialization of vector&lt;bool&gt; was
      available (it's actually a typedef for the specialization now).
      <TT>&lt;hash_map&gt;</TT> and <TT>&lt;hash_set&gt;</TT>
      are discussed further below.  <TT>&lt;rope&gt;</TT> is the SGI
      specialization for large strings (&quot;rope,&quot; &quot;large
      strings,&quot; get it?  love those SGI folks).
      <TT>&lt;slist&gt;</TT> is a singly-linked list, for when the
      doubly-linked <TT>list&lt;&gt;</TT> is too much space overhead, and
      <TT>&lt;tree&gt;</TT> exposes the red-black tree classes used in the
      implementation of the standard maps and sets.
   </P>
   <P>Okay, about those hashing classes...  I'm going to foist most of the
      work off onto SGI's own site.
   </P>
   <P>Each of the associative containers map, multimap, set, and multiset
      have a counterpart which uses a
      <A HREF="http://www.sgi.com/Technology/STL/HashFunction.html">hashing
      function</A> to do the arranging, instead of a strict weak ordering
      function.  The classes take as one of their template parameters a
      function object that will return the hash value; by default, an
      instantiation of
      <A HREF="http://www.sgi.com/Technology/STL/hash.html">hash</A>.
      You should specialize this functor for your class, or define your own,
      before trying to use one of the hashing classes.
   </P>
   <P>The hashing classes support all the usual associative container
      functions, as well as some extra constructors specifying the number
      of buckets, etc.
   </P>
   <P>Why would you want to use a hashing class instead of the
      &quot;normal&quot; implementations?  Matt Austern writes:
      <BLOCKQUOTE><EM>[W]ith a well chosen hash function, hash tables
      generally provide much better average-case performance than binary
      search trees, and much worse worst-case performance.  So if your
      implementation has hash_map, if you don't mind using nonstandard
      components, and if you aren't scared about the possibility of
      pathological cases, you'll probably get better performance from
      hash_map.</EM></BLOCKQUOTE>
   </P>
   <P>(Side note:  for those of you wondering, <B>&quot;Why wasn't a hash
      table included in the Standard in the first #!$@ place?&quot;</B> I'll
      give a quick answer:  it was proposed, but too late and in too
      unorganized a fashion.  Some sort of hashing will undoubtedly be
      included in a future Standard.
   </P>
   <P>Return <A HREF="#top">to top of page</A> or
      <A HREF="../faq/index.html">to the FAQ</A>.
   </P>

<HR>
<H2><A NAME="2">Added members</A></H2>
   <P>Some of the classes in the Standard Library have additional
      publicly-available members.  Of those, some are intended purely for
      the implementors, for example, additional typedefs.  Those won't be
      described here (or anywhere else).  This list will grow slowly, since
      we expect it to be rare -- most extensions will be self-contained.
   </P>
   <P>
    <UL>
     <LI><TT>filebuf</TT>s have another ctor with this signature:<BR>
<TT>basic_filebuf(__c_file_type*, ios_base::openmode, int_type);</TT>
         <BR>This comes in very handy in a number of places, such as
         attaching Unix sockets, pipes, and anything else which uses file
         descriptors, into the IOStream buffering classes.  The three
         arguments are as follows:
         <UL>
          <LI><TT>__c_file_type*      F   </TT>
              // the __c_file_type typedef usually boils down to stdio's FILE
          <LI><TT>ios_base::openmode  M   </TT>
              // same as all the other uses of openmode
          <LI><TT>int_type            B   </TT>
              // buffer size, defaults to BUFSIZ
         </UL>
         For those wanting to use file descriptors instead of FILE*'s, I
         invite you to contemplate the mysteries of C's <TT>fdopen()</TT>.
    </UL>
   </P>
   <P>Return <A HREF="#top">to top of page</A> or
      <A HREF="../faq/index.html">to the FAQ</A>.
   </P>

<HR>
<H2><A NAME="3">Allocators</A></H2>
   <P>This will be blank for a while.  It will describe all of the different
      memory allocators, most inherited from SGI's code.  Input is solicited.
   </P>
   <P>Return <A HREF="#top">to top of page</A> or
      <A HREF="../faq/index.html">to the FAQ</A>.
   </P>

<HR>
<H2><A NAME="4">Compile-time checks</A></H2>
   <P>Currently libstdc++-v3 uses the concept checkers from the Boost
      library to perform <A HREF="../19_diagnostics/howto.html#3">optional
      compile-time checking</A> of template instantiations of the standard
      containers.  They are described in the linked-to page.
   </P>
   <P>Return <A HREF="#top">to top of page</A> or
      <A HREF="../faq/index.html">to the FAQ</A>.
   </P>




<!-- ####################################################### -->

<HR>
<P CLASS="fineprint"><EM>
Comments and suggestions are welcome, and may be sent to
<A HREF="mailto:libstdc++@gcc.gnu.org">the mailing list</A>.
<BR> $Id: howto.html,v 1.1.4.1 2001/05/14 19:48:58 bkoz Exp $
</EM></P>


</BODY>
</HTML>