1 |
786 |
skrzyp |
// This file is part of the uSTL library, an STL implementation.
|
2 |
|
|
//
|
3 |
|
|
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
|
4 |
|
|
// This file is free software, distributed under the MIT License.
|
5 |
|
|
|
6 |
|
|
#ifndef USTL_H_6A5A10410D2CD7FC2D78FE470F045EB7
|
7 |
|
|
#define USTL_H_6A5A10410D2CD7FC2D78FE470F045EB7
|
8 |
|
|
|
9 |
|
|
#include <pkgconf/ustl.h>
|
10 |
|
|
|
11 |
|
|
#include "ustl/uspecial.h"
|
12 |
|
|
#include "ustl/umap.h"
|
13 |
|
|
#include "ustl/umultimap.h"
|
14 |
|
|
#include "ustl/ustack.h"
|
15 |
|
|
#include "ustl/uqueue.h"
|
16 |
|
|
#ifdef CYGCLS_USTL_FSTREAMS
|
17 |
|
|
#include "ustl/ofstream.h"
|
18 |
|
|
#endif
|
19 |
|
|
#include "ustl/unumeric.h"
|
20 |
|
|
#include "ustl/ulist.h"
|
21 |
|
|
#include "ustl/uheap.h"
|
22 |
|
|
#include "ustl/ustdxept.h"
|
23 |
|
|
#include "ustl/ustlecos.h"
|
24 |
|
|
|
25 |
|
|
#endif
|
26 |
|
|
|
27 |
|
|
/// \mainpage
|
28 |
|
|
///
|
29 |
|
|
/// \section intro Introduction
|
30 |
|
|
///
|
31 |
|
|
/// uSTL is a partial implementation of the STL specification intended to
|
32 |
|
|
/// reduce code size of the derivative programs. Usually, the STL containers
|
33 |
|
|
/// manage their own storage with new[] and delete[] operators, which create
|
34 |
|
|
/// strongly typed storage. That is the standard way of allocating C++ object
|
35 |
|
|
/// vectors, allowing appropriate constructors and destructors to be called on
|
36 |
|
|
/// the allocated storage and ensuring that objects are copied via their copy
|
37 |
|
|
/// operators. Although type safety is a good thing, placing memory management
|
38 |
|
|
/// code into a template necessitates its reinstantiation for every template
|
39 |
|
|
/// instance used by the derivative program. This produces substantial code
|
40 |
|
|
/// bloat, that is frequently derided by C developers and used by them as
|
41 |
|
|
/// an argument that C is better than C++. The uSTL implementation solves
|
42 |
|
|
/// this problem by factoring memory management code into a non-template base
|
43 |
|
|
/// class, ustl::memblock, which performs unstructured memory allocation. STL
|
44 |
|
|
/// containers are then implemented as template wrappers for memblock to
|
45 |
|
|
/// provide a measure of type safety. The result is that each template
|
46 |
|
|
/// instantiation contains less code, and although it does not completely
|
47 |
|
|
/// "disappear", due to the requirement for calling placement constructors
|
48 |
|
|
/// on the allocated memory, most of it does, being replaced by calls to
|
49 |
|
|
/// memblock methods. The base classes for unstructured storage management
|
50 |
|
|
/// (cmemlink - link to constant memory, memlink - link to mutable memory,
|
51 |
|
|
/// and memblock - owner of mutable memory) are, of course, also available
|
52 |
|
|
/// for use as data buffers wherever those are needed, and streams that
|
53 |
|
|
/// efficiently read and write binary data into them are also available.
|
54 |
|
|
//
|
55 |
|
|
/// \defgroup Containers Containers
|
56 |
|
|
/// Here you'll find all the containers for your objects and data.
|
57 |
|
|
//
|
58 |
|
|
/// \defgroup MemoryManagement Memory Management
|
59 |
|
|
/// \ingroup Containers
|
60 |
|
|
/// Classes that implement low-level memory management and form the base for
|
61 |
|
|
/// all containers in the library. Almost all functionality in the containers
|
62 |
|
|
/// is reduced to calls to these base classes through a great deal of inline
|
63 |
|
|
/// crunching by the compiler, and thus you end up storing all your data in
|
64 |
|
|
/// ustl::memblock objects with the container templates as mere syntactic sugar.
|
65 |
|
|
//
|
66 |
|
|
/// \defgroup Sequences Sequence Containers
|
67 |
|
|
/// \ingroup Containers
|
68 |
|
|
/// Containers containing sequences of objects.
|
69 |
|
|
//
|
70 |
|
|
/// \defgroup AssociativeContainers Associative Containers
|
71 |
|
|
/// \ingroup Containers
|
72 |
|
|
/// Containers containing associations of objects.
|
73 |
|
|
//
|
74 |
|
|
/// \defgroup Streams Streams
|
75 |
|
|
/// Streams convert objects into flat data.
|
76 |
|
|
//
|
77 |
|
|
/// \defgroup BinaryStreams Binary Streams
|
78 |
|
|
/// \ingroup Streams
|
79 |
|
|
/// Unlike the C++ standard library,
|
80 |
|
|
/// the default behaviour is very strongly biased toward binary streams. I
|
81 |
|
|
/// believe that text formats should be used very sparingly due to numerous
|
82 |
|
|
/// problems they cause, such as total lack of structure, buffer overflows,
|
83 |
|
|
/// the great multitude of formats and encodings for even the most
|
84 |
|
|
/// trivial of things like integers, and the utter lack of readability
|
85 |
|
|
/// despite ardent claims to the contrary. Binary formats are well-structured,
|
86 |
|
|
/// are simpler to define exhaustively, are aggregates of basic types which
|
87 |
|
|
/// are universal to all architectures (with the exception of two types of
|
88 |
|
|
/// byte ordering, which I hope to be an issue that will go away soon), and
|
89 |
|
|
/// are much more readable (through an appropriate formatting tool equipped
|
90 |
|
|
/// to read binary format specifications).
|
91 |
|
|
//
|
92 |
|
|
/// \defgroup BinaryStreamIterators Binary Stream Iterators
|
93 |
|
|
/// \ingroup BinaryStreams
|
94 |
|
|
/// \ingroup Iterators
|
95 |
|
|
/// Iterators for using STL algorithms with binary streams.
|
96 |
|
|
//
|
97 |
|
|
/// \defgroup TextStreams TextStreams
|
98 |
|
|
/// \ingroup Streams
|
99 |
|
|
/// Streams converting objects into streams of text.
|
100 |
|
|
//
|
101 |
|
|
/// \defgroup DeviceStreams Device Streams
|
102 |
|
|
/// \ingroup Streams
|
103 |
|
|
/// Standard cout, cerr, and cin implementations for reading
|
104 |
|
|
/// and writing text through standard file descriptors.
|
105 |
|
|
//
|
106 |
|
|
/// \defgroup Iterators Iterators
|
107 |
|
|
/// Generalizations of the pointer concept, allowing algorithms to treat
|
108 |
|
|
/// all containers in a unified fashion.
|
109 |
|
|
//
|
110 |
|
|
/// \defgroup IteratorAdaptors Iterator Adaptors
|
111 |
|
|
/// \ingroup Iterators
|
112 |
|
|
/// Iterators made out of other iterators.
|
113 |
|
|
//
|
114 |
|
|
/// \defgroup Algorithms Algorithms
|
115 |
|
|
/// STL algorithms are the heart of generic programming. The idea is to
|
116 |
|
|
/// separate algorithms from containers to take advantage of the fact that
|
117 |
|
|
/// there are fewer distinct algorithms than typed containers. This is
|
118 |
|
|
/// diametrically opposed to object oriented programming, where each object
|
119 |
|
|
/// must contain all functionality related to its internal data. You will
|
120 |
|
|
/// find, I think, that in practice, generic programming is not terribly
|
121 |
|
|
/// convenient because it prevents you from encapsulating all your data.
|
122 |
|
|
/// The best approach is to compromise and have raw data classes that will
|
123 |
|
|
/// be manipulated by algorithms and to treat the rest of the objects as
|
124 |
|
|
/// stateful data transformers.
|
125 |
|
|
//
|
126 |
|
|
/// \defgroup MutatingAlgorithms Mutating Algorithms
|
127 |
|
|
/// \ingroup Algorithms
|
128 |
|
|
/// Algorithms for modifying your data in some way.
|
129 |
|
|
//
|
130 |
|
|
/// \defgroup SortingAlgorithms Sorting Algorithms
|
131 |
|
|
/// \ingroup MutatingAlgorithms
|
132 |
|
|
/// Algorithms for sorting containers.
|
133 |
|
|
//
|
134 |
|
|
/// \defgroup GeneratorAlgorithms Generator Algorithms
|
135 |
|
|
/// \ingroup MutatingAlgorithms
|
136 |
|
|
/// Algorithms for generating data.
|
137 |
|
|
//
|
138 |
|
|
/// \defgroup NumericAlgorithms Numeric Algorithms
|
139 |
|
|
/// \ingroup MutatingAlgorithms
|
140 |
|
|
/// Algorithms generalizing mathematical operations.
|
141 |
|
|
//
|
142 |
|
|
/// \defgroup SetAlgorithms Set Algorithms
|
143 |
|
|
/// \ingroup MutatingAlgorithms
|
144 |
|
|
/// Algorithms for working with sorted sets.
|
145 |
|
|
//
|
146 |
|
|
/// \defgroup HeapAlgorithms Heap Algorithms
|
147 |
|
|
/// \ingroup MutatingAlgorithms
|
148 |
|
|
/// Algorithms for generating and manipulating heaps.
|
149 |
|
|
//
|
150 |
|
|
/// \defgroup SwapAlgorithms Swap Algorithms
|
151 |
|
|
/// \ingroup MutatingAlgorithms
|
152 |
|
|
/// Algorithms for swapping elements.
|
153 |
|
|
//
|
154 |
|
|
/// \defgroup RawStorageAlgorithms Raw Storage Algorithms
|
155 |
|
|
/// \ingroup MutatingAlgorithms
|
156 |
|
|
/// Algorithms for manipulating unstructured memory.
|
157 |
|
|
//
|
158 |
|
|
/// \defgroup ConditionAlgorithms Condition Algorithms
|
159 |
|
|
/// \ingroup Algorithms
|
160 |
|
|
/// Algorithms for obtaining information about data.
|
161 |
|
|
//
|
162 |
|
|
/// \defgroup SearchingAlgorithms Searching Algorithms
|
163 |
|
|
/// \ingroup ConditionAlgorithms
|
164 |
|
|
/// Algorithms for searching through containers.
|
165 |
|
|
//
|
166 |
|
|
/// \defgroup PredicateAlgorithms Predicate Algorithms
|
167 |
|
|
/// \ingroup Algorithms
|
168 |
|
|
/// Algorithms that take a functor object. Avoid these if you can,
|
169 |
|
|
/// and carefully check the generated assembly if you can't. These
|
170 |
|
|
/// algorithms can and will generate prodigious amounts of bloat
|
171 |
|
|
/// if you are not very very careful about writing your functors.
|
172 |
|
|
//
|
173 |
|
|
/// \defgroup Functors Functors
|
174 |
|
|
/// Functors are inteded to be passed as arguments to \link PredicateAlgorithms
|
175 |
|
|
/// predicate algorithms\endlink. Ivory tower academics make much of this capability,
|
176 |
|
|
/// no doubt happy that C++ can now be made to look just like their precious lisp.
|
177 |
|
|
/// In practice, however, functors and predicate algorithms are mostly useless.
|
178 |
|
|
/// An iterative solution using \ref foreach is usually far simpler to write
|
179 |
|
|
/// and to maintain. Furthermore, functional programming in C++ often
|
180 |
|
|
/// generates much bloat and slowness, which is difficult to avoid with any
|
181 |
|
|
/// but the most primitive functors. Try them if you wish, now and then, but
|
182 |
|
|
/// compare with an iterative solution to see if the compiler really can see
|
183 |
|
|
/// through all your functional trickery.
|
184 |
|
|
//
|
185 |
|
|
/// \defgroup FunctorObjects Functor Objects
|
186 |
|
|
/// \ingroup Functors
|
187 |
|
|
/// Objects that wrap other functors to provide new functionality.
|
188 |
|
|
//
|
189 |
|
|
/// \defgroup FunctorAccessors Functor Object Accessors
|
190 |
|
|
/// \ingroup Functors
|
191 |
|
|
/// Because C++ is so very unsuited to functional programming, trying
|
192 |
|
|
/// to do so may require a lot of typing. These accessor functions
|
193 |
|
|
/// are somewhat helpful in making functional constructs more readable.
|