aboutsummaryrefslogtreecommitdiff
path: root/libstdc++/std
diff options
context:
space:
mode:
authorJason Merrill <jason@gcc.gnu.org>1997-08-21 18:57:35 -0400
committerJason Merrill <jason@gcc.gnu.org>1997-08-21 18:57:35 -0400
commit6599da043e22e96ac830fb50a61c1b6d95d1b142 (patch)
treea3b19970338bdae580faff126a716e1d5520400c /libstdc++/std
parent8975416cfb6269ad94b6330d42960cca8b0925b7 (diff)
downloadgcc-6599da043e22e96ac830fb50a61c1b6d95d1b142.zip
gcc-6599da043e22e96ac830fb50a61c1b6d95d1b142.tar.gz
gcc-6599da043e22e96ac830fb50a61c1b6d95d1b142.tar.bz2
Initial revision
From-SVN: r14877
Diffstat (limited to 'libstdc++/std')
-rw-r--r--libstdc++/std/bastring.cc514
-rw-r--r--libstdc++/std/bastring.h560
-rw-r--r--libstdc++/std/complext.cc273
-rw-r--r--libstdc++/std/complext.h423
-rw-r--r--libstdc++/std/dcomplex.h94
-rw-r--r--libstdc++/std/fcomplex.h90
-rw-r--r--libstdc++/std/ldcomplex.h98
-rw-r--r--libstdc++/std/straits.h161
8 files changed, 2213 insertions, 0 deletions
diff --git a/libstdc++/std/bastring.cc b/libstdc++/std/bastring.cc
new file mode 100644
index 0000000..155656a
--- /dev/null
+++ b/libstdc++/std/bastring.cc
@@ -0,0 +1,514 @@
+// Member templates for the -*- C++ -*- string classes.
+// Copyright (C) 1994 Free Software Foundation
+
+// This file is part of the GNU ANSI C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+// As a special exception, if you link this library with files
+// compiled with a GNU compiler to produce an executable, this does not cause
+// the resulting executable to be covered by the GNU General Public License.
+// This exception does not however invalidate any other reasons why
+// the executable file might be covered by the GNU General Public License.
+
+// Written by Jason Merrill based upon the specification by Takanori Adachi
+// in ANSI X3J16/94-0013R2.
+
+#include <cstddef>
+#include <std/bastring.h>
+
+extern "C++" {
+template <class charT, class traits>
+inline void * basic_string <charT, traits>::Rep::
+operator new (size_t s, size_t extra)
+{
+ return ::operator new (s + extra * sizeof (charT));
+}
+
+template <class charT, class traits>
+inline size_t basic_string <charT, traits>::Rep::
+#if _G_ALLOC_CONTROL
+default_frob (size_t s)
+#else
+frob_size (size_t s)
+#endif
+{
+ size_t i = 16;
+ while (i < s) i *= 2;
+ return i;
+}
+
+template <class charT, class traits>
+inline basic_string <charT, traits>::Rep * basic_string <charT, traits>::Rep::
+create (size_t extra)
+{
+ extra = frob_size (extra + 1);
+ Rep *p = new (extra) Rep;
+ p->res = extra;
+ p->ref = 1;
+ p->selfish = false;
+ return p;
+}
+
+template <class charT, class traits>
+charT * basic_string <charT, traits>::Rep::
+clone ()
+{
+ Rep *p = Rep::create (len);
+ p->copy (0, data (), len);
+ p->len = len;
+ return p->data ();
+}
+
+template <class charT, class traits>
+inline bool basic_string <charT, traits>::Rep::
+#ifdef _G_ALLOC_CONTROL
+default_excess (size_t s, size_t r)
+#else
+excess_slop (size_t s, size_t r)
+#endif
+{
+ return 2 * (s <= 16 ? 16 : s) < r;
+}
+
+template <class charT, class traits>
+inline bool basic_string <charT, traits>::
+check_realloc (size_t s) const
+{
+ s += sizeof (charT);
+ return (rep ()->ref > 1
+ || s > capacity ()
+ || Rep::excess_slop (s, capacity ()));
+}
+
+template <class charT, class traits>
+void basic_string <charT, traits>::
+alloc (size_t size, bool save)
+{
+ if (! check_realloc (size))
+ return;
+
+ Rep *p = Rep::create (size);
+
+ if (save)
+ {
+ p->copy (0, data (), length ());
+ p->len = length ();
+ }
+ else
+ p->len = 0;
+
+ repup (p);
+}
+
+template <class charT, class traits>
+basic_string <charT, traits>& basic_string <charT, traits>::
+replace (size_t pos1, size_t n1,
+ const basic_string& str, size_t pos2, size_t n2)
+{
+ const size_t len2 = str.length ();
+
+ if (pos1 == 0 && n1 >= length () && pos2 == 0 && n2 >= len2)
+ return operator= (str);
+
+ OUTOFRANGE (pos2 > len2);
+
+ if (n2 > len2 - pos2)
+ n2 = len2 - pos2;
+
+ return replace (pos1, n1, str.data () + pos2, n2);
+}
+
+template <class charT, class traits>
+inline void basic_string <charT, traits>::Rep::
+copy (size_t pos, const charT *s, size_t n)
+{
+ if (n)
+ traits::copy (data () + pos, s, n);
+}
+
+template <class charT, class traits>
+inline void basic_string <charT, traits>::Rep::
+move (size_t pos, const charT *s, size_t n)
+{
+ if (n)
+ traits::move (data () + pos, s, n);
+}
+
+template <class charT, class traits>
+basic_string <charT, traits>& basic_string <charT, traits>::
+replace (size_t pos, size_t n1, const charT* s, size_t n2)
+{
+ const size_t len = length ();
+ OUTOFRANGE (pos > len);
+ if (n1 > len - pos)
+ n1 = len - pos;
+ LENGTHERROR (len - n1 > max_size () - n2);
+ size_t newlen = len - n1 + n2;
+
+ if (check_realloc (newlen))
+ {
+ Rep *p = Rep::create (newlen);
+ p->copy (0, data (), pos);
+ p->copy (pos + n2, data () + pos + n1, len - (pos + n1));
+ p->copy (pos, s, n2);
+ repup (p);
+ }
+ else
+ {
+ rep ()->move (pos + n2, data () + pos + n1, len - (pos + n1));
+ rep ()->copy (pos, s, n2);
+ }
+ rep ()->len = newlen;
+
+ return *this;
+}
+
+template <class charT, class traits>
+inline void basic_string <charT, traits>::Rep::
+set (size_t pos, const charT c, size_t n)
+{
+ traits::set (data () + pos, c, n);
+}
+
+template <class charT, class traits>
+basic_string <charT, traits>& basic_string <charT, traits>::
+replace (size_t pos, size_t n1, size_t n2, charT c)
+{
+ const size_t len = length ();
+ OUTOFRANGE (pos > len);
+ if (n1 > len - pos)
+ n1 = len - pos;
+ LENGTHERROR (len - n1 > max_size () - n2);
+ size_t newlen = len - n1 + n2;
+
+ if (check_realloc (newlen))
+ {
+ Rep *p = Rep::create (newlen);
+ p->copy (0, data (), pos);
+ p->copy (pos + n2, data () + pos + n1, len - (pos + n1));
+ p->set (pos, c, n2);
+ repup (p);
+ }
+ else
+ {
+ rep ()->move (pos + n2, data () + pos + n1, len - (pos + n1));
+ rep ()->set (pos, c, n2);
+ }
+ rep ()->len = newlen;
+
+ return *this;
+}
+
+template <class charT, class traits>
+void basic_string <charT, traits>::
+resize (size_t n, charT c)
+{
+ LENGTHERROR (n > max_size ());
+
+ if (n > length ())
+ append (n - length (), c);
+ else
+ remove (n);
+}
+
+template <class charT, class traits>
+size_t basic_string <charT, traits>::
+copy (charT* s, size_t n, size_t pos)
+{
+ OUTOFRANGE (pos > length ());
+
+ if (n > length () - pos)
+ n = length () - pos;
+
+ traits::copy (s, data () + pos, n);
+ return n;
+}
+
+template <class charT, class traits>
+size_t basic_string <charT, traits>::
+find (const charT* s, size_t pos, size_t n) const
+{
+ size_t xpos = pos;
+ for (; xpos + n <= length (); ++xpos)
+ if (traits::eq (data () [xpos], *s)
+ && traits::compare (data () + xpos, s, n) == 0)
+ return xpos;
+ return npos;
+}
+
+template <class charT, class traits>
+inline size_t basic_string <charT, traits>::
+_find (const charT* ptr, charT c, size_t xpos, size_t len)
+{
+ for (; xpos < len; ++xpos)
+ if (traits::eq (ptr [xpos], c))
+ return xpos;
+ return npos;
+}
+
+template <class charT, class traits>
+size_t basic_string <charT, traits>::
+find (charT c, size_t pos) const
+{
+ return _find (data (), c, pos, length ());
+}
+
+template <class charT, class traits>
+size_t basic_string <charT, traits>::
+rfind (const charT* s, size_t pos, size_t n) const
+{
+ if (n > length ())
+ return npos;
+
+ size_t xpos = length () - n;
+ if (xpos > pos)
+ xpos = pos;
+
+ for (++xpos; xpos-- > 0; )
+ if (traits::eq (data () [xpos], *s)
+ && traits::compare (data () + xpos, s, n) == 0)
+ return xpos;
+ return npos;
+}
+
+template <class charT, class traits>
+size_t basic_string <charT, traits>::
+rfind (charT c, size_t pos) const
+{
+ if (1 > length ())
+ return npos;
+
+ size_t xpos = length () - 1;
+ if (xpos > pos)
+ xpos = pos;
+
+ for (++xpos; xpos-- > 0; )
+ if (traits::eq (data () [xpos], c))
+ return xpos;
+ return npos;
+}
+
+template <class charT, class traits>
+size_t basic_string <charT, traits>::
+find_first_of (const charT* s, size_t pos, size_t n) const
+{
+ size_t xpos = pos;
+ for (; xpos < length (); ++xpos)
+ if (_find (s, data () [xpos], 0, n) != npos)
+ return xpos;
+ return npos;
+}
+
+template <class charT, class traits>
+size_t basic_string <charT, traits>::
+find_last_of (const charT* s, size_t pos, size_t n) const
+{
+ size_t xpos = length () - 1;
+ if (xpos > pos)
+ xpos = pos;
+ for (; xpos; --xpos)
+ if (_find (s, data () [xpos], 0, n) != npos)
+ return xpos;
+ return npos;
+}
+
+template <class charT, class traits>
+size_t basic_string <charT, traits>::
+find_first_not_of (const charT* s, size_t pos, size_t n) const
+{
+ size_t xpos = pos;
+ for (; xpos < length (); ++xpos)
+ if (_find (s, data () [xpos], 0, n) == npos)
+ return xpos;
+ return npos;
+}
+
+template <class charT, class traits>
+size_t basic_string <charT, traits>::
+find_first_not_of (charT c, size_t pos) const
+{
+ size_t xpos = pos;
+ for (; xpos < length (); ++xpos)
+ if (traits::ne (data () [xpos], c))
+ return xpos;
+ return npos;
+}
+
+template <class charT, class traits>
+size_t basic_string <charT, traits>::
+find_last_not_of (const charT* s, size_t pos, size_t n) const
+{
+ size_t xpos = length () - 1;
+ if (xpos > pos)
+ xpos = pos;
+ for (; xpos; --xpos)
+ if (_find (s, data () [xpos], 0, n) == npos)
+ return xpos;
+ return npos;
+}
+
+template <class charT, class traits>
+size_t basic_string <charT, traits>::
+find_last_not_of (charT c, size_t pos) const
+{
+ size_t xpos = length () - 1;
+ if (xpos > pos)
+ xpos = pos;
+ for (; xpos; --xpos)
+ if (traits::ne (data () [xpos], c))
+ return xpos;
+ return npos;
+}
+
+template <class charT, class traits>
+int basic_string <charT, traits>::
+compare (const basic_string& str, size_t pos, size_t n) const
+{
+ OUTOFRANGE (pos > length ());
+
+ size_t rlen = length () - pos;
+ if (rlen > n)
+ rlen = n;
+ if (rlen > str.length ())
+ rlen = str.length ();
+ int r = traits::compare (data () + pos, str.data (), rlen);
+ if (r != 0)
+ return r;
+ if (rlen == n)
+ return 0;
+ return (length () - pos) - str.length ();
+}
+
+template <class charT, class traits>
+int basic_string <charT, traits>::
+compare (const charT* s, size_t pos, size_t n) const
+{
+ OUTOFRANGE (pos > length ());
+
+ size_t rlen = length () - pos;
+ if (rlen > n)
+ rlen = n;
+ int r = traits::compare (data () + pos, s, rlen);
+ if (r != 0)
+ return r;
+ return (length () - pos) - n;
+}
+
+#include <iostream.h>
+
+template <class charT, class traits>
+istream &
+operator>> (istream &is, basic_string <charT, traits> &s)
+{
+ int w = is.width (0);
+ if (is.ipfx0 ())
+ {
+ register streambuf *sb = is.rdbuf ();
+ s.resize (0);
+ while (1)
+ {
+ int ch = sb->sbumpc ();
+ if (ch == EOF)
+ {
+ is.setstate (ios::eofbit);
+ break;
+ }
+ else if (traits::is_del (ch))
+ {
+ sb->sungetc ();
+ break;
+ }
+ s += ch;
+ if (--w == 1)
+ break;
+ }
+ }
+
+ is.isfx ();
+ if (s.length () == 0)
+ is.setstate (ios::failbit);
+
+ return is;
+}
+
+template <class charT, class traits>
+ostream &
+operator<< (ostream &o, const basic_string <charT, traits>& s)
+{
+ return o.write (s.data (), s.length ());
+}
+
+template <class charT, class traits>
+istream&
+getline (istream &is, basic_string <charT, traits>& s, charT delim)
+{
+ if (is.ipfx1 ())
+ {
+ _IO_size_t count = 0;
+ streambuf *sb = is.rdbuf ();
+ s.resize (0);
+
+ while (1)
+ {
+ int ch = sb->sbumpc ();
+ if (ch == EOF)
+ {
+ is.setstate (count == 0
+ ? (ios::failbit|ios::eofbit)
+ : ios::eofbit);
+ break;
+ }
+
+ ++count;
+
+ if (ch == delim)
+ break;
+
+ s += ch;
+
+ if (s.length () == s.npos - 1)
+ {
+ is.setstate (ios::failbit);
+ break;
+ }
+ }
+ }
+
+ // We need to be friends with istream to do this.
+ // is._gcount = count;
+ is.isfx ();
+
+ return is;
+}
+
+template <class charT, class traits>
+basic_string <charT, traits>::Rep
+basic_string<charT, traits>::nilRep = { 0, 0, 1 };
+
+template <class charT, class traits>
+const basic_string <charT, traits>::size_type
+basic_string <charT, traits>::npos;
+
+#ifdef _G_ALLOC_CONTROL
+template <class charT, class traits>
+bool (*basic_string <charT, traits>::Rep::excess_slop) (size_t, size_t)
+ = basic_string <charT, traits>::Rep::default_excess;
+
+template <class charT, class traits>
+size_t (*basic_string <charT, traits>::Rep::frob_size) (size_t)
+ = basic_string <charT, traits>::Rep::default_frob;
+#endif
+
+} // extern "C++"
diff --git a/libstdc++/std/bastring.h b/libstdc++/std/bastring.h
new file mode 100644
index 0000000..5a2605b
--- /dev/null
+++ b/libstdc++/std/bastring.h
@@ -0,0 +1,560 @@
+// Main templates for the -*- C++ -*- string classes.
+// Copyright (C) 1994, 1995 Free Software Foundation
+
+// This file is part of the GNU ANSI C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+// As a special exception, if you link this library with files
+// compiled with a GNU compiler to produce an executable, this does not cause
+// the resulting executable to be covered by the GNU General Public License.
+// This exception does not however invalidate any other reasons why
+// the executable file might be covered by the GNU General Public License.
+
+// Written by Jason Merrill based upon the specification by Takanori Adachi
+// in ANSI X3J16/94-0013R2.
+
+#ifndef __BASTRING__
+#define __BASTRING__
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include <cstddef>
+#include <std/straits.h>
+
+#if _G_USE_EXCEPTIONS
+
+#include <stdexcept>
+#define OUTOFRANGE(cond) \
+ do { if (!(cond)) throw out_of_range (#cond); } while (0)
+#define LENGTHERROR(cond) \
+ do { if (!(cond)) throw length_error (#cond); } while (0)
+
+#else
+
+#include <cassert>
+#define OUTOFRANGE(cond) assert (!(cond))
+#define LENGTHERROR(cond) assert (!(cond))
+
+#endif
+
+extern "C++" {
+class istream; class ostream;
+
+// #include <iterator.h>
+
+template <class charT, class traits = string_char_traits<charT> >
+class basic_string
+{
+private:
+ struct Rep {
+ size_t len, res, ref;
+ bool selfish;
+
+ charT* data () { return reinterpret_cast<charT *>(this + 1); }
+ charT& operator[] (size_t s) { return data () [s]; }
+ charT* grab () { if (selfish) return clone (); ++ref; return data (); }
+ void release () { if (--ref == 0) delete this; }
+
+ inline static void * operator new (size_t, size_t);
+ inline static Rep* create (size_t);
+ charT* clone ();
+
+ inline void copy (size_t, const charT *, size_t);
+ inline void move (size_t, const charT *, size_t);
+ inline void set (size_t, const charT, size_t);
+
+#if _G_ALLOC_CONTROL
+ // These function pointers allow you to modify the allocation policy used
+ // by the string classes. By default they expand by powers of two, but
+ // this may be excessive for space-critical applications.
+
+ // Returns true if ALLOCATED is too much larger than LENGTH
+ static bool (*excess_slop) (size_t length, size_t allocated);
+ inline static bool default_excess (size_t, size_t);
+
+ // Returns a good amount of space to allocate for a string of length LENGTH
+ static size_t (*frob_size) (size_t length);
+ inline static size_t default_frob (size_t);
+#else
+ inline static bool excess_slop (size_t, size_t);
+ inline static size_t frob_size (size_t);
+#endif
+
+ private:
+ Rep &operator= (const Rep &);
+ };
+
+public:
+// types:
+ typedef traits traits_type;
+ typedef charT value_type;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef charT& reference;
+ typedef const charT& const_reference;
+ typedef charT* pointer;
+ typedef const charT* const_pointer;
+ typedef pointer iterator;
+ typedef const_pointer const_iterator;
+#if 0
+ typedef reverse_iterator<iterator, value_type,
+ reference, difference_type> reverse_iterator;
+ typedef reverse_iterator<const_iterator, value_type, const_reference,
+ difference_type> const_reverse_iterator;
+#endif
+ static const size_type npos = static_cast<size_type>(-1);
+
+private:
+ Rep *rep () const { return reinterpret_cast<Rep *>(dat) - 1; }
+ void repup (Rep *p) { rep ()->release (); dat = p->data (); }
+
+public:
+ const charT* data () const
+ { return rep ()->data(); }
+ size_type length () const
+ { return rep ()->len; }
+ size_type size () const
+ { return rep ()->len; }
+ size_type capacity () const
+ { return rep ()->res; }
+ size_type max_size () const
+ { return (npos - 1)/sizeof (charT); } // XXX
+ bool empty () const
+ { return size () == 0; }
+
+// _lib.string.cons_ construct/copy/destroy:
+ basic_string& operator= (const basic_string& str)
+ {
+ if (&str != this) { rep ()->release (); dat = str.rep ()->grab (); }
+ return *this;
+ }
+
+ explicit basic_string (): dat (nilRep.grab ()) { }
+ basic_string (const basic_string& str): dat (str.rep ()->grab ()) { }
+ basic_string (const basic_string& str, size_type pos, size_type n = npos)
+ : dat (nilRep.grab ()) { assign (str, pos, n); }
+ basic_string (const charT* s, size_type n)
+ : dat (nilRep.grab ()) { assign (s, n); }
+ basic_string (const charT* s)
+ : dat (nilRep.grab ()) { assign (s); }
+ basic_string (size_type n, charT c)
+ : dat (nilRep.grab ()) { assign (n, c); }
+#if 0
+ template<class InputIterator>
+ basic_string(InputIterator begin, InputIterator end,
+ Allocator& = Allocator());
+#endif
+
+ ~basic_string ()
+ { rep ()->release (); }
+
+ void swap (basic_string &s) { charT *d = dat; dat = s.dat; s.dat = d; }
+
+ basic_string& append (const basic_string& str, size_type pos = 0,
+ size_type n = npos)
+ { return replace (length (), 0, str, pos, n); }
+ basic_string& append (const charT* s, size_type n)
+ { return replace (length (), 0, s, n); }
+ basic_string& append (const charT* s)
+ { return append (s, traits::length (s)); }
+ basic_string& append (size_type n, charT c)
+ { return replace (length (), 0, n, c); }
+#if 0
+ template<class InputIterator>
+ basic_string& append(InputIterator first, InputIterator last);
+#endif
+
+ basic_string& assign (const basic_string& str, size_type pos = 0,
+ size_type n = npos)
+ { return replace (0, npos, str, pos, n); }
+ basic_string& assign (const charT* s, size_type n)
+ { return replace (0, npos, s, n); }
+ basic_string& assign (const charT* s)
+ { return assign (s, traits::length (s)); }
+ basic_string& assign (size_type n, charT c)
+ { return replace (0, npos, n, c); }
+#if 0
+ template<class InputIterator>
+ basic_string& assign(InputIterator first, InputIterator last);
+#endif
+
+ basic_string& operator= (const charT* s)
+ { return assign (s); }
+ basic_string& operator= (charT c)
+ { return assign (1, c); }
+
+ basic_string& operator+= (const basic_string& rhs)
+ { return append (rhs); }
+ basic_string& operator+= (const charT* s)
+ { return append (s); }
+ basic_string& operator+= (charT c)
+ { return append (1, c); }
+
+ basic_string& insert (size_type pos1, const basic_string& str,
+ size_type pos2 = 0, size_type n = npos)
+ { return replace (pos1, 0, str, pos2, n); }
+ basic_string& insert (size_type pos, const charT* s, size_type n)
+ { return replace (pos, 0, s, n); }
+ basic_string& insert (size_type pos, const charT* s)
+ { return insert (pos, s, traits::length (s)); }
+ basic_string& insert (size_type pos, size_type n, charT c)
+ { return replace (pos, 0, n, c); }
+ iterator insert(iterator p, charT c)
+ { size_type pos = p - begin (); insert (pos, 1, c); return pos +begin (); }
+ iterator insert(iterator p, size_type n, charT c)
+ { size_type pos = p - begin (); insert (pos, n, c); return pos +begin (); }
+#if 0
+ template<class InputIterator>
+ void insert(iterator p, InputIterator first, InputIterator last);
+#endif
+
+ basic_string& remove (size_type pos = 0, size_type n = npos)
+ { return replace (pos, n, (size_type)0, (charT)0); }
+ basic_string& remove (iterator pos)
+ { return replace (pos - begin (), 1, (size_type)0, (charT)0); }
+ basic_string& remove (iterator first, iterator last)
+ { return replace (first - begin (), last - first, (size_type)0, (charT)0);}
+
+ basic_string& replace (size_type pos1, size_type n1, const basic_string& str,
+ size_type pos2 = 0, size_type n2 = npos);
+ basic_string& replace (size_type pos, size_type n1, const charT* s,
+ size_type n2);
+ basic_string& replace (size_type pos, size_type n1, const charT* s)
+ { return replace (pos, n1, s, traits::length (s)); }
+ basic_string& replace (size_type pos, size_type n1, size_type n2, charT c);
+ basic_string& replace (size_type pos, size_type n, charT c)
+ { return replace (pos, n, 1, c); }
+ basic_string& replace (iterator i1, iterator i2, const basic_string& str)
+ { return replace (i1 - begin (), i2 - i1, str); }
+ basic_string& replace (iterator i1, iterator i2, const charT* s, size_type n)
+ { return replace (i1 - begin (), i2 - i1, s, n); }
+ basic_string& replace (iterator i1, iterator i2, const charT* s)
+ { return replace (i1 - begin (), i2 - i1, s); }
+ basic_string& replace (iterator i1, iterator i2, size_type n, charT c)
+ { return replace (i1 - begin (), i2 - i1, n, c); }
+#if 0
+ template<class InputIterator>
+ basic_string& replace(iterator i1, iterator i2,
+ InputIterator j1, InputIterator j2);
+#endif
+
+private:
+ static charT eos () { return traits::eos (); }
+ void unique () { if (rep ()->ref > 1) alloc (capacity (), true); }
+ void selfish () { unique (); rep ()->selfish = true; }
+
+public:
+ charT operator[] (size_type pos) const
+ {
+ if (pos == length ())
+ return eos ();
+ return data ()[pos];
+ }
+
+ reference operator[] (size_type pos)
+ { unique (); return (*rep ())[pos]; }
+
+ reference at (size_type pos)
+ {
+ OUTOFRANGE (pos >= length ());
+ return (*this)[pos];
+ }
+ const_reference at (size_type pos) const
+ {
+ OUTOFRANGE (pos >= length ());
+ return data ()[pos];
+ }
+
+private:
+ void terminate () const
+ { traits::assign ((*rep ())[length ()], eos ()); }
+
+public:
+ const charT* c_str () const
+ { terminate (); return data (); }
+ void resize (size_type n, charT c);
+ void resize (size_type n)
+ { resize (n, eos ()); }
+ void reserve (size_type) { }
+
+ size_type copy (charT* s, size_type n, size_type pos = 0);
+
+ size_type find (const basic_string& str, size_type pos = 0) const
+ { return find (str.data(), pos, str.length()); }
+ size_type find (const charT* s, size_type pos, size_type n) const;
+ size_type find (const charT* s, size_type pos = 0) const
+ { return find (s, pos, traits::length (s)); }
+ size_type find (charT c, size_type pos = 0) const;
+
+ size_type rfind (const basic_string& str, size_type pos = npos) const
+ { return rfind (str.data(), pos, str.length()); }
+ size_type rfind (const charT* s, size_type pos, size_type n) const;
+ size_type rfind (const charT* s, size_type pos = npos) const
+ { return rfind (s, pos, traits::length (s)); }
+ size_type rfind (charT c, size_type pos = npos) const;
+
+ size_type find_first_of (const basic_string& str, size_type pos = 0) const
+ { return find_first_of (str.data(), pos, str.length()); }
+ size_type find_first_of (const charT* s, size_type pos, size_type n) const;
+ size_type find_first_of (const charT* s, size_type pos = 0) const
+ { return find_first_of (s, pos, traits::length (s)); }
+ size_type find_first_of (charT c, size_type pos = 0) const
+ { return find (c, pos); }
+
+ size_type find_last_of (const basic_string& str, size_type pos = npos) const
+ { return find_last_of (str.data(), pos, str.length()); }
+ size_type find_last_of (const charT* s, size_type pos, size_type n) const;
+ size_type find_last_of (const charT* s, size_type pos = npos) const
+ { return find_last_of (s, pos, traits::length (s)); }
+ size_type find_last_of (charT c, size_type pos = npos) const
+ { return rfind (c, pos); }
+
+ size_type find_first_not_of (const basic_string& str, size_type pos = 0) const
+ { return find_first_not_of (str.data(), pos, str.length()); }
+ size_type find_first_not_of (const charT* s, size_type pos, size_type n) const;
+ size_type find_first_not_of (const charT* s, size_type pos = 0) const
+ { return find_first_not_of (s, pos, traits::length (s)); }
+ size_type find_first_not_of (charT c, size_type pos = 0) const;
+
+ size_type find_last_not_of (const basic_string& str, size_type pos = npos) const
+ { return find_last_not_of (str.data(), pos, str.length()); }
+ size_type find_last_not_of (const charT* s, size_type pos, size_type n) const;
+ size_type find_last_not_of (const charT* s, size_type pos = npos) const
+ { return find_last_not_of (s, pos, traits::length (s)); }
+ size_type find_last_not_of (charT c, size_type pos = npos) const;
+
+ basic_string substr (size_type pos = 0, size_type n = npos) const
+ { return basic_string (*this, pos, n); }
+
+ int compare (const basic_string& str, size_type pos = 0, size_type n = npos) const;
+ // There is no 'strncmp' equivalent for charT pointers.
+ int compare (const charT* s, size_type pos, size_type n) const;
+ int compare (const charT* s, size_type pos = 0) const
+ { return compare (s, pos, traits::length (s)); }
+
+ iterator begin () { selfish (); return &(*this)[0]; }
+ iterator end () { selfish (); return &(*this)[length ()]; }
+ const_iterator begin () const { return &(*rep ())[0]; }
+ const_iterator end () const { return &(*rep ())[length ()]; }
+
+#if 0
+ reverse_iterator rbegin() { return reverse_iterator (end ()); }
+ const_reverse_iterator rbegin() const
+ { return const_reverse_iterator (end ()); }
+ reverse_iterator rend() { return reverse_iterator (begin ()); }
+ const_reverse_iterator rend() const
+ { return const reverse_iterator (begin ()); }
+#endif
+
+private:
+ void alloc (size_type size, bool save);
+ static size_type _find (const charT* ptr, charT c, size_type xpos, size_type len);
+ inline bool check_realloc (size_type s) const;
+
+ static Rep nilRep;
+ charT *dat;
+};
+
+template <class charT, class traits>
+inline basic_string <charT, traits>
+operator+ (const basic_string <charT, traits>& lhs,
+ const basic_string <charT, traits>& rhs)
+{
+ basic_string <charT, traits> str (lhs);
+ str.append (rhs);
+ return str;
+}
+
+template <class charT, class traits>
+inline basic_string <charT, traits>
+operator+ (const charT* lhs, const basic_string <charT, traits>& rhs)
+{
+ basic_string <charT, traits> str (lhs);
+ str.append (rhs);
+ return str;
+}
+
+template <class charT, class traits>
+inline basic_string <charT, traits>
+operator+ (charT lhs, const basic_string <charT, traits>& rhs)
+{
+ basic_string <charT, traits> str (1, lhs);
+ str.append (rhs);
+ return str;
+}
+
+template <class charT, class traits>
+inline basic_string <charT, traits>
+operator+ (const basic_string <charT, traits>& lhs, const charT* rhs)
+{
+ basic_string <charT, traits> str (lhs);
+ str.append (rhs);
+ return str;
+}
+
+template <class charT, class traits>
+inline basic_string <charT, traits>
+operator+ (const basic_string <charT, traits>& lhs, charT rhs)
+{
+ basic_string <charT, traits> str (lhs);
+ str.append (1, rhs);
+ return str;
+}
+
+template <class charT, class traits>
+inline bool
+operator== (const basic_string <charT, traits>& lhs,
+ const basic_string <charT, traits>& rhs)
+{
+ return (lhs.compare (rhs) == 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator== (const charT* lhs, const basic_string <charT, traits>& rhs)
+{
+ return (rhs.compare (lhs) == 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator== (const basic_string <charT, traits>& lhs, const charT* rhs)
+{
+ return (lhs.compare (rhs) == 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator!= (const charT* lhs, const basic_string <charT, traits>& rhs)
+{
+ return (rhs.compare (lhs) != 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator!= (const basic_string <charT, traits>& lhs, const charT* rhs)
+{
+ return (lhs.compare (rhs) != 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator< (const basic_string <charT, traits>& lhs,
+ const basic_string <charT, traits>& rhs)
+{
+ return (lhs.compare (rhs) < 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator< (const charT* lhs, const basic_string <charT, traits>& rhs)
+{
+ return (rhs.compare (lhs) > 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator< (const basic_string <charT, traits>& lhs, const charT* rhs)
+{
+ return (lhs.compare (rhs) < 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator> (const charT* lhs, const basic_string <charT, traits>& rhs)
+{
+ return (rhs.compare (lhs) < 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator> (const basic_string <charT, traits>& lhs, const charT* rhs)
+{
+ return (lhs.compare (rhs) > 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator<= (const charT* lhs, const basic_string <charT, traits>& rhs)
+{
+ return (rhs.compare (lhs) >= 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator<= (const basic_string <charT, traits>& lhs, const charT* rhs)
+{
+ return (lhs.compare (rhs) <= 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator>= (const charT* lhs, const basic_string <charT, traits>& rhs)
+{
+ return (rhs.compare (lhs) <= 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator>= (const basic_string <charT, traits>& lhs, const charT* rhs)
+{
+ return (lhs.compare (rhs) >= 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator!= (const basic_string <charT, traits>& lhs,
+ const basic_string <charT, traits>& rhs)
+{
+ return (lhs.compare (rhs) != 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator> (const basic_string <charT, traits>& lhs,
+ const basic_string <charT, traits>& rhs)
+{
+ return (lhs.compare (rhs) > 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator<= (const basic_string <charT, traits>& lhs,
+ const basic_string <charT, traits>& rhs)
+{
+ return (lhs.compare (rhs) <= 0);
+}
+
+template <class charT, class traits>
+inline bool
+operator>= (const basic_string <charT, traits>& lhs,
+ const basic_string <charT, traits>& rhs)
+{
+ return (lhs.compare (rhs) >= 0);
+}
+
+class istream; class ostream;
+template <class charT, class traits> istream&
+operator>> (istream&, basic_string <charT, traits>&);
+template <class charT, class traits> ostream&
+operator<< (ostream&, const basic_string <charT, traits>&);
+template <class charT, class traits> istream&
+getline (istream&, basic_string <charT, traits>&, charT delim = '\n');
+
+} // extern "C++"
+
+#endif
diff --git a/libstdc++/std/complext.cc b/libstdc++/std/complext.cc
new file mode 100644
index 0000000..d50bf08
--- /dev/null
+++ b/libstdc++/std/complext.cc
@@ -0,0 +1,273 @@
+// Member templates for the -*- C++ -*- complex number classes.
+// Copyright (C) 1994 Free Software Foundation
+
+// This file is part of the GNU ANSI C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+// As a special exception, if you link this library with files
+// compiled with a GNU compiler to produce an executable, this does not cause
+// the resulting executable to be covered by the GNU General Public License.
+// This exception does not however invalidate any other reasons why
+// the executable file might be covered by the GNU General Public License.
+
+// Written by Jason Merrill based upon the specification in the 27 May 1994
+// C++ working paper, ANSI document X3J16/94-0098.
+
+#include <complex>
+
+extern "C++" {
+template <class FLOAT> complex<FLOAT>
+cos (const complex<FLOAT>& x)
+{
+ return complex<FLOAT> (cos (real (x)) * cosh (imag (x)),
+ - sin (real (x)) * sinh (imag (x)));
+}
+
+template <class FLOAT> complex<FLOAT>
+cosh (const complex<FLOAT>& x)
+{
+ return complex<FLOAT> (cosh (real (x)) * cos (imag (x)),
+ sinh (real (x)) * sin (imag (x)));
+}
+
+template <class FLOAT> complex<FLOAT>
+exp (const complex<FLOAT>& x)
+{
+ return polar (FLOAT (exp (real (x))), imag (x));
+}
+
+template <class FLOAT> complex<FLOAT>
+log (const complex<FLOAT>& x)
+{
+ return complex<FLOAT> (log (abs (x)), arg (x));
+}
+
+template <class FLOAT> complex<FLOAT>
+pow (const complex<FLOAT>& x, const complex<FLOAT>& y)
+{
+ FLOAT logr = log (abs (x));
+ FLOAT t = arg (x);
+
+ return polar (FLOAT (exp (logr * real (y) - imag (y) * t)),
+ FLOAT (imag (y) * logr + real (y) * t));
+}
+
+template <class FLOAT> complex<FLOAT>
+pow (const complex<FLOAT>& x, FLOAT y)
+{
+ return exp (FLOAT (y) * log (x));
+}
+
+template <class FLOAT> complex<FLOAT>
+pow (FLOAT x, const complex<FLOAT>& y)
+{
+ return exp (y * FLOAT (log (x)));
+}
+
+template <class FLOAT> complex<FLOAT>
+sin (const complex<FLOAT>& x)
+{
+ return complex<FLOAT> (sin (real (x)) * cosh (imag (x)),
+ cos (real (x)) * sinh (imag (x)));
+}
+
+template <class FLOAT> complex<FLOAT>
+sinh (const complex<FLOAT>& x)
+{
+ return complex<FLOAT> (sinh (real (x)) * cos (imag (x)),
+ cosh (real (x)) * sin (imag (x)));
+}
+
+#include <iostream.h>
+
+template <class FLOAT> istream&
+operator >> (istream& is, complex<FLOAT>& x)
+{
+ FLOAT re, im = 0;
+ char ch = 0;
+
+ if (is.ipfx0 ())
+ {
+ if (is.peek () == '(')
+ is >> ch;
+ is >> re;
+ if (ch == '(')
+ {
+ is >> ch;
+ if (ch == ',')
+ is >> im >> ch;
+ }
+ }
+ is.isfx ();
+
+ if (ch != 0 && ch != ')')
+ is.setstate (ios::failbit);
+ else if (is.good ())
+ x = complex<FLOAT> (re, im);
+
+ return is;
+}
+
+template <class FLOAT> ostream&
+operator << (ostream& os, const complex<FLOAT>& x)
+{
+ return os << '(' << real (x) << ',' << imag (x) << ')';
+}
+
+// The code below is adapted from f2c's libF77, and is subject to this
+// copyright:
+
+/****************************************************************
+Copyright 1990, 1991, 1992, 1993 by AT&T Bell Laboratories and Bellcore.
+
+Permission to use, copy, modify, and distribute this software
+and its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the names of AT&T Bell Laboratories or
+Bellcore or any of their entities not be used in advertising or
+publicity pertaining to distribution of the software without
+specific, written prior permission.
+
+AT&T and Bellcore disclaim all warranties with regard to this
+software, including all implied warranties of merchantability
+and fitness. In no event shall AT&T or Bellcore be liable for
+any special, indirect or consequential damages or any damages
+whatsoever resulting from loss of use, data or profits, whether
+in an action of contract, negligence or other tortious action,
+arising out of or in connection with the use or performance of
+this software.
+****************************************************************/
+
+template <class FLOAT> complex<FLOAT>&
+__doadv (complex<FLOAT>* ths, const complex<FLOAT>& y)
+{
+ FLOAT ar = abs (y.re);
+ FLOAT ai = abs (y.im);
+ FLOAT nr, ni;
+ FLOAT t, d;
+ if (ar <= ai)
+ {
+ t = y.re / y.im;
+ d = y.im * (1 + t*t);
+ nr = (ths->re * t + ths->im) / d;
+ ni = (ths->im * t - ths->re) / d;
+ }
+ else
+ {
+ t = y.im / y.re;
+ d = y.re * (1 + t*t);
+ nr = (ths->re + ths->im * t) / d;
+ ni = (ths->im - ths->re * t) / d;
+ }
+ ths->re = nr;
+ ths->im = ni;
+ return *ths;
+}
+
+template <class FLOAT> complex<FLOAT>
+operator / (const complex<FLOAT>& x, const complex<FLOAT>& y)
+{
+ FLOAT ar = abs (real (y));
+ FLOAT ai = abs (imag (y));
+ FLOAT nr, ni;
+ FLOAT t, d;
+ if (ar <= ai)
+ {
+ t = real (y) / imag (y);
+ d = imag (y) * (1 + t*t);
+ nr = (real (x) * t + imag (x)) / d;
+ ni = (imag (x) * t - real (x)) / d;
+ }
+ else
+ {
+ t = imag (y) / real (y);
+ d = real (y) * (1 + t*t);
+ nr = (real (x) + imag (x) * t) / d;
+ ni = (imag (x) - real (x) * t) / d;
+ }
+ return complex<FLOAT> (nr, ni);
+}
+
+template <class FLOAT> complex<FLOAT>
+operator / (FLOAT x, const complex<FLOAT>& y)
+{
+ FLOAT ar = abs (real (y));
+ FLOAT ai = abs (imag (y));
+ FLOAT nr, ni;
+ FLOAT t, d;
+ if (ar <= ai)
+ {
+ t = real (y) / imag (y);
+ d = imag (y) * (1 + t*t);
+ nr = x * t / d;
+ ni = -x / d;
+ }
+ else
+ {
+ t = imag (y) / real (y);
+ d = real (y) * (1 + t*t);
+ nr = x / d;
+ ni = -x * t / d;
+ }
+ return complex<FLOAT> (nr, ni);
+}
+
+template <class FLOAT> complex<FLOAT>
+pow (const complex<FLOAT>& xin, int y)
+{
+ if (y == 0)
+ return complex<FLOAT> (1.0);
+ complex<FLOAT> r (1.0);
+ complex<FLOAT> x (xin);
+ if (y < 0)
+ {
+ y = -y;
+ x = 1/x;
+ }
+ for (;;)
+ {
+ if (y & 1)
+ r *= x;
+ if (y >>= 1)
+ x *= x;
+ else
+ return r;
+ }
+}
+
+template <class FLOAT> complex<FLOAT>
+sqrt (const complex<FLOAT>& x)
+{
+ FLOAT r = abs (x);
+ FLOAT nr, ni;
+ if (r == 0.0)
+ nr = ni = r;
+ else if (real (x) > 0)
+ {
+ nr = sqrt (0.5 * (r + real (x)));
+ ni = imag (x) / nr / 2;
+ }
+ else
+ {
+ ni = sqrt (0.5 * (r - real (x)));
+ if (imag (x) < 0)
+ ni = - ni;
+ nr = imag (x) / ni / 2;
+ }
+ return complex<FLOAT> (nr, ni);
+}
+} // extern "C++"
diff --git a/libstdc++/std/complext.h b/libstdc++/std/complext.h
new file mode 100644
index 0000000..57976f0
--- /dev/null
+++ b/libstdc++/std/complext.h
@@ -0,0 +1,423 @@
+// The template and inlines for the -*- C++ -*- complex number classes.
+// Copyright (C) 1994 Free Software Foundation
+
+// This file is part of the GNU ANSI C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the terms of
+// the GNU General Public License as published by the Free Software
+// Foundation; either version 2, or (at your option) any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+// As a special exception, if you link this library with files compiled
+// with a GNU compiler to produce an executable, this does not cause the
+// resulting executable to be covered by the GNU General Public License.
+// This exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+// Written by Jason Merrill based upon the specification in the 27 May 1994
+// C++ working paper, ANSI document X3J16/94-0098.
+
+#ifndef __COMPLEXT__
+#define __COMPLEXT__
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include <cmath>
+
+#if ! defined (__GNUG__) && ! defined (__attribute__)
+#define __attribute__(foo) /* Ignore. */
+#endif
+
+class istream;
+class ostream;
+
+extern "C++" {
+template <class _FLT>
+class complex
+{
+public:
+ complex (_FLT r = 0, _FLT i = 0): re (r), im (i) { }
+ complex& operator += (const complex&);
+ complex& operator -= (const complex&);
+ complex& operator *= (const complex&);
+ complex& operator /= (const complex&);
+ _FLT real () const { return re; }
+ _FLT imag () const { return im; }
+private:
+ _FLT re, im;
+
+ friend complex& __doapl (complex *, const complex&);
+ friend complex& __doami (complex *, const complex&);
+ friend complex& __doaml (complex *, const complex&);
+ friend complex& __doadv (complex *, const complex&);
+
+ // These functions are specified as friends for purposes of name injection;
+ // they do not actually reference private members.
+ friend _FLT real (const complex&) __attribute__ ((const));
+ friend _FLT imag (const complex&) __attribute__ ((const));
+ friend complex operator + (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator + (const complex&, _FLT) __attribute__ ((const));
+ friend complex operator + (_FLT, const complex&) __attribute__ ((const));
+ friend complex operator - (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator - (const complex&, _FLT) __attribute__ ((const));
+ friend complex operator - (_FLT, const complex&) __attribute__ ((const));
+ friend complex operator * (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator * (const complex&, _FLT) __attribute__ ((const));
+ friend complex operator * (_FLT, const complex&) __attribute__ ((const));
+ friend complex operator / (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator / (const complex&, _FLT) __attribute__ ((const));
+ friend complex operator / (_FLT, const complex&) __attribute__ ((const));
+ friend bool operator == (const complex&, const complex&) __attribute__ ((const));
+ friend bool operator == (const complex&, _FLT) __attribute__ ((const));
+ friend bool operator == (_FLT, const complex&) __attribute__ ((const));
+ friend bool operator != (const complex&, const complex&) __attribute__ ((const));
+ friend bool operator != (const complex&, _FLT) __attribute__ ((const));
+ friend bool operator != (_FLT, const complex&) __attribute__ ((const));
+ friend complex polar (_FLT, _FLT) __attribute__ ((const));
+ friend complex pow (const complex&, const complex&) __attribute__ ((const));
+ friend complex pow (const complex&, _FLT) __attribute__ ((const));
+ friend complex pow (const complex&, int) __attribute__ ((const));
+ friend complex pow (_FLT, const complex&) __attribute__ ((const));
+ friend istream& operator>> (istream&, complex&);
+ friend ostream& operator<< (ostream&, const complex&);
+};
+
+// Declare specializations.
+class complex<float>;
+class complex<double>;
+class complex<long double>;
+
+template <class _FLT>
+inline complex<_FLT>&
+__doapl (complex<_FLT>* ths, const complex<_FLT>& r)
+{
+ ths->re += r.re;
+ ths->im += r.im;
+ return *ths;
+}
+template <class _FLT>
+inline complex<_FLT>&
+complex<_FLT>::operator += (const complex<_FLT>& r)
+{
+ return __doapl (this, r);
+}
+
+template <class _FLT>
+inline complex<_FLT>&
+__doami (complex<_FLT>* ths, const complex<_FLT>& r)
+{
+ ths->re -= r.re;
+ ths->im -= r.im;
+ return *ths;
+}
+template <class _FLT>
+inline complex<_FLT>&
+complex<_FLT>::operator -= (const complex<_FLT>& r)
+{
+ return __doami (this, r);
+}
+
+template <class _FLT>
+inline complex<_FLT>&
+__doaml (complex<_FLT>* ths, const complex<_FLT>& r)
+{
+ _FLT f = ths->re * r.re - ths->im * r.im;
+ ths->im = ths->re * r.im + ths->im * r.re;
+ ths->re = f;
+ return *ths;
+}
+template <class _FLT>
+inline complex<_FLT>&
+complex<_FLT>::operator *= (const complex<_FLT>& r)
+{
+ return __doaml (this, r);
+}
+
+template <class _FLT> complex<_FLT>&
+ __doadv (complex<_FLT>* ths, const complex<_FLT>& r);
+
+template <class _FLT>
+inline complex<_FLT>&
+complex<_FLT>::operator /= (const complex<_FLT>& r)
+{
+ return __doadv (this, r);
+}
+
+template <class _FLT> inline _FLT
+imag (const complex<_FLT>& x) __attribute__ ((const));
+
+template <class _FLT> inline _FLT
+imag (const complex<_FLT>& x)
+{
+ return x.imag ();
+}
+
+template <class _FLT> inline _FLT
+real (const complex<_FLT>& x) __attribute__ ((const));
+
+template <class _FLT> inline _FLT
+real (const complex<_FLT>& x)
+{
+ return x.real ();
+}
+
+template <class _FLT> inline complex<_FLT>
+operator + (const complex<_FLT>& x, const complex<_FLT>& y) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+operator + (const complex<_FLT>& x, const complex<_FLT>& y)
+{
+ return complex<_FLT> (real (x) + real (y), imag (x) + imag (y));
+}
+
+template <class _FLT> inline complex<_FLT>
+operator + (const complex<_FLT>& x, _FLT y) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+operator + (const complex<_FLT>& x, _FLT y)
+{
+ return complex<_FLT> (real (x) + y, imag (x));
+}
+
+template <class _FLT> inline complex<_FLT>
+operator + (_FLT x, const complex<_FLT>& y) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+operator + (_FLT x, const complex<_FLT>& y)
+{
+ return complex<_FLT> (x + real (y), imag (y));
+}
+
+template <class _FLT> inline complex<_FLT>
+operator - (const complex<_FLT>& x, const complex<_FLT>& y) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+operator - (const complex<_FLT>& x, const complex<_FLT>& y)
+{
+ return complex<_FLT> (real (x) - real (y), imag (x) - imag (y));
+}
+
+template <class _FLT> inline complex<_FLT>
+operator - (const complex<_FLT>& x, _FLT y) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+operator - (const complex<_FLT>& x, _FLT y)
+{
+ return complex<_FLT> (real (x) - y, imag (x));
+}
+
+template <class _FLT> inline complex<_FLT>
+operator - (_FLT x, const complex<_FLT>& y) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+operator - (_FLT x, const complex<_FLT>& y)
+{
+ return complex<_FLT> (x - real (y), - imag (y));
+}
+
+template <class _FLT> inline complex<_FLT>
+operator * (const complex<_FLT>& x, const complex<_FLT>& y) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+operator * (const complex<_FLT>& x, const complex<_FLT>& y)
+{
+ return complex<_FLT> (real (x) * real (y) - imag (x) * imag (y),
+ real (x) * imag (y) + imag (x) * real (y));
+}
+
+template <class _FLT> inline complex<_FLT>
+operator * (const complex<_FLT>& x, _FLT y) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+operator * (const complex<_FLT>& x, _FLT y)
+{
+ return complex<_FLT> (real (x) * y, imag (x) * y);
+}
+
+template <class _FLT> inline complex<_FLT>
+operator * (_FLT x, const complex<_FLT>& y) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+operator * (_FLT x, const complex<_FLT>& y)
+{
+ return complex<_FLT> (x * real (y), x * imag (y));
+}
+
+template <class _FLT> complex<_FLT>
+operator / (const complex<_FLT>& x, _FLT y) __attribute__ ((const));
+
+template <class _FLT> complex<_FLT>
+operator / (const complex<_FLT>& x, _FLT y)
+{
+ return complex<_FLT> (real (x) / y, imag (x) / y);
+}
+
+template <class _FLT> inline complex<_FLT>
+operator + (const complex<_FLT>& x) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+operator + (const complex<_FLT>& x)
+{
+ return x;
+}
+
+template <class _FLT> inline complex<_FLT>
+operator - (const complex<_FLT>& x) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+operator - (const complex<_FLT>& x)
+{
+ return complex<_FLT> (-real (x), -imag (x));
+}
+
+template <class _FLT> inline bool
+operator == (const complex<_FLT>& x, const complex<_FLT>& y) __attribute__ ((const));
+
+template <class _FLT> inline bool
+operator == (const complex<_FLT>& x, const complex<_FLT>& y)
+{
+ return real (x) == real (y) && imag (x) == imag (y);
+}
+
+template <class _FLT> inline bool
+operator == (const complex<_FLT>& x, _FLT y) __attribute__ ((const));
+
+template <class _FLT> inline bool
+operator == (const complex<_FLT>& x, _FLT y)
+{
+ return real (x) == y && imag (x) == 0;
+}
+
+template <class _FLT> inline bool
+operator == (_FLT x, const complex<_FLT>& y) __attribute__ ((const));
+
+template <class _FLT> inline bool
+operator == (_FLT x, const complex<_FLT>& y)
+{
+ return x == real (y) && imag (y) == 0;
+}
+
+template <class _FLT> inline bool
+operator != (const complex<_FLT>& x, const complex<_FLT>& y) __attribute__ ((const));
+
+template <class _FLT> inline bool
+operator != (const complex<_FLT>& x, const complex<_FLT>& y)
+{
+ return real (x) != real (y) || imag (x) != imag (y);
+}
+
+template <class _FLT> inline bool
+operator != (const complex<_FLT>& x, _FLT y) __attribute__ ((const));
+
+template <class _FLT> inline bool
+operator != (const complex<_FLT>& x, _FLT y)
+{
+ return real (x) != y || imag (x) != 0;
+}
+
+template <class _FLT> inline bool
+operator != (_FLT x, const complex<_FLT>& y) __attribute__ ((const));
+
+template <class _FLT> inline bool
+operator != (_FLT x, const complex<_FLT>& y)
+{
+ return x != real (y) || imag (y) != 0;
+}
+
+// Some targets don't provide a prototype for hypot when -ansi.
+extern "C" double hypot (double, double) __attribute__ ((const));
+
+template <class _FLT> inline _FLT
+abs (const complex<_FLT>& x) __attribute__ ((const));
+
+template <class _FLT> inline _FLT
+abs (const complex<_FLT>& x)
+{
+ return hypot (real (x), imag (x));
+}
+
+template <class _FLT> inline _FLT
+arg (const complex<_FLT>& x) __attribute__ ((const));
+
+template <class _FLT> inline _FLT
+arg (const complex<_FLT>& x)
+{
+ return atan2 (imag (x), real (x));
+}
+
+template <class _FLT> inline complex<_FLT>
+polar (_FLT r, _FLT t) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+polar (_FLT r, _FLT t)
+{
+ return complex<_FLT> (r * cos (t), r * sin (t));
+}
+
+template <class _FLT> inline complex<_FLT>
+conj (const complex<_FLT>& x) __attribute__ ((const));
+
+template <class _FLT> inline complex<_FLT>
+conj (const complex<_FLT>& x)
+{
+ return complex<_FLT> (real (x), -imag (x));
+}
+
+template <class _FLT> inline _FLT
+norm (const complex<_FLT>& x) __attribute__ ((const));
+
+template <class _FLT> inline _FLT
+norm (const complex<_FLT>& x)
+{
+ return real (x) * real (x) + imag (x) * imag (x);
+}
+
+// Declarations of templates in complext.ccI
+
+template <class _FLT> complex<_FLT>
+ operator / (const complex<_FLT>&, const complex<_FLT>&) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ operator / (_FLT, const complex<_FLT>&) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ cos (const complex<_FLT>&) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ cosh (const complex<_FLT>&) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ exp (const complex<_FLT>&) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ log (const complex<_FLT>&) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ pow (const complex<_FLT>&, const complex<_FLT>&) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ pow (const complex<_FLT>&, _FLT) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ pow (const complex<_FLT>&, int) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ pow (_FLT, const complex<_FLT>&) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ sin (const complex<_FLT>&) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ sinh (const complex<_FLT>&) __attribute__ ((const));
+template <class _FLT> complex<_FLT>
+ sqrt (const complex<_FLT>&) __attribute__ ((const));
+
+template <class _FLT> istream& operator >> (istream&, complex<_FLT>&);
+template <class _FLT> ostream& operator << (ostream&, const complex<_FLT>&);
+} // extern "C++"
+
+// Specializations and such
+
+#include <std/fcomplex.h>
+#include <std/dcomplex.h>
+#include <std/ldcomplex.h>
+
+#endif
diff --git a/libstdc++/std/dcomplex.h b/libstdc++/std/dcomplex.h
new file mode 100644
index 0000000..fde3f09
--- /dev/null
+++ b/libstdc++/std/dcomplex.h
@@ -0,0 +1,94 @@
+// The -*- C++ -*- double_complex class.
+// Copyright (C) 1994 Free Software Foundation
+
+// This file is part of the GNU ANSI C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+// As a special exception, if you link this library with files
+// compiled with a GNU compiler to produce an executable, this does not cause
+// the resulting executable to be covered by the GNU General Public License.
+// This exception does not however invalidate any other reasons why
+// the executable file might be covered by the GNU General Public License.
+
+// Written by Jason Merrill based upon the specification in the 27 May 1994
+// C++ working paper, ANSI document X3J16/94-0098.
+
+#ifndef __DCOMPLEX__
+#define __DCOMPLEX__
+
+#ifdef __GNUG__
+#pragma interface "dcomplex"
+#endif
+
+extern "C++" {
+class complex<double>
+{
+public:
+ complex (double r = 0, double i = 0): re (r), im (i) { }
+ complex (const complex<float>& r): re (r.real ()), im (r.imag ()) { }
+ explicit complex (const complex<long double>& r);
+
+ complex& operator+= (const complex& r) { return __doapl (this, r); }
+ complex& operator-= (const complex& r) { return __doami (this, r); }
+ complex& operator*= (const complex& r) { return __doaml (this, r); }
+ complex& operator/= (const complex& r) { return __doadv (this, r); }
+
+ double real () const { return re; }
+ double imag () const { return im; }
+private:
+ double re, im;
+
+ friend complex& __doapl (complex *, const complex&);
+ friend complex& __doami (complex *, const complex&);
+ friend complex& __doaml (complex *, const complex&);
+ friend complex& __doadv (complex *, const complex&);
+
+ // These functions are specified as friends for purposes of name injection;
+ // they do not actually reference private members.
+ friend double real (const complex& x) { return x.real (); }
+ friend double imag (const complex& x) { return x.imag (); }
+ friend complex operator + (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator + (const complex&, double) __attribute__ ((const));
+ friend complex operator + (double, const complex&) __attribute__ ((const));
+ friend complex operator - (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator - (const complex&, double) __attribute__ ((const));
+ friend complex operator - (double, const complex&) __attribute__ ((const));
+ friend complex operator * (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator * (const complex&, double) __attribute__ ((const));
+ friend complex operator * (double, const complex&) __attribute__ ((const));
+ friend complex operator / (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator / (const complex&, double) __attribute__ ((const));
+ friend complex operator / (double, const complex&) __attribute__ ((const));
+ friend bool operator == (const complex&, const complex&) __attribute__ ((const));
+ friend bool operator == (const complex&, double) __attribute__ ((const));
+ friend bool operator == (double, const complex&) __attribute__ ((const));
+ friend bool operator != (const complex&, const complex&) __attribute__ ((const));
+ friend bool operator != (const complex&, double) __attribute__ ((const));
+ friend bool operator != (double, const complex&) __attribute__ ((const));
+ friend complex polar (double, double) __attribute__ ((const));
+ friend complex pow (const complex&, const complex&) __attribute__ ((const));
+ friend complex pow (const complex&, double) __attribute__ ((const));
+ friend complex pow (const complex&, int) __attribute__ ((const));
+ friend complex pow (double, const complex&) __attribute__ ((const));
+ friend istream& operator>> (istream&, complex&);
+ friend ostream& operator<< (ostream&, const complex&);
+};
+
+inline complex<float>::complex (const complex<double>& r)
+: re (r.real ()), im (r.imag ())
+{ }
+} // extern "C++"
+
+#endif
diff --git a/libstdc++/std/fcomplex.h b/libstdc++/std/fcomplex.h
new file mode 100644
index 0000000..3a389e0
--- /dev/null
+++ b/libstdc++/std/fcomplex.h
@@ -0,0 +1,90 @@
+// The -*- C++ -*- float_complex class.
+// Copyright (C) 1994 Free Software Foundation
+
+// This file is part of the GNU ANSI C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+// As a special exception, if you link this library with files
+// compiled with a GNU compiler to produce an executable, this does not cause
+// the resulting executable to be covered by the GNU General Public License.
+// This exception does not however invalidate any other reasons why
+// the executable file might be covered by the GNU General Public License.
+
+// Written by Jason Merrill based upon the specification in the 27 May 1994
+// C++ working paper, ANSI document X3J16/94-0098.
+
+#ifndef __FCOMPLEX__
+#define __FCOMPLEX__
+
+#ifdef __GNUG__
+#pragma interface "fcomplex"
+#endif
+
+extern "C++" {
+class complex<float>
+{
+public:
+ complex (float r = 0, float i = 0): re (r), im (i) { }
+ explicit complex (const complex<double>& r);
+ explicit complex (const complex<long double>& r);
+
+ complex& operator+= (const complex& r) { return __doapl (this, r); }
+ complex& operator-= (const complex& r) { return __doami (this, r); }
+ complex& operator*= (const complex& r) { return __doaml (this, r); }
+ complex& operator/= (const complex& r) { return __doadv (this, r); }
+
+ float real () const { return re; }
+ float imag () const { return im; }
+private:
+ float re, im;
+
+ friend complex& __doapl (complex *, const complex&);
+ friend complex& __doami (complex *, const complex&);
+ friend complex& __doaml (complex *, const complex&);
+ friend complex& __doadv (complex *, const complex&);
+
+ // These functions are specified as friends for purposes of name injection;
+ // they do not actually reference private members.
+ friend float real (const complex& x) { return x.real (); }
+ friend float imag (const complex& x) { return x.imag (); }
+ friend complex operator + (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator + (const complex&, float) __attribute__ ((const));
+ friend complex operator + (float, const complex&) __attribute__ ((const));
+ friend complex operator - (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator - (const complex&, float) __attribute__ ((const));
+ friend complex operator - (float, const complex&) __attribute__ ((const));
+ friend complex operator * (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator * (const complex&, float) __attribute__ ((const));
+ friend complex operator * (float, const complex&) __attribute__ ((const));
+ friend complex operator / (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator / (const complex&, float) __attribute__ ((const));
+ friend complex operator / (float, const complex&) __attribute__ ((const));
+ friend bool operator == (const complex&, const complex&) __attribute__ ((const));
+ friend bool operator == (const complex&, float) __attribute__ ((const));
+ friend bool operator == (float, const complex&) __attribute__ ((const));
+ friend bool operator != (const complex&, const complex&) __attribute__ ((const));
+ friend bool operator != (const complex&, float) __attribute__ ((const));
+ friend bool operator != (float, const complex&) __attribute__ ((const));
+ friend complex polar (float, float) __attribute__ ((const));
+ friend complex pow (const complex&, const complex&) __attribute__ ((const));
+ friend complex pow (const complex&, float) __attribute__ ((const));
+ friend complex pow (const complex&, int) __attribute__ ((const));
+ friend complex pow (float, const complex&) __attribute__ ((const));
+ friend istream& operator>> (istream&, complex&);
+ friend ostream& operator<< (ostream&, const complex&);
+};
+} // extern "C++"
+
+#endif
diff --git a/libstdc++/std/ldcomplex.h b/libstdc++/std/ldcomplex.h
new file mode 100644
index 0000000..9feb303
--- /dev/null
+++ b/libstdc++/std/ldcomplex.h
@@ -0,0 +1,98 @@
+// The -*- C++ -*- long_double_complex class.
+// Copyright (C) 1994 Free Software Foundation
+
+// This file is part of the GNU ANSI C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+// As a special exception, if you link this library with files
+// compiled with a GNU compiler to produce an executable, this does not cause
+// the resulting executable to be covered by the GNU General Public License.
+// This exception does not however invalidate any other reasons why
+// the executable file might be covered by the GNU General Public License.
+
+// Written by Jason Merrill based upon the specification in the 27 May 1994
+// C++ working paper, ANSI document X3J16/94-0098.
+
+#ifndef __LDCOMPLEX__
+#define __LDCOMPLEX__
+
+#ifdef __GNUG__
+#pragma interface "ldcomplex"
+#endif
+
+extern "C++" {
+class complex<long double>
+{
+public:
+ complex (long double r = 0, long double i = 0): re (r), im (i) { }
+ complex (const complex<float>& r): re (r.real ()), im (r.imag ()) { }
+ complex (const complex<double>& r): re (r.real ()), im (r.imag ()) { }
+
+ complex& operator+= (const complex& r) { return __doapl (this, r); }
+ complex& operator-= (const complex& r) { return __doami (this, r); }
+ complex& operator*= (const complex& r) { return __doaml (this, r); }
+ complex& operator/= (const complex& r) { return __doadv (this, r); }
+
+ long double real () const { return re; }
+ long double imag () const { return im; }
+private:
+ long double re, im;
+
+ friend complex& __doapl (complex *, const complex&);
+ friend complex& __doami (complex *, const complex&);
+ friend complex& __doaml (complex *, const complex&);
+ friend complex& __doadv (complex *, const complex&);
+
+ // These functions are specified as friends for purposes of name injection;
+ // they do not actually reference private members.
+ friend long double real (const complex& x) { return x.real (); }
+ friend long double imag (const complex& x) { return x.imag (); }
+ friend complex operator + (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator + (const complex&, long double) __attribute__ ((const));
+ friend complex operator + (long double, const complex&) __attribute__ ((const));
+ friend complex operator - (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator - (const complex&, long double) __attribute__ ((const));
+ friend complex operator - (long double, const complex&) __attribute__ ((const));
+ friend complex operator * (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator * (const complex&, long double) __attribute__ ((const));
+ friend complex operator * (long double, const complex&) __attribute__ ((const));
+ friend complex operator / (const complex&, const complex&) __attribute__ ((const));
+ friend complex operator / (const complex&, long double) __attribute__ ((const));
+ friend complex operator / (long double, const complex&) __attribute__ ((const));
+ friend bool operator == (const complex&, const complex&) __attribute__ ((const));
+ friend bool operator == (const complex&, long double) __attribute__ ((const));
+ friend bool operator == (long double, const complex&) __attribute__ ((const));
+ friend bool operator != (const complex&, const complex&) __attribute__ ((const));
+ friend bool operator != (const complex&, long double) __attribute__ ((const));
+ friend bool operator != (long double, const complex&) __attribute__ ((const));
+ friend complex polar (long double, long double) __attribute__ ((const));
+ friend complex pow (const complex&, const complex&) __attribute__ ((const));
+ friend complex pow (const complex&, long double) __attribute__ ((const));
+ friend complex pow (const complex&, int) __attribute__ ((const));
+ friend complex pow (long double, const complex&) __attribute__ ((const));
+ friend istream& operator>> (istream&, complex&);
+ friend ostream& operator<< (ostream&, const complex&);
+};
+
+inline complex<float>::complex (const complex<long double>& r)
+: re (r.real ()), im (r.imag ())
+{ }
+
+inline complex<double>::complex (const complex<long double>& r)
+: re (r.real ()), im (r.imag ())
+{ }
+} // extern "C++"
+
+#endif
diff --git a/libstdc++/std/straits.h b/libstdc++/std/straits.h
new file mode 100644
index 0000000..c80e7ab
--- /dev/null
+++ b/libstdc++/std/straits.h
@@ -0,0 +1,161 @@
+// Character traits template for the -*- C++ -*- string classes.
+// Copyright (C) 1994 Free Software Foundation
+
+// This file is part of the GNU ANSI C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+// As a special exception, if you link this library with files
+// compiled with a GNU compiler to produce an executable, this does not cause
+// the resulting executable to be covered by the GNU General Public License.
+// This exception does not however invalidate any other reasons why
+// the executable file might be covered by the GNU General Public License.
+
+// Written by Jason Merrill based upon the specification by Takanori Adachi
+// in ANSI X3J16/94-0013R2.
+
+#ifndef __STRING_CHAR_TRAITS__
+#define __STRING_CHAR_TRAITS__
+
+#ifdef __GNUG__
+// For string_char_traits <char>
+#pragma interface "std/straits.h"
+#endif
+
+#include <cstddef>
+
+extern "C++" {
+template <class charT>
+struct string_char_traits {
+ typedef charT char_type; // for users to acquire the basic character type
+
+ // constraints
+
+ static void assign (char_type& c1, const char_type& c2)
+ { c1 = c2; }
+ static bool eq (const char_type& c1, const char_type& c2)
+ { return (c1 == c2); }
+ static bool ne (const char_type& c1, const char_type& c2)
+ { return !(c1 == c2); }
+ static bool lt (const char_type& c1, const char_type& c2)
+ { return (c1 < c2); }
+ static char_type eos () { return char_type(); } // the null character
+ static bool is_del(char_type a) { return 0; }
+ // characteristic function for delimiters of charT
+
+ // speed-up functions
+
+ static int compare (const char_type* s1, const char_type* s2, size_t n)
+ {
+ size_t i;
+ for (i = 0; i < n; ++i)
+ if (ne (s1[i], s2[i]))
+ return lt (s1[i], s2[i]) ? -1 : 1;
+
+ return 0;
+ }
+
+ static size_t length (const char_type* s)
+ {
+ size_t l = 0;
+ while (ne (*s++, eos ()))
+ ++l;
+ return l;
+ }
+
+ static char_type* copy (char_type* s1, const char_type* s2, size_t n)
+ {
+ for (; n--; )
+ assign (s1[n], s2[n]);
+ return s1;
+ }
+
+ static char_type* move (char_type* s1, const char_type* s2, size_t n)
+ {
+ char_type a[n];
+ size_t i;
+ for (i = 0; i < n; ++i)
+ assign (a[i], s2[i]);
+ for (i = 0; i < n; ++i)
+ assign (s1[i], a[i]);
+ return s1;
+ }
+
+ static char_type* set (char_type* s1, const char_type& c, size_t n)
+ {
+ for (; n--; )
+ assign (s1[n], c);
+ return s1;
+ }
+};
+
+class istream;
+class ostream;
+#include <cctype>
+#include <cstring>
+
+struct string_char_traits <char> {
+ typedef char char_type;
+
+ static void assign (char_type& c1, const char_type& c2)
+ { c1 = c2; }
+ static bool eq (const char_type & c1, const char_type& c2)
+ { return (c1 == c2); }
+ static bool ne (const char_type& c1, const char_type& c2)
+ { return (c1 != c2); }
+ static bool lt (const char_type& c1, const char_type& c2)
+ { return (c1 < c2); }
+ static char_type eos () { return 0; }
+ static bool is_del(char_type a) { return isspace(a); }
+
+ static int compare (const char_type* s1, const char_type* s2, size_t n)
+ { return memcmp (s1, s2, n); }
+ static size_t length (const char_type* s)
+ { return strlen (s); }
+ static char_type* copy (char_type* s1, const char_type* s2, size_t n)
+ { return (char_type*) memcpy (s1, s2, n); }
+ static char_type* move (char_type* s1, const char_type* s2, size_t n)
+ { return (char_type*) memmove (s1, s2, n); }
+ static char_type* set (char_type* s1, const char_type& c, size_t n)
+ { return (char_type*) memset (s1, c, n); }
+};
+
+#if 0
+#include <cwctype>
+struct string_char_traits <wchar_t> {
+ typedef wchar_t char_type;
+
+ static void assign (char_type& c1, const char_type& c2)
+ { c1 = c2; }
+ static bool eq (const char_type & c1, const char_type& c2)
+ { return (c1 == c2); }
+ static bool ne (const char_type& c1, const char_type& c2)
+ { return (c1 != c2); }
+ static bool lt (const char_type& c1, const char_type& c2)
+ { return (c1 < c2); }
+ static char_type eos () { return 0; }
+ static bool is_del(char_type a) { return iswspace(a); }
+
+ static int compare (const char_type* s1, const char_type* s2, size_t n)
+ { return wmemcmp (s1, s2, n); }
+ static size_t length (const char_type* s)
+ { return wcslen (s); }
+ static char_type* copy (char_type* s1, const char_type* s2, size_t n)
+ { return wmemcpy (s1, s2, n); }
+ static char_type* set (char_type* s1, const char_type& c, size_t n)
+ { return wmemset (s1, c, n); }
+};
+#endif
+} // extern "C++"
+#endif