30a20a1ee0
2001-04-02 Phil Edwards <pme@sources.redhat.com> New concept checking implementation. * docs/html/19_diagnostics/howto.html: Document. * docs/html/17_intro/concept_check.diff: New file, for reference. * include/bits/boost_concept_check.h: New file from Boost. * include/bits/c++config: Update comments. * include/bits/concept_check.h: New file. * include/bits/concept_checks.h: Removed. * include/bits/container_concepts.h: Removed. * include/bits/sequence_concepts.h: Removed. * include/bits/stl_iterator_base.h: Removed; split into... * include/bits/stl_iterator_base_funcs.h: ...this new file... * include/bits/stl_iterator_base_types.h: ...and this new file. * include/bits/sbuf_iter.h: Update to use new implementation. * include/bits/std_iterator.h: Likewise. * include/bits/std_memory.h: Likewise. * include/bits/stl_algo.h: Likewise. * include/bits/stl_algobase.h: Likewise. * include/bits/stl_construct.h: Likewise. * include/bits/stl_deque.h: Likewise. * include/bits/stl_heap.h: Likewise. * include/bits/stl_list.h: Likewise. * include/bits/stl_map.h: Likewise. * include/bits/stl_multimap.h: Likewise. * include/bits/stl_multiset.h: Likewise. * include/bits/stl_numeric.h: Likewise. * include/bits/stl_queue.h: Likewise. * include/bits/stl_set.h: Likewise. * include/bits/stl_stack.h: Likewise. * include/bits/stl_uninitialized.h: Likewise. * include/bits/stl_vector.h: Likewise. * include/ext/hash_map: Likewise. * include/ext/hash_set: Likewise. * include/ext/slist: Likewise. * include/ext/stl_hashtable.h: Likewise. * src/Makefile.am (base_headers): Update list of headers. * Makefile.in: Regenerated. * src/Makefile.in: Regenerated. * libio/Makefile.in: Regenerated. * libmath/Makefile.in: Regenerated. * libsupc++/Makefile.in: Regenerated. * testsuite/Makefile.in: Regenerated. * docs/html/install.html: Update contact information. * docs/html/17_intro/howto.html: Ditto. * docs/html/18_support/howto.html: Ditto. * docs/html/20_util/howto.html: Ditto. * docs/html/21_strings/howto.html: Ditto. * docs/html/22_locale/howto.html: Ditto. * docs/html/23_containers/howto.html: Ditto. * docs/html/24_iterators/howto.html: Ditto. * docs/html/25_algorithms/howto.html: Ditto. * docs/html/26_numerics/howto.html: Ditto. * docs/html/27_io/howto.html: Ditto. * docs/html/faq/index.html: Ditto, plus info on new checking code. * docs/html/ext/howto.html: Ditto, plus info on new checking code. * docs/html/faq/index.txt: Regenerated. From-SVN: r41031
142 lines
5.7 KiB
HTML
142 lines
5.7 KiB
HTML
<!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="HOWTO for the libstdc++ chapter 26.">
|
|
<META NAME="GENERATOR" CONTENT="vi and eight fingers">
|
|
<TITLE>libstdc++-v3 HOWTO: Chapter 26</TITLE>
|
|
<LINK REL=StyleSheet HREF="../lib3styles.css">
|
|
<!-- $Id: howto.html,v 1.1 2000/12/10 04:04:56 pme Exp $ -->
|
|
</HEAD>
|
|
<BODY>
|
|
|
|
<H1 CLASS="centered"><A NAME="top">Chapter 26: Numerics</A></H1>
|
|
|
|
<P>Chapter 26 deals with building block abstractions to aid in
|
|
numerical computing:
|
|
<UL>
|
|
<LI>Template data structures such as <TT>valarray<></TT>
|
|
and <TT>complex<></TT>.
|
|
<LI>Template numerical functions such as <TT>accumulate</TT>;
|
|
<TT>inner_product</TT>; <TT>partial_sum</TT> and
|
|
<TT>adjacent_difference</TT>.
|
|
</UL>
|
|
All of the Standard C math functions are of course included in C++,
|
|
and overloaded versions for <TT>long</TT>, <TT>float</TT>, and
|
|
<TT>long double</TT> have been added for all of them.
|
|
</P>
|
|
|
|
<!-- ####################################################### -->
|
|
<HR>
|
|
<H1>Contents</H1>
|
|
<UL>
|
|
<LI><A HREF="#1">Complex Number Processing</A>
|
|
<LI><A HREF="#2">Array Processing</A>
|
|
<LI><A HREF="#3">Numerical Functions</A>
|
|
</UL>
|
|
|
|
<HR>
|
|
|
|
<!-- ####################################################### -->
|
|
|
|
<H2><A NAME="1">Complex Number Processing</A></H2>
|
|
<P>Using <TT>complex<></TT> becomes even more comple- er, sorry,
|
|
<EM>complicated</EM>, with the not-quite-gratuitously-incompatible
|
|
addition of complex types to the C language. David Tribble has
|
|
compiled a list of C++98 and C99 conflict points; his description of
|
|
C's new type versus those of C++ and how to get them playing together
|
|
nicely is
|
|
<A HREF="http://home.flash.net/~dtribble/text/cdiffs.htm#C99.complex">here</A>.
|
|
</P>
|
|
<P><TT>complex<></TT> is intended to be instantiated with a
|
|
floating-point type. As long as you meet that and some other basic
|
|
requirements, then the resulting instantiation has all of the usual
|
|
math operators defined, as well as definitions of <TT>op<<</TT>
|
|
and <TT>op>></TT> that work with iostreams: <TT>op<<</TT>
|
|
prints <TT>(u,v)</TT> and <TT>op>></TT> can read <TT>u</TT>,
|
|
<TT>(u)</TT>, and <TT>(u,v)</TT>.
|
|
</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">Array Processing</A></H2>
|
|
<P>One of the major reasons why FORTRAN can chew through numbers so well
|
|
is that it is defined to be free of pointer aliasing, an assumption
|
|
that C89 is not allowed to make, and neither is C++. C99 adds a new
|
|
keyword, <TT>restrict</TT>, to apply to individual pointers. The C++
|
|
solution is contained in the library rather than the language
|
|
(although many vendors can be expected to add this to their compilers
|
|
as an extension).
|
|
</P>
|
|
<P>That library solution is a set of two classes, five template classes,
|
|
and "a whole bunch" of functions. The classes are required
|
|
to be free of pointer aliasing, so compilers can optimize the
|
|
daylights out of them the same way that they have been for FORTRAN.
|
|
They are collectively called <TT>valarray</TT>, although strictly
|
|
speaking this is only one of the five template classes, and they are
|
|
designed to be familiar to people who have worked with the BLAS
|
|
libraries before.
|
|
</P>
|
|
<P>Some more stuff should go here once somebody has time to write it.
|
|
</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">Numerical Functions</A></H2>
|
|
<P>There are four generalized functions in the <numeric> header
|
|
that follow the same conventions as those in <algorithm>. Each
|
|
of them is overloaded: one signature for common default operations,
|
|
and a second for fully general operations. Their names are
|
|
self-explanatory to anyone who works with numerics on a regular basis:
|
|
<UL>
|
|
<LI><TT>accumulate</TT>
|
|
<LI><TT>inner_product</TT>
|
|
<LI><TT>partial_sum</TT>
|
|
<LI><TT>adjacent_difference</TT>
|
|
</UL>
|
|
</P>
|
|
<P>Here is a simple example of the two forms of <TT>accumulate</TT>.
|
|
<PRE>
|
|
int ar[50];
|
|
int someval = somefunction();
|
|
|
|
// ...initialize members of ar to something...
|
|
|
|
int sum = std::accumulate(ar,ar+50,0);
|
|
int sum_stuff = std::accumulate(ar,ar+50,someval);
|
|
int product = std::accumulate(ar,ar+50,1,std::multiplies<int>());
|
|
</PRE>
|
|
The first call adds all the members of the array, using zero as an
|
|
initial value for <TT>sum</TT>. The second does the same, but uses
|
|
<TT>someval</TT> as the starting value (thus, <TT>sum_stuff == sum +
|
|
someval</TT>). The final call uses the second of the two signatures,
|
|
and multiplies all the members of the array; here we must obviously
|
|
use 1 as a starting value instead of 0.
|
|
</P>
|
|
<P>The other three functions have similar dual-signature forms.
|
|
</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 2000/12/10 04:04:56 pme Exp $
|
|
</EM></P>
|
|
|
|
|
|
</BODY>
|
|
</HTML>
|