aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/bits
diff options
context:
space:
mode:
authorBenjamin Kosnik <bkoz@gcc.gnu.org>2000-04-21 20:33:34 +0000
committerBenjamin Kosnik <bkoz@gcc.gnu.org>2000-04-21 20:33:34 +0000
commitb2dad0e3727cadca78d4c2cc51596d1ef1bf0946 (patch)
treee72cc26bb321e8bf90f4e68330674848db54eddf /libstdc++-v3/bits
parent051d082b263958a8524d91066f5c481b9e048bfd (diff)
downloadgcc-b2dad0e3727cadca78d4c2cc51596d1ef1bf0946.zip
gcc-b2dad0e3727cadca78d4c2cc51596d1ef1bf0946.tar.gz
gcc-b2dad0e3727cadca78d4c2cc51596d1ef1bf0946.tar.bz2
libstdc++-v3: New directory.
2000-04-21 Benjamin Kosnik <bkoz@redhat.com> * libstdc++-v3: New directory. From-SVN: r33317
Diffstat (limited to 'libstdc++-v3/bits')
-rw-r--r--libstdc++-v3/bits/basic_file.h174
-rw-r--r--libstdc++-v3/bits/basic_ios.h216
-rw-r--r--libstdc++-v3/bits/basic_ios.tcc142
-rw-r--r--libstdc++-v3/bits/basic_string.h1039
-rw-r--r--libstdc++-v3/bits/c++config.h66
-rw-r--r--libstdc++-v3/bits/char_traits.h327
-rw-r--r--libstdc++-v3/bits/cpp_type_traits.h301
-rw-r--r--libstdc++-v3/bits/exception_support.h79
-rw-r--r--libstdc++-v3/bits/fpos.h121
-rw-r--r--libstdc++-v3/bits/fstream.tcc568
-rw-r--r--libstdc++-v3/bits/generic_shadow.h57
-rw-r--r--libstdc++-v3/bits/gslice.h117
-rw-r--r--libstdc++-v3/bits/gslice_array.h169
-rw-r--r--libstdc++-v3/bits/indirect_array.h160
-rw-r--r--libstdc++-v3/bits/ios_base.h576
-rw-r--r--libstdc++-v3/bits/istream.tcc1216
-rw-r--r--libstdc++-v3/bits/limits_generic.h786
-rw-r--r--libstdc++-v3/bits/locale_facets.h1935
-rw-r--r--libstdc++-v3/bits/locale_facets.tcc1440
-rw-r--r--libstdc++-v3/bits/localefwd.h497
-rw-r--r--libstdc++-v3/bits/mask_array.h160
-rw-r--r--libstdc++-v3/bits/ostream.tcc673
-rw-r--r--libstdc++-v3/bits/pthread_allocimpl.h495
-rw-r--r--libstdc++-v3/bits/sbuf_iter.h264
-rw-r--r--libstdc++-v3/bits/slice.h77
-rw-r--r--libstdc++-v3/bits/slice_array.h161
-rw-r--r--libstdc++-v3/bits/sstream.tcc221
-rw-r--r--libstdc++-v3/bits/std_algorithm.h40
-rw-r--r--libstdc++-v3/bits/std_bitset.h1216
-rw-r--r--libstdc++-v3/bits/std_cassert.h38
-rw-r--r--libstdc++-v3/bits/std_cctype.h210
-rw-r--r--libstdc++-v3/bits/std_cerrno.h39
-rw-r--r--libstdc++-v3/bits/std_cfloat.h46
-rw-r--r--libstdc++-v3/bits/std_ciso646.h71
-rw-r--r--libstdc++-v3/bits/std_climits.h39
-rw-r--r--libstdc++-v3/bits/std_clocale.h40
-rw-r--r--libstdc++-v3/bits/std_cmath.h247
-rw-r--r--libstdc++-v3/bits/std_complex.h966
-rw-r--r--libstdc++-v3/bits/std_csetjmp.h39
-rw-r--r--libstdc++-v3/bits/std_csignal.h39
-rw-r--r--libstdc++-v3/bits/std_cstdarg.h39
-rw-r--r--libstdc++-v3/bits/std_cstddef.h39
-rw-r--r--libstdc++-v3/bits/std_cstdio.h60
-rw-r--r--libstdc++-v3/bits/std_cstdlib.h53
-rw-r--r--libstdc++-v3/bits/std_cstring.h43
-rw-r--r--libstdc++-v3/bits/std_ctime.h39
-rw-r--r--libstdc++-v3/bits/std_cwchar.h108
-rw-r--r--libstdc++-v3/bits/std_cwctype.h164
-rw-r--r--libstdc++-v3/bits/std_deque.h41
-rw-r--r--libstdc++-v3/bits/std_exception.h80
-rw-r--r--libstdc++-v3/bits/std_fstream.h386
-rw-r--r--libstdc++-v3/bits/std_functional.h27
-rw-r--r--libstdc++-v3/bits/std_iomanip.h219
-rw-r--r--libstdc++-v3/bits/std_ios.h52
-rw-r--r--libstdc++-v3/bits/std_iosfwd.h157
-rw-r--r--libstdc++-v3/bits/std_iostream.h58
-rw-r--r--libstdc++-v3/bits/std_istream.h307
-rw-r--r--libstdc++-v3/bits/std_iterator.h46
-rw-r--r--libstdc++-v3/bits/std_list.h40
-rw-r--r--libstdc++-v3/bits/std_locale.h44
-rw-r--r--libstdc++-v3/bits/std_map.h40
-rw-r--r--libstdc++-v3/bits/std_memory.h124
-rw-r--r--libstdc++-v3/bits/std_new.h81
-rw-r--r--libstdc++-v3/bits/std_numeric.h41
-rw-r--r--libstdc++-v3/bits/std_ostream.h288
-rw-r--r--libstdc++-v3/bits/std_queue.h45
-rw-r--r--libstdc++-v3/bits/std_set.h40
-rw-r--r--libstdc++-v3/bits/std_sstream.h367
-rw-r--r--libstdc++-v3/bits/std_stack.h41
-rw-r--r--libstdc++-v3/bits/std_stdexcept.h90
-rw-r--r--libstdc++-v3/bits/std_streambuf.h460
-rw-r--r--libstdc++-v3/bits/std_string.h63
-rw-r--r--libstdc++-v3/bits/std_strstream.h159
-rw-r--r--libstdc++-v3/bits/std_typeinfo.h80
-rw-r--r--libstdc++-v3/bits/std_utility.h38
-rw-r--r--libstdc++-v3/bits/std_valarray.h748
-rw-r--r--libstdc++-v3/bits/std_vector.h42
-rw-r--r--libstdc++-v3/bits/stl_algo.h2900
-rw-r--r--libstdc++-v3/bits/stl_algobase.h652
-rw-r--r--libstdc++-v3/bits/stl_alloc.h905
-rw-r--r--libstdc++-v3/bits/stl_config.h490
-rw-r--r--libstdc++-v3/bits/stl_construct.h90
-rw-r--r--libstdc++-v3/bits/stl_deque.h1768
-rw-r--r--libstdc++-v3/bits/stl_function.h732
-rw-r--r--libstdc++-v3/bits/stl_heap.h281
-rw-r--r--libstdc++-v3/bits/stl_iterator.h1093
-rw-r--r--libstdc++-v3/bits/stl_iterator_base.h358
-rw-r--r--libstdc++-v3/bits/stl_list.h867
-rw-r--r--libstdc++-v3/bits/stl_map.h273
-rw-r--r--libstdc++-v3/bits/stl_multimap.h275
-rw-r--r--libstdc++-v3/bits/stl_multiset.h266
-rw-r--r--libstdc++-v3/bits/stl_numeric.h239
-rw-r--r--libstdc++-v3/bits/stl_pair.h101
-rw-r--r--libstdc++-v3/bits/stl_pthread_alloc.h31
-rw-r--r--libstdc++-v3/bits/stl_queue.h221
-rw-r--r--libstdc++-v3/bits/stl_range_errors.h74
-rw-r--r--libstdc++-v3/bits/stl_raw_storage_iter.h81
-rw-r--r--libstdc++-v3/bits/stl_relops.h62
-rw-r--r--libstdc++-v3/bits/stl_set.h259
-rw-r--r--libstdc++-v3/bits/stl_stack.h133
-rw-r--r--libstdc++-v3/bits/stl_string_fwd.h47
-rw-r--r--libstdc++-v3/bits/stl_tempbuf.h161
-rw-r--r--libstdc++-v3/bits/stl_threads.h369
-rw-r--r--libstdc++-v3/bits/stl_tree.h1368
-rw-r--r--libstdc++-v3/bits/stl_uninitialized.h281
-rw-r--r--libstdc++-v3/bits/stl_vector.h873
-rw-r--r--libstdc++-v3/bits/streambuf.tcc259
-rw-r--r--libstdc++-v3/bits/string.tcc858
-rw-r--r--libstdc++-v3/bits/type_traits.h387
-rw-r--r--libstdc++-v3/bits/valarray_array.h535
-rw-r--r--libstdc++-v3/bits/valarray_array.tcc161
-rw-r--r--libstdc++-v3/bits/valarray_meta.h1057
112 files changed, 38323 insertions, 0 deletions
diff --git a/libstdc++-v3/bits/basic_file.h b/libstdc++-v3/bits/basic_file.h
new file mode 100644
index 0000000..71fdb01
--- /dev/null
+++ b/libstdc++-v3/bits/basic_file.h
@@ -0,0 +1,174 @@
+// Wrapper of C-language FILE struct -*- C++ -*-
+
+// Copyright (C) 1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.8 File-based streams
+//
+
+#ifndef _CPP_BASIC_FILE
+#define _CPP_BASIC_FILE 1
+
+#include <bits/c++config.h>
+#include <bits/std_ios.h>
+
+namespace std {
+
+ // Some of these member functions are based on libio/filebuf.cc.
+ // Also note that the order and number of virtual functions has to precisely
+ // match the order and number in the _IO_jump_t struct defined in libioP.h.
+#if _GLIBCPP_BASIC_FILE_INHERITANCE
+ class __basic_file: public __c_file_type
+#else
+ class __basic_file
+#endif
+ {
+#if _GLIBCPP_BASIC_FILE_ENCAPSULATION
+ int _M_fileno;
+ __c_file_type* _M_cfile;
+#endif
+
+ public:
+ __basic_file(__c_lock* __lock = 0);
+
+ // Eqivalent to the normal fopen function.
+ __basic_file*
+ open(const char* __name, ios_base::openmode __mode, int __prot = 0664);
+
+ // Used for opening the standard streams, cin, cout, cerr, clog,
+ // and their wide-stream equivalents. Instead of calling open, it
+ // just sets __c_file_type->_fileno and the respective _flags bits, and
+ // returns.
+ __basic_file*
+ sys_open(int __fd, ios_base::openmode __mode);
+
+ __basic_file*
+ close();
+
+ bool
+ is_open();
+
+ // Needed by ios_base::sync_with_stdio.
+ int get_fileno(void);
+
+ // NB: Must match FILE specific jump table starting here--this
+ // means all virtual functions starting with the dtor must match,
+ // slot by slot. For glibc-based dystems, this means the _IO_FILE
+ // as the FILE struct and _IO_jump_t as the jump table.
+ virtual
+ ~__basic_file(); // Takes the place of __finish.
+
+ virtual int
+ overflow(int __c = EOF);
+
+ virtual int
+ underflow();
+
+ virtual int
+ uflow();
+
+ virtual int
+ pbackfail(int __c);
+
+ // A complex "write" function that sets all of __c_file_type's
+ // ponters and associated data members correctly and manages it's
+ // relation to the external byte sequence.
+ virtual streamsize
+ xsputn(const char* __s, streamsize __n);
+
+ // A complex "read" function that sets all of __c_file_type's
+ // ponters and associated data members correctly and manages it's
+ // relation to the external byte sequence.
+ virtual streamsize
+ xsgetn(char* __s, streamsize __n);
+
+ // A complex "seekoff" function that sets all of __c_file_type's
+ // ponters and associated data members correctly and manages it's
+ // relation to the external byte sequence.
+ virtual __c_streampos
+ seekoff(streamoff __off, ios_base::seekdir __way,
+ ios_base::openmode __mode = ios_base::in | ios_base::out);
+
+ // A complex "seekpos" function that sets all of __c_file_type's
+ // pointers and associated data members correctly and manages it's
+ // relation to the external byte sequence.
+ virtual __c_streampos
+ seekpos(__c_streampos __pos,
+ ios_base::openmode __mode = ios_base::in | ios_base::out);
+
+ virtual streambuf*
+ setbuf(char* __b, int __len);
+
+ virtual int
+ sync();
+
+ virtual int
+ doallocate();
+
+ // A simple read function for the external byte sequence, that
+ // does no mucking around with or setting of the pointers or flags
+ // in __c_file_type.
+ virtual streamsize
+ sys_read(char* __s, streamsize __n);
+
+ // A simple write function for the external byte sequence, that
+ // does no mucking around with or setting of the pointers or flags
+ // in __c_file_type.
+ virtual streamsize
+ sys_write(const char* __s, streamsize __n);
+
+ // A simple seek function for the external byte sequence, that
+ // does no mucking around with or setting of the pointers or flags
+ // in __c_file_type.
+ virtual __c_streampos
+ sys_seek(__c_streampos __off, ios_base::seekdir __way);
+
+ virtual int
+ sys_close();
+
+ virtual int
+ sys_stat(void* __v);
+
+ virtual int
+ showmanyc();
+
+ virtual void
+ imbue(void* __v);
+ };
+
+} // namespace std
+
+#endif /* _CPP_BASIC_FILE */
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/basic_ios.h b/libstdc++-v3/bits/basic_ios.h
new file mode 100644
index 0000000..8168ec0
--- /dev/null
+++ b/libstdc++-v3/bits/basic_ios.h
@@ -0,0 +1,216 @@
+// Iostreams base classes -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+#ifndef _CPP_BITS_BASICIOS_H
+#define _CPP_BITS_BASICIOS_H 1
+
+#include <bits/sbuf_iter.h>
+
+namespace std {
+
+ // 27.4.5 Template class basic_ios
+ template<typename _CharT, typename _Traits>
+ class basic_ios : public ios_base
+ {
+ public:
+
+ // Types:
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+
+ // Non-standard Types:
+ typedef ctype<_CharT> __ctype_type;
+ // From ostream
+ typedef ostreambuf_iterator<_CharT> __ostreambuf_iter;
+ typedef num_put<_CharT, __ostreambuf_iter> __numput_type;
+ typedef istreambuf_iterator<_CharT> __istreambuf_iter;
+ typedef num_get<_CharT, __istreambuf_iter> __numget_type;
+
+ // Data members:
+ private:
+ basic_ostream<_CharT, _Traits>* _M_tie;
+ char_type _M_fill;
+ iostate _M_exception;
+
+ protected:
+ basic_streambuf<_CharT, _Traits>* _M_streambuf;
+ iostate _M_streambuf_state;
+
+ // Cached use_facet<ctype>, which is based on the current locale info.
+ const __ctype_type* _M_fctype_ios;
+ // From ostream.
+ const __numput_type* _M_fnumput;
+ // From istream.
+ const __numget_type* _M_fnumget;
+
+ public:
+
+ inline const __ctype_type*
+ _M_get_fctype_ios(void)
+ { return _M_fctype_ios; }
+
+ inline const __numget_type*
+ _M_get_fnumget(void)
+ { return _M_fnumget; }
+
+ inline const __numput_type*
+ _M_get_fnumput(void)
+ { return _M_fnumput; }
+
+ operator void*() const
+ { return this->fail() ? 0 : const_cast<basic_ios*>(this); }
+
+ inline bool
+ operator!() const
+ { return this->fail(); }
+
+ inline iostate
+ rdstate() const
+ { return _M_streambuf_state; }
+
+ inline void
+ clear(iostate __state = goodbit)
+ {
+ if (this->rdbuf())
+ _M_streambuf_state = __state;
+ else
+ _M_streambuf_state = __state | badbit;
+ if ((this->rdstate() & this->exceptions()))
+ throw failure("basic_ios::clear(iostate) caused exception");
+ }
+
+ inline void
+ setstate(iostate __state)
+ { this->clear(this->rdstate() | __state); }
+
+ inline bool
+ good() const
+ { return this->rdstate() == 0; }
+
+ inline bool
+ eof() const
+ { return (this->rdstate() & eofbit) != 0; }
+
+ inline bool
+ fail() const
+ { return (this->rdstate() & (badbit | failbit)) != 0; }
+
+ inline bool
+ bad() const
+ { return (this->rdstate() & badbit) != 0; }
+
+ inline iostate
+ exceptions() const
+ { return _M_exception; }
+
+ inline void
+ exceptions(iostate __except)
+ {
+ _M_exception = __except;
+ this->clear(_M_streambuf_state);
+ }
+
+ // Constructor/destructor:
+ explicit
+ basic_ios(basic_streambuf<_CharT, _Traits>* __sb) : ios_base()
+ { this->init(__sb); }
+
+ virtual
+ ~basic_ios() { }
+
+ // Members:
+ inline basic_ostream<_CharT, _Traits>*
+ tie() const
+ { return _M_tie; }
+
+ inline basic_ostream<_CharT, _Traits>*
+ tie(basic_ostream<_CharT, _Traits>* __tiestr)
+ {
+ basic_ostream<_CharT, _Traits>* __old = _M_tie;
+ _M_tie = __tiestr;
+ return __old;
+ }
+
+ inline basic_streambuf<_CharT, _Traits>*
+ rdbuf() const
+ { return _M_streambuf; }
+
+ basic_streambuf<_CharT, _Traits>*
+ rdbuf(basic_streambuf<_CharT, _Traits>* __sb);
+
+ basic_ios&
+ copyfmt(const basic_ios& __rhs);
+
+ inline char_type
+ fill() const
+ { return _M_fill; }
+
+ inline char_type
+ fill(char_type __ch)
+ {
+ char_type __old = _M_fill;
+ _M_fill = __ch;
+ return __old;
+ }
+
+ // Locales:
+ locale
+ imbue(const locale& __loc);
+
+ char
+ narrow(char_type __c, char __dfault) const;
+
+ char_type
+ widen(char __c) const;
+
+ protected:
+ // 27.4.5.1 basic_ios constructors
+ basic_ios() : ios_base()
+ { }
+
+ void
+ init(basic_streambuf<_CharT, _Traits>* __sb);
+ };
+
+} // namespace std
+
+#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
+# define export
+//#include <bits/basic_ios.tcc>
+#endif
+
+#endif /* _CPP_BITS_BASICIOS_H */
+
+
+
+
+
diff --git a/libstdc++-v3/bits/basic_ios.tcc b/libstdc++-v3/bits/basic_ios.tcc
new file mode 100644
index 0000000..3c24e24
--- /dev/null
+++ b/libstdc++-v3/bits/basic_ios.tcc
@@ -0,0 +1,142 @@
+// basic_ios locale and locale-related member functions -*- C++ -*-
+
+// Copyright (C) 1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+#ifndef _CPP_BITS_BASICIOS_TCC
+#define _CPP_BITS_BASICIOS_TCC 1
+
+namespace std {
+
+ template<typename _CharT, typename _Traits>
+ basic_streambuf<_CharT, _Traits>*
+ basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __sb)
+ {
+ basic_streambuf<_CharT, _Traits>* __old = _M_streambuf;
+ _M_streambuf = __sb;
+ this->clear();
+ return __old;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ios<_CharT, _Traits>&
+ basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
+ {
+ // Per 27.1.1.1, do not call imbue, yet must trash all caches
+ // associated with imbue()
+
+ // Alloc any new word array first, so if it fails we have "rollback".
+ _Words* __words = (__rhs._M_word_limit <= _S_local_words) ?
+ _M_word_array : new _Words[__rhs._M_word_limit];
+
+ // XXX This is the only reason _Callback_list was defined
+ // inline. The suspicion is that this increased compilation
+ // times dramatically for functions that use this member
+ // function (inserters_extractors, ios_manip_fmtflags). FIX ME,
+ // clean this stuff up. Callbacks are broken right now, anyway.
+
+ // Bump refs before doing callbacks, for safety.
+ _Callback_list* __cb = __rhs._M_callbacks;
+ if (__cb)
+ __cb->_M_add_reference();
+ _M_call_callbacks(erase_event);
+ if (_M_words != _M_word_array)
+ delete [] _M_words;
+ _M_dispose_callbacks();
+
+ _M_callbacks = __cb; // NB: Don't want any added during above.
+ for (int __i = 0; __i < __rhs._M_word_limit; ++__i)
+ __words[__i] = __rhs._M_words[__i];
+ if (_M_words != _M_word_array)
+ delete [] _M_words;
+ _M_words = __words;
+ _M_word_limit = __rhs._M_word_limit;
+
+ this->flags(__rhs.flags());
+ this->width(__rhs.width());
+ this->precision(__rhs.precision());
+ this->tie(__rhs.tie());
+ this->fill(__rhs.fill());
+ // The next is required to be the last assignment.
+ this->exceptions(__rhs.exceptions());
+
+ _M_call_callbacks(copyfmt_event);
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ char
+ basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
+ { return _M_fctype_ios->narrow(__c, __dfault); }
+
+ template<typename _CharT, typename _Traits>
+ _CharT
+ basic_ios<_CharT, _Traits>::widen(char __c) const
+ { return _M_fctype_ios->widen(__c); }
+
+ // Locales:
+ template<typename _CharT, typename _Traits>
+ locale
+ basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
+ {
+ locale __old(this->getloc());
+ ios_base::imbue(__loc);
+ _M_fctype_ios = &use_facet<__ctype_type>(__loc);
+ _M_fnumput = &use_facet<__numput_type>(__loc);
+ _M_fnumget = &use_facet<__numget_type>(__loc);
+ if (this->rdbuf() != 0)
+ this->rdbuf()->pubimbue(__loc);
+ return __old;
+ }
+
+ template<typename _CharT, typename _Traits>
+ void
+ basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
+ {
+ // NB: This may be called more than once on the same object.
+ ios_base::_M_init();
+ locale __loc = this->getloc();
+ _M_fctype_ios = &use_facet<__ctype_type>(__loc);
+ // Should be filled in by ostream and istream, respectively.
+ _M_fnumput = &use_facet<__numput_type>(__loc);
+ _M_fnumget = &use_facet<__numget_type>(__loc);
+ _M_tie = 0;
+ _M_fill = this->widen(' ');
+ _M_exception = goodbit;
+ _M_streambuf = __sb;
+ iostate __state = __sb ? goodbit : badbit;
+ _M_streambuf_state = __state;
+ }
+
+} // namespace std
+
+#endif /* _CPP_BITS_BASICIOS_TCC */
+
+
+
+
+
diff --git a/libstdc++-v3/bits/basic_string.h b/libstdc++-v3/bits/basic_string.h
new file mode 100644
index 0000000..f80cc94
--- /dev/null
+++ b/libstdc++-v3/bits/basic_string.h
@@ -0,0 +1,1039 @@
+// Components for manipulating sequences of characters -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 21 Strings library
+//
+
+#ifndef _CPP_BITS_STRING_H
+#define _CPP_BITS_STRING_H 1
+
+#include <bits/exception_support.h>
+#include <atomicity.h>
+
+namespace std {
+
+ // Documentation? What's that?
+ // Nathan Myers <ncm@cantrip.org>.
+ //
+ // A string looks like this:
+ //
+ // [_Rep]
+ // _M_length
+ // [basic_string<char_type>] _M_capacity
+ // _M_dataplus _M_state
+ // _M_p ----------------> unnamed array of char_type
+
+ // Where the _M_p points to the first character in the string, and
+ // you cast it to a pointer-to-_Rep and subtract 1 to get a
+ // pointer to the header.
+
+ // This approach has the enormous advantage that a string object
+ // requires only one allocation. All the ugliness is confined
+ // within a single pair of inline functions, which each compile to
+ // a single "add" instruction: _Rep::_M_data(), and
+ // string::_M_rep(); and the allocation function which gets a
+ // block of raw bytes and with room enough and constructs a _Rep
+ // object at the front.
+
+ // The reason you want _M_data pointing to the character array and
+ // not the _Rep is so that the debugger can see the string
+ // contents. (Probably we should add a non-inline member to get
+ // the _Rep for the debugger to use, so users can check the actual
+ // string length.)
+
+ // Note that the _Rep object is a POD so that you can have a
+ // static "empty string" _Rep object already "constructed" before
+ // static constructors have run. The reference-count encoding is
+ // chosen so that a 0 indicates one reference, so you never try to
+ // destroy the empty-string _Rep object.
+
+ // All but the last paragraph is considered pretty conventional
+ // for a C++ string implementation.
+
+ // 21.3 Template class basic_string
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ class basic_string
+ {
+ // Types:
+ public:
+ typedef _Traits traits_type;
+ typedef typename _Traits::char_type value_type;
+ typedef _Alloc allocator_type;
+ typedef typename _Alloc::size_type size_type;
+ typedef typename _Alloc::difference_type difference_type;
+ typedef typename _Alloc::reference reference;
+ typedef typename _Alloc::const_reference const_reference;
+ typedef typename _Alloc::pointer pointer;
+ typedef typename _Alloc::const_pointer const_pointer;
+ typedef __normal_iterator<pointer, basic_string> iterator;
+ typedef __normal_iterator<const_pointer, basic_string> const_iterator;
+ typedef reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef reverse_iterator<iterator> reverse_iterator;
+
+ // Data Members:
+ // NB: This is an unsigned type, and thus represents the maximum
+ // size that the allocator can hold.
+ static const size_type npos = static_cast<size_type>(-1);
+
+ private:
+ // _Rep: string representation
+ // Invariants:
+ // 1. String really contains _M_length + 1 characters; last is set
+ // to 0 only on call to c_str(). We avoid instantiating
+ // _CharT() where the interface does not require it.
+ // 2. _M_capacity >= _M_length
+ // Allocated memory is always _M_capacity + (1 * sizeof(_CharT)).
+ // 3. _M_state has three states:
+ // -1: leaked, one reference, no ref-copies allowed, non-const.
+ // 0: one reference, non-const.
+ // n>0: n + 1 references, operations require a lock, const.
+ // 4. All fields==0 is an empty string, given the extra storage
+ // beyond-the-end for a null terminator; thus, the shared
+ // empty string representation needs no constructor.
+
+ struct _Rep
+ {
+ // Types:
+ typedef typename _Alloc::rebind<char>::other _Raw_bytes_alloc;
+
+ // NB: Would be better if atomicity.h defined type(s) itself.
+ typedef uint32_t _State_type;
+ typedef int32_t _Signed_state_type;
+
+ // (Public) Data members:
+
+ // The maximum number of individual char_type elements of an
+ // individual string is determined by _S_max_size. This is the
+ // value that will be returned by max_size(). (Whereas npos
+ // is the maximum number of bytes the allocator can allocate.)
+ // If one was to divvy up the theoretical largest size string,
+ // with a terminating character and m _CharT elements, it'd
+ // look like this:
+ // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
+ // Solving for m:
+ // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
+ // In addition, this implementation quarters this ammount.
+ static size_type _S_max_size;
+ static _CharT _S_terminal;
+
+ size_type _M_length;
+ size_type _M_capacity;
+ _State_type _M_state;
+
+ bool
+ _M_is_leaked() const
+ { return static_cast<_Signed_state_type>(_M_state) < 0; }
+
+ bool
+ _M_is_shared() const
+ { return static_cast<_Signed_state_type>(_M_state) > 0; }
+
+ void
+ _M_set_leaked()
+ { _M_state = _State_type(-1); }
+
+ void
+ _M_set_sharable()
+ { _M_state = 0; }
+
+ _CharT*
+ _M_refdata() throw()
+ { return reinterpret_cast<_CharT*> (this + 1); }
+
+ _CharT&
+ operator[](size_t __s) throw()
+ { return _M_refdata() [__s]; }
+
+ _CharT*
+ _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
+ { return (!_M_is_leaked() && __alloc1 == __alloc2) ?
+ _M_refcopy() : _M_clone(__alloc1); }
+
+ // Create & Destroy
+ static _Rep*
+ _S_create(size_t, const _Alloc&);
+
+ void
+ _M_dispose(const _Alloc& __a)
+ {
+ if (_Signed_state_type(exchange_and_add(&_M_state, -1)) <= 0)
+ _M_destroy(__a);
+ } // XXX MT
+
+ void
+ _M_destroy(const _Alloc&) throw();
+
+ _CharT*
+ _M_refcopy() throw()
+ {
+ atomic_add(&_M_state, 1);
+ return _M_refdata();
+ } // XXX MT
+
+ _CharT*
+ _M_clone(const _Alloc&, size_type __res = 0);
+
+#if _GLIBCPP_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 (*_S_excess_slop) (size_t __length, size_t __allocated);
+
+ inline static bool
+ __default_excess(size_t, size_t);
+#else
+ inline static bool
+ _S_excess_slop(size_t, size_t);
+#endif
+ };
+
+ // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
+ struct _Alloc_hider : _Alloc
+ {
+ _Alloc_hider(_CharT* __dat, const _Alloc& __a)
+ : _Alloc(__a), _M_p(__dat) { }
+
+ _CharT* _M_p; // The actual data.
+ };
+
+ mutable _Alloc_hider _M_dataplus;
+
+ _CharT*
+ _M_data() const
+ { return _M_dataplus._M_p; }
+
+ _CharT*
+ _M_data(_CharT* __p)
+ { return (_M_dataplus._M_p = __p); }
+
+ _Rep*
+ _M_rep() const
+ { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
+
+ // For the internal use we have functions similar to `begin'/`end'
+ // but they do not call _M_leak.
+ iterator
+ _M_ibegin() const { return iterator(_M_data()); }
+
+ iterator
+ _M_iend() const { return iterator(_M_data() + this->size()); }
+
+ void
+ _M_leak() // for use in begin() & non-const op[]
+ {
+ if (!_M_rep()->_M_is_leaked())
+ _M_leak_hard();
+ }
+
+ iterator
+ _M_check(size_type __pos) const
+ {
+ __OUTOFRANGE(__pos > this->size());
+ return _M_ibegin() + __pos;
+ }
+
+ // NB: _M_fold doesn't check for a bad __pos1 value.
+ iterator
+ _M_fold(size_type __pos, size_type __off) const
+ {
+ bool __testoff = __off < this->size() - __pos;
+ size_type __newoff = __testoff ? __off : this->size() - __pos;
+ return (_M_ibegin() + __pos + __newoff);
+ }
+
+ // _S_copy_chars is a separate template to permit specialization
+ // to optimize for the common case of pointers as iterators.
+ template<class _Iterator>
+ static void
+ _S_copy_chars(_CharT* __p, _Iterator __j1, _Iterator __j2)
+ {
+ for (; __j1 != __j2; ++__j1, ++__p)
+ traits_type::assign(*__p, *__j1); //these types are off
+ }
+
+ static void
+ _S_copy_chars(_CharT* __p, iterator __j1, iterator __j2)
+ { _S_copy_chars(__p, __j1.base(), __j2.base()); }
+
+ static void
+ _S_copy_chars(_CharT* __p, const_iterator __j1, const_iterator __j2)
+ { _S_copy_chars(__p, __j1.base(), __j2.base()); }
+
+ static void
+ _S_copy_chars(_CharT* __p, _CharT* __j1, _CharT* __j2)
+ { traits_type::copy(__p, __j1, __j2 - __j1); }
+
+ static void
+ _S_copy_chars(_CharT* __p, const _CharT* __j1, const _CharT* __j2)
+ { traits_type::copy(__p, __j1, __j2 - __j1); }
+
+ void
+ _M_mutate(size_type __pos, size_type __len1, size_type __len2);
+
+ void
+ _M_leak_hard();
+
+ // The following storage is init'd to 0 by the linker, resulting
+ // (carefully) in an empty string with one reference.
+ static size_type _S_empty_rep_storage[
+ (sizeof(_Rep) + sizeof(_CharT) + sizeof(size_type)-1)/sizeof(size_type)];
+
+ static _Rep&
+ _S_empty_rep()
+ { return *reinterpret_cast<_Rep*> (&_S_empty_rep_storage); }
+
+ public:
+ // Construct/copy/destroy:
+ // NB: We overload ctors in some cases instead of using default
+ // arguments, per 17.4.4.4 para. 2 item 2.
+
+ inline
+ basic_string();
+
+ explicit
+ basic_string(const _Alloc& __a);
+
+ // NB: per LWG issue 42, semantics different from IS:
+ basic_string(const basic_string& __str);
+ basic_string(const basic_string& __str, size_type __pos,
+ size_type __n = npos);
+ basic_string(const basic_string& __str, size_type __pos,
+ size_type __n, const _Alloc& __a);
+
+ basic_string(const _CharT* __s, size_type __n,
+ const _Alloc& __a = _Alloc());
+ basic_string(const _CharT* __s, const _Alloc& __a = _Alloc());
+ basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
+
+ template<class _InputIterator>
+ basic_string(_InputIterator __begin, _InputIterator __end,
+ const _Alloc& __a = _Alloc());
+
+ ~basic_string()
+ { _M_rep()->_M_dispose(this->get_allocator()); }
+
+ basic_string&
+ operator=(const basic_string& __str) { return this->assign(__str); }
+
+ basic_string&
+ operator=(const _CharT* __s) { return this->assign(__s); }
+
+ basic_string&
+ operator=(_CharT __c) { return this->assign(1, __c); }
+
+ // Iterators:
+ iterator
+ begin()
+ {
+ _M_leak();
+ return iterator(_M_data());
+ }
+
+ const_iterator
+ begin() const
+ { return const_iterator(_M_data()); }
+
+ iterator
+ end()
+ {
+ _M_leak();
+ return iterator(_M_data() + this->size());
+ }
+
+ const_iterator
+ end() const
+ { return const_iterator(_M_data() + this->size()); }
+
+ reverse_iterator
+ rbegin()
+ { return reverse_iterator(this->end()); }
+
+ const_reverse_iterator
+ rbegin() const
+ { return const_reverse_iterator(this->end()); }
+
+ reverse_iterator
+ rend()
+ { return reverse_iterator(this->begin()); }
+
+ const_reverse_iterator
+ rend() const
+ { return const_reverse_iterator(this->begin()); }
+
+ public:
+ // Capacity:
+ size_type
+ size() const { return _M_rep()->_M_length; }
+
+ size_type
+ length() const { return _M_rep()->_M_length; }
+
+ size_type
+ max_size() const { return _Rep::_S_max_size; }
+
+ void
+ resize(size_type __n, _CharT __c);
+
+ void
+ resize(size_type __n) { this->resize(__n, _CharT()); }
+
+ size_type
+ capacity() const { return _M_rep()->_M_capacity; }
+
+ void
+ reserve(size_type __res_arg = 0);
+
+ void
+ clear() { _M_mutate(0, this->size(), 0); }
+
+ bool
+ empty() const { return this->size() == 0; }
+
+ // Element access:
+ const_reference
+ operator[] (size_type __pos) const
+ { return _M_data()[__pos]; }
+
+ reference
+ operator[](size_type __pos)
+ {
+ _M_leak();
+ return _M_data()[__pos];
+ }
+
+ const_reference
+ at(size_type __n) const
+ {
+ __OUTOFRANGE(__n >= this->size());
+ return _M_data()[__n];
+ }
+
+ reference
+ at(size_type __n)
+ {
+ __OUTOFRANGE(__n >= size());
+ _M_leak();
+ return _M_data()[__n];
+ }
+
+ // Modifiers:
+ basic_string&
+ operator+=(const basic_string& __str) { return this->append(__str); }
+
+ basic_string&
+ operator+=(const _CharT* __s) { return this->append(__s); }
+
+ basic_string&
+ operator+=(_CharT __c) { return this->append(size_type(1), __c); }
+
+ basic_string&
+ append(const basic_string& __str);
+
+ basic_string&
+ append(const basic_string& __str, size_type __pos, size_type __n);
+
+ basic_string&
+ append(const _CharT* __s, size_type __n);
+
+ basic_string&
+ append(const _CharT* __s)
+ { return this->append(__s, traits_type::length(__s)); }
+
+ basic_string&
+ append(size_type __n, _CharT __c);
+
+ template<class _InputIterator>
+ basic_string&
+ append(_InputIterator __first, _InputIterator __last)
+ { return this->replace(_M_iend(), _M_iend(), __first, __last); }
+
+ void
+ push_back(_CharT __c)
+ { this->replace(_M_iend(), _M_iend(), 1, __c); }
+
+ basic_string&
+ assign(const basic_string& __str);
+
+ basic_string&
+ assign(const basic_string& __str, size_type __pos, size_type __n)
+ {
+ return this->assign(__str._M_check(__pos), __str._M_fold(__pos, __n));
+ }
+
+ basic_string&
+ assign(const _CharT* __s, size_type __n)
+ { return this->assign(__s, __s + __n); }
+
+ basic_string&
+ assign(const _CharT* __s)
+ { return this->assign(__s, __s + traits_type::length(__s)); }
+
+ basic_string&
+ assign(size_type __n, _CharT __c)
+ { return this->replace(_M_ibegin(), _M_iend(), __n, __c); }
+
+ template<class _InputIterator>
+ basic_string&
+ assign(_InputIterator __first, _InputIterator __last)
+ { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
+
+ void
+ insert(iterator __p, size_type __n, _CharT __c)
+ { this->replace(__p, __p, __n, __c); }
+
+ template<class _InputIterator>
+ void insert(iterator __p, _InputIterator __beg, _InputIterator __end)
+ { this->replace(__p, __p, __beg, __end); }
+
+ basic_string&
+ insert(size_type __pos1, const basic_string& __str)
+ {
+ iterator __p = _M_check(__pos1);
+ this->replace(__p, __p, __str._M_ibegin(), __str._M_iend());
+ return *this;
+ }
+
+ basic_string&
+ insert(size_type __pos1, const basic_string& __str,
+ size_type __pos2, size_type __n)
+ {
+ iterator __p = _M_check(__pos1);
+ this->replace(__p, __p, __str._M_check(__pos2),
+ __str._M_fold(__pos2, __n));
+ return *this;
+ }
+
+ basic_string&
+ insert(size_type __pos, const _CharT* __s, size_type __n)
+ {
+ iterator __p = _M_check(__pos);
+ this->replace(__p, __p, __s, __s + __n);
+ return *this;
+ }
+
+ basic_string&
+ insert(size_type __pos, const _CharT* __s)
+ { return this->insert(__pos, __s, traits_type::length(__s)); }
+
+ basic_string&
+ insert(size_type __pos, size_type __n, _CharT __c)
+ {
+ this->insert(_M_check(__pos), __n, __c);
+ return *this;
+ }
+
+ iterator
+ insert(iterator __p, _CharT __c = _CharT())
+ {
+ size_type __pos = __p - _M_ibegin();
+ this->insert(_M_check(__pos), size_type(1), __c);
+ _M_rep()->_M_set_leaked();
+ return this->_M_ibegin() + __pos;
+ }
+
+ basic_string&
+ erase(size_type __pos = 0, size_type __n = npos)
+ {
+ return this->replace(_M_check(__pos), _M_fold(__pos, __n),
+ _M_data(), _M_data());
+ }
+
+ iterator
+ erase(iterator __position)
+ {
+ size_type __i = __position - _M_ibegin();
+ this->replace(__position, __position + 1, _M_data(), _M_data());
+ _M_rep()->_M_set_leaked();
+ return _M_ibegin() + __i;
+ }
+
+ iterator
+ erase(iterator __first, iterator __last)
+ {
+ size_type __i = __first - _M_ibegin();
+ this->replace(__first, __last, _M_data(), _M_data());
+ _M_rep()->_M_set_leaked();
+ return _M_ibegin() + __i;
+ }
+
+ basic_string&
+ replace(size_type __pos, size_type __n, const basic_string& __str)
+ {
+ return this->replace(_M_check(__pos), _M_fold(__pos, __n),
+ __str.begin(), __str.end());
+ }
+
+ basic_string&
+ replace(size_type __pos1, size_type __n1, const basic_string& __str,
+ size_type __pos2, size_type __n2);
+
+ basic_string&
+ replace(size_type __pos, size_type __n1, const _CharT* __s,
+ size_type __n2)
+ {
+ return this->replace(_M_check(__pos), _M_fold(__pos, __n1),
+ __s, __s + __n2);
+ }
+
+ basic_string&
+ replace(size_type __pos, size_type __n1, const _CharT* __s)
+ {
+ return this->replace(_M_check(__pos), _M_fold(__pos, __n1),
+ __s, __s + traits_type::length(__s));
+ }
+
+ basic_string&
+ replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
+ {
+ return this->replace(_M_check(__pos), _M_fold(__pos, __n1), __n2, __c);
+ }
+
+ basic_string&
+ replace(iterator __i1, iterator __i2, const basic_string& __str)
+ { return this->replace(__i1, __i2, __str.begin(), __str.end()); }
+
+ basic_string&
+ replace(iterator __i1, iterator __i2,
+ const _CharT* __s, size_type __n)
+ { return this->replace(__i1, __i2, __s, __s + __n); }
+
+ basic_string&
+ replace(iterator __i1, iterator __i2, const _CharT* __s)
+ { return this->replace(__i1, __i2, __s,
+ __s + traits_type::length(__s)); }
+
+ basic_string&
+ replace(iterator __i1, iterator __i2, size_type __n, _CharT __c);
+
+ template<class _InputIterator>
+ basic_string&
+ replace(iterator __i1, iterator __i2,
+ _InputIterator __j1, _InputIterator __j2)
+ { return _M_replace(__i1, __i2, __j1, __j2,
+ typename iterator_traits<_InputIterator>::iterator_category()); }
+
+ private:
+ template<class _InputIterator>
+ basic_string&
+ _M_replace(iterator __i1, iterator __i2, _InputIterator __j1,
+ _InputIterator __j2, input_iterator_tag);
+
+ template<class _FwdIterator>
+ basic_string&
+ _M_replace(iterator __i1, iterator __i2, _FwdIterator __j1,
+ _FwdIterator __j2, forward_iterator_tag);
+
+ // _S_construct_aux is used to implement the 21.3.1 para 15 which
+ // requires special behaviour if _InIter is an integral type
+ template<class _InIter>
+ static _CharT*
+ _S_construct_aux(_InIter __beg, _InIter __end, const _Alloc& __a,
+ __false_type)
+ {
+ typedef typename iterator_traits<_InIter>::iterator_category _Tag;
+ return _S_construct(__beg, __end, __a, _Tag());
+ }
+
+ template<class _InIter>
+ static _CharT*
+ _S_construct_aux(_InIter __beg, _InIter __end, const _Alloc& __a,
+ __true_type)
+ {
+ return _S_construct(static_cast<size_type>(__beg),
+ static_cast<value_type>(__end), __a);
+ }
+
+ template<class _InIter>
+ static _CharT*
+ _S_construct(_InIter __beg, _InIter __end, const _Alloc& __a)
+ {
+ typedef typename _Is_integer<_InIter>::_Integral _Integral;
+ return _S_construct_aux(__beg, __end, __a, _Integral());
+ }
+
+ // For Input Iterators, used in istreambuf_iterators, etc.
+ template<class _InIter>
+ static _CharT*
+ _S_construct(_InIter __beg, _InIter __end, const _Alloc& __a,
+ input_iterator_tag);
+
+ // For forward_iterators up to random_access_iterators, used for
+ // string::iterator, _CharT*, etc.
+ template<class _FwdIter>
+ static _CharT*
+ _S_construct(_FwdIter __end, _FwdIter __beg, const _Alloc& __a,
+ forward_iterator_tag);
+
+ static _CharT*
+ _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
+
+ public:
+
+ size_type
+ copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
+
+ void
+ swap(basic_string<_CharT, _Traits, _Alloc>& __s);
+
+ // String operations:
+ const _CharT*
+ c_str() const
+ {
+ // MT: This assumes concurrent writes are OK.
+ size_type __n = this->size();
+ traits_type::assign(_M_data()[__n], _Rep::_S_terminal);
+ return _M_data();
+ }
+
+ const _CharT*
+ data() const { return _M_data(); }
+
+ allocator_type
+ get_allocator() const { return _M_dataplus; }
+
+ size_type
+ find(const _CharT* __s, size_type __pos, size_type __n) const;
+
+ size_type
+ find(const basic_string& __str, size_type __pos = 0) const
+ { return this->find(__str.data(), __pos, __str.size()); }
+
+ size_type
+ find(const _CharT* __s, size_type __pos = 0) const
+ { return this->find(__s, __pos, traits_type::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 this->rfind(__str.data(), __pos, __str.size()); }
+
+ 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 this->rfind(__s, __pos, traits_type::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 this->find_first_of(__str.data(), __pos, __str.size()); }
+
+ 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 this->find_first_of(__s, __pos, traits_type::length(__s)); }
+
+ size_type
+ find_first_of(_CharT __c, size_type __pos = 0) const
+ { return this->find(__c, __pos); }
+
+ size_type
+ find_last_of(const basic_string& __str, size_type __pos = npos) const
+ { return this->find_last_of(__str.data(), __pos, __str.size()); }
+
+ 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 this->find_last_of(__s, __pos, traits_type::length(__s)); }
+
+ size_type
+ find_last_of(_CharT __c, size_type __pos = npos) const
+ { return this->rfind(__c, __pos); }
+
+ size_type
+ find_first_not_of(const basic_string& __str, size_type __pos = 0) const
+ { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
+
+ 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 this->find_first_not_of(__s, __pos, traits_type::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 this->find_last_not_of(__str.data(), __pos, __str.size()); }
+
+ 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 this->find_last_not_of(__s, __pos, traits_type::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
+ {
+ __OUTOFRANGE(__pos > this->size());
+ return basic_string(*this, __pos, __n);
+ }
+
+ int
+ compare(const basic_string& __str) const
+ {
+ size_type __size = this->size();
+ size_type __osize = __str.size();
+ size_type __len = min(__size, __osize);
+
+ int __r = traits_type::compare(_M_data(), __str.data(), __len);
+ if (!__r)
+ __r = __size - __osize;
+ return __r;
+ }
+
+ int
+ compare(size_type __pos, size_type __n, const basic_string& __str) const;
+
+ int
+ compare(size_type __pos1, size_type __n1, const basic_string& __str,
+ size_type __pos2, size_type __n2) const;
+
+ int
+ compare(const _CharT* __s) const;
+
+ int
+ compare(size_type __pos, size_type __n1, const _CharT* __s,
+ size_type __n2 = npos) const;
+
+ private:
+ static const _CharT*
+ _S_find (const _CharT* __beg, const _CharT* __end, _CharT __c);
+ };
+
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline basic_string<_CharT, _Traits, _Alloc>::
+ basic_string()
+ : _M_dataplus(_S_empty_rep()._M_refcopy(), _Alloc()) { }
+
+ // operator+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>
+ operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ {
+ basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
+ __str.append(__rhs);
+ return __str;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT,_Traits,_Alloc>
+ operator+(const _CharT* __lhs,
+ const basic_string<_CharT,_Traits,_Alloc>& __rhs);
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT,_Traits,_Alloc>
+ operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline basic_string<_CharT, _Traits, _Alloc>
+ operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const _CharT* __rhs)
+ {
+ basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
+ __str.append(__rhs);
+ return __str;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline basic_string<_CharT, _Traits, _Alloc>
+ operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
+ {
+ typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
+ __string_type __str(__lhs);
+ __str.append(__string_type::size_type(1), __rhs);
+ return __str;
+ }
+
+ // operator ==
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __lhs.compare(__rhs) == 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator==(const _CharT* __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __rhs.compare(__lhs) == 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const _CharT* __rhs)
+ { return __lhs.compare(__rhs) == 0; }
+
+ // operator !=
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __rhs.compare(__lhs) != 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator!=(const _CharT* __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __rhs.compare(__lhs) != 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const _CharT* __rhs)
+ { return __lhs.compare(__rhs) != 0; }
+
+ // operator <
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __lhs.compare(__rhs) < 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const _CharT* __rhs)
+ { return __lhs.compare(__rhs) < 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator<(const _CharT* __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __rhs.compare(__lhs) > 0; }
+
+ // operator >
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __lhs.compare(__rhs) > 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const _CharT* __rhs)
+ { return __lhs.compare(__rhs) > 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator>(const _CharT* __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __rhs.compare(__lhs) < 0; }
+
+ // operator <=
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __lhs.compare(__rhs) <= 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const _CharT* __rhs)
+ { return __lhs.compare(__rhs) <= 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator<=(const _CharT* __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __rhs.compare(__lhs) >= 0; }
+
+ // operator >=
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __lhs.compare(__rhs) >= 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ const _CharT* __rhs)
+ { return __lhs.compare(__rhs) >= 0; }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+ operator>=(const _CharT* __lhs,
+ const basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { return __rhs.compare(__lhs) <= 0; }
+
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline void
+ swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
+ basic_string<_CharT, _Traits, _Alloc>& __rhs)
+ { __lhs.swap(__rhs); }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_istream<_CharT, _Traits>&
+ operator>>(basic_istream<_CharT, _Traits>& __is,
+ basic_string<_CharT, _Traits, _Alloc>& __str);
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __os,
+ const basic_string<_CharT, _Traits, _Alloc>& __str);
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_istream<_CharT,_Traits>&
+ getline(basic_istream<_CharT, _Traits>& __is,
+ basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline basic_istream<_CharT,_Traits>&
+ getline(basic_istream<_CharT, _Traits>& __is,
+ basic_string<_CharT, _Traits, _Alloc>& __str);
+
+} // namespace std
+
+#endif /* _CPP_BITS_STRING_H */
diff --git a/libstdc++-v3/bits/c++config.h b/libstdc++-v3/bits/c++config.h
new file mode 100644
index 0000000..780d3e1
--- /dev/null
+++ b/libstdc++-v3/bits/c++config.h
@@ -0,0 +1,66 @@
+// Predefined symbols and macros -*- C++ -*-
+
+// Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+#ifndef _CPP_CPPCONFIG
+#define _CPP_CPPCONFIG 1
+
+// The current version of the C++ library in compressed ISO date format.
+#define __GLIBCPP__ 20000324
+
+// This flag controls the error handling in string, and perhaps other
+// bits as time goes on: check out bits/basic_string.h for more
+// info. It also helps alleviate the circular dependency between
+// string and exception.
+# define _GLIBCPP_USE_EXCEPTIONS 1
+
+// This is necessary until Egcs supports separate template
+// compilation.
+#define _GLIBCPP_NO_TEMPLATE_EXPORT 1
+
+// This is a hack around not having either pre-compiled headers or
+// export compilation. If defined, the io, string, and valarray
+// headers will include all the necessary bits. If not defined, the
+// implementation optimizes the headers for the most commonly-used
+// types. For the io library, this means that larger, out-of-line
+// member functions are only declared, and definitions are not parsed
+// by the compiler, but instead instantiated into the library binary.
+//#define _GLIBCPP_FULLY_COMPLIANT_HEADERS 1
+
+// To enable older, ARM-style iostreams and other anachronisms use this.
+//#define _GLIBCPP_DEPRICATED 1
+
+// Use corrected code from the committee library group's issues list.
+# define _GLIBCPP_RESOLVE_LIB_DEFECTS 1
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/char_traits.h b/libstdc++-v3/bits/char_traits.h
new file mode 100644
index 0000000..3943e6e
--- /dev/null
+++ b/libstdc++-v3/bits/char_traits.h
@@ -0,0 +1,327 @@
+// Character Traits for use by standard string and iostream
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 21 Strings library
+//
+
+#ifndef _CPP_BITS_CHAR_TRAITS_H
+#define _CPP_BITS_CHAR_TRAITS_H 1
+
+#include <bits/std_cwchar.h> // For mbstate_t.
+#include <bits/std_cstring.h> // For memmove, memset, memchr
+#include <bits/fpos.h> // For streamoff, streamsize
+
+namespace std {
+
+ // Same as iosfwd
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ // Can't have self-recursive types for streampos.
+ // 21.1.3.1 char_traits sets size_type to streampos
+ // 27.4.1
+ // And here, where streampos is typedefed to fpos<traits::state_type>
+ typedef fpos<mbstate_t> streampos;
+# ifdef _GLIBCPP_USE_WCHAR_T
+ typedef fpos<mbstate_t> wstreampos;
+# endif
+#endif
+
+ // 21.1.2 Basis for explicit _Traits specialization
+ // NB: That for any given actual character type this definition is
+ // probably wrong.
+
+ template<class _CharT>
+ struct char_traits
+ {
+ typedef _CharT char_type;
+ // Unsigned as wint_t in unsigned.
+ typedef unsigned long int_type;
+ typedef streampos pos_type;
+ typedef streamoff off_type;
+ typedef mbstate_t state_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
+ lt(const char_type& __c1, const char_type& __c2)
+ { return __c1 < __c2; }
+
+ static int
+ compare(const char_type* __s1, const char_type* __s2, int_type __n)
+ {
+ for (int_type __i = 0; __i < __n; ++__i)
+ if (!eq(__s1[__i],__s2[__i]))
+ return lt(__s1[__i],__s2[__i]) ? -1 : 1;
+ return 0;
+ }
+
+ static size_t
+ length(const char_type* __s)
+ {
+ const char_type* __p = __s;
+ while (*__p) ++__p;
+ return (__p - __s);
+ }
+
+ static const char_type*
+ find(const char_type* __s, int __n, const char_type& __a)
+ {
+ for (const char_type* __p = __s; __p < __s+__n; ++__p)
+ if (*__p == __a) return __p;
+ return 0;
+ }
+
+ static char_type*
+ move(char_type* __s1, const char_type* __s2, int_type __n)
+ { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
+
+ static char_type*
+ copy(char_type* __s1, const char_type* __s2, int_type __n)
+ { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
+
+ static char_type*
+ assign(char_type* __s, int_type __n, char_type __a)
+ {
+ for (char_type* __p = __s; __p - __s < __n; ++__p)
+ assign(*__p, __a);
+ return __s;
+ }
+
+ static char_type
+ to_char_type(const int_type& __c)
+ { return char_type(__c); }
+
+ static int_type
+ to_int_type(const char_type& __c) { return int_type(__c); }
+
+ static bool
+ eq_int_type(const int_type& __c1, const int_type& __c2)
+ { return __c1 == __c2; }
+
+ static state_type
+ get_state (pos_type __pos) { return __pos.state(); }
+
+ static int_type
+ eof() { return static_cast<int_type>(-1); }
+
+ static int_type
+ eos() { return int_type(); }
+
+ static int_type
+ not_eof(const int_type& __c)
+ { return eq_int_type(__c, eof()) ? int_type(0) : __c; }
+ };
+
+ // 21.1.4 char_traits specializations
+ template<>
+ struct char_traits<char>
+ {
+ typedef char char_type;
+ typedef unsigned int int_type;
+ typedef streampos pos_type;
+ typedef streamoff off_type;
+ typedef mbstate_t state_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
+ lt(const char_type& __c1, const char_type& __c2)
+ { return __c1 < __c2; }
+
+ static int
+ compare(const char_type* __s1, const char_type* __s2, int_type __n)
+ { return memcmp(__s1, __s2, __n); }
+
+ static size_t
+ length(const char_type* __s)
+ { return strlen(__s); }
+
+ static const char_type*
+ find(const char_type* __s, int __n, const char_type& __a)
+ { return static_cast<char*>(memchr(__s, __a, __n)); }
+
+ static char_type*
+ move(char_type* __s1, const char_type* __s2, int_type __n)
+ { return static_cast<char*>(memmove(__s1, __s2, __n)); }
+
+ static char_type*
+ copy(char_type* __s1, const char_type* __s2, int_type __n)
+ { return static_cast<char*>(memcpy(__s1, __s2, __n)); }
+
+ static char_type*
+ assign(char_type* __s, int_type __n, char_type __a)
+ { return static_cast<char*>(memset(__s, __a, __n)); }
+
+ static char_type
+ to_char_type(const int_type& __c)
+ { return static_cast<char>(__c); }
+
+ // To keep both the byte 0xff and the eof symbol 0xffffffff
+ // from ending up as 0xffffffff.
+ static int_type
+ to_int_type(const char_type& __c)
+ { return static_cast<int_type>(static_cast<unsigned char>(__c)); }
+
+ static bool
+ eq_int_type(const int_type& __c1, const int_type& __c2)
+ { return __c1 == __c2; }
+
+ static state_type
+ get_state(pos_type __pos) { return __pos.state(); }
+
+ static int_type
+ eof() { return static_cast<int_type>(EOF); }
+
+ static int_type
+ eos() { return '\0'; }
+
+ static int_type
+ not_eof(const int_type& __c)
+ { return (__c == eof()) ? 0 : __c; }
+ };
+
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ struct char_traits<wchar_t>
+ {
+ typedef wchar_t char_type;
+ typedef wint_t int_type;
+ typedef wstreamoff off_type;
+ typedef wstreampos pos_type;
+ typedef mbstate_t state_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
+ lt(const char_type& __c1, const char_type& __c2)
+ { return __c1 < __c2; }
+
+ static int
+ compare(const char_type* __s1, const char_type* __s2, int_type __n)
+ {
+ for (int_type __i = 0; __i < __n; ++__i)
+ if (!eq(__s1[__i], __s2[__i]))
+ return lt(__s1[__i], __s2[__i]) ? -1 : 1;
+ return 0;
+ }
+
+ static size_t
+ length(const char_type* __s)
+ {
+ const char_type* __p = __s;
+ while (*__p)
+ ++__p;
+ return (__p - __s);
+ }
+
+ static const char_type*
+ find (const char_type* __s, int __n, const char_type& __a)
+ {
+ for (const char_type* __p = __s; __p < __s+__n; ++__p)
+ if (*__p == __a)
+ return __p;
+ return 0;
+ }
+
+ static char_type*
+ move(char_type* __s1, const char_type* __s2, int_type __n)
+ { return static_cast<wchar_t*>(memmove(__s1, __s2,
+ __n * sizeof(wchar_t))); }
+
+ static char_type*
+ copy(char_type* __s1, const char_type* __s2, int_type __n)
+ { return static_cast<wchar_t*>(memcpy(__s1, __s2,
+ __n * sizeof(wchar_t))); }
+
+ static char_type*
+ assign(char_type* __s, int_type __n, char_type __a)
+ {
+ for (char_type* __p = __s; __p < __s + __n; ++__p)
+ assign(*__p, __a);
+ return __s;
+ }
+
+ static char_type
+ to_char_type(const int_type& __c) { return char_type(__c); }
+
+ static int_type
+ to_int_type(const char_type& __c) { return int_type(__c); }
+
+ static bool
+ eq_int_type(const int_type& __c1, const int_type& __c2)
+ { return __c1 == __c2; }
+
+ static state_type
+ get_state(pos_type __pos) { return __pos.state(); }
+
+ static int_type
+ eof() { return static_cast<int_type>(WEOF); }
+
+ static int_type
+ eos() { return int_type(); }
+
+ static int_type
+ not_eof(const int_type& __c)
+ { return eq_int_type(__c, eof()) ? 0 : __c; }
+ };
+#endif //_GLIBCPP_USE_WCHAR_T
+
+ template<typename _CharT, typename _Traits>
+ struct _Char_traits_match
+ {
+ _CharT _M_c;
+ _Char_traits_match(_CharT const& __c) : _M_c(__c) { }
+
+ bool
+ operator()(_CharT const& __a) { return _Traits::eq(_M_c,__a); }
+ };
+
+} // namespace std
+
+
+#endif /* _CPP_BITS_CHAR_TRAITS_H */
+
+
diff --git a/libstdc++-v3/bits/cpp_type_traits.h b/libstdc++-v3/bits/cpp_type_traits.h
new file mode 100644
index 0000000..2b62ee8
--- /dev/null
+++ b/libstdc++-v3/bits/cpp_type_traits.h
@@ -0,0 +1,301 @@
+// The -*- C++ -*- type traits classes for internal use in libstdc++
+
+// Copyright (C) 2000 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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 Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
+
+#ifndef _CPP_BITS_CPP_TYPE_TRAITS_H
+#define _CPP_BITS_CPP_TYPE_TRAITS_H 1
+
+//
+// This file provides some compile-time information about various types.
+// These informations were designed, on purpose, to be constant-expressions
+// and not types as found in <stl/bits/type_traits.h>. In particular, they
+// can be used in control structures and the optimizer hopefully will do
+// the obvious thing.
+//
+// Why integral expressions, and not functions nor types?
+// Firstly, these compile-time information entities are used as
+// template-arguments so function return values won't work. We
+// need compile-time entities. We're left with types and constant
+// integral expressions.
+// Secondly, from the point of view of ease of use type-based compile-time
+// information is -not- *that* convenient. On has to write lots of
+// overloaded functions and to hope that the compiler will select the right
+// one. As a net effect, the overall structure isn't very clear at first
+// glance.
+// Thirdly, partial ordering and overload resolution (of template functions)
+// is very costly in terms of compiler-resource. It is a Good Thing to
+// keep these resource consumption as least as possible.
+//
+// -- Gaby (dosreis@cmla.ens-cachan.fr) 2000-03-06.
+//
+
+namespace std {
+
+ template<typename _Tp>
+ struct __is_void
+ {
+ enum
+ {
+ _M_type = 0
+ };
+ };
+
+ template<>
+ struct __is_void<void>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ //
+ // Integer types
+ //
+ template<typename _Tp>
+ struct __is_integer
+ {
+ enum
+ {
+ _M_type = 0
+ };
+ };
+
+ // Thirteen specializations (yes there are eleven standard integer
+ // types; 'long long' and 'unsigned long long' are supported as
+ // extensions)
+ template<>
+ struct __is_integer<bool>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ template<>
+ struct __is_integer<char>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ template<>
+ struct __is_integer<signed char>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ template<>
+ struct __is_integer<unsigned char>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+# ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ struct __is_integer<wchar_t>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+# endif
+
+ template<>
+ struct __is_integer<short>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ template<>
+ struct __is_integer<unsigned short>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ template<>
+ struct __is_integer<int>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ template<>
+ struct __is_integer<unsigned int>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ template<>
+ struct __is_integer<long>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ template<>
+ struct __is_integer<unsigned long>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+# ifdef _GLIBCPP_USE_LONG_LONG
+ template<>
+ struct __is_integer<long long>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ template<>
+ struct __is_integer<unsigned long long>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+# endif
+
+ //
+ // Floating point types
+ //
+ template<typename _Tp>
+ struct __is_floating
+ {
+ enum
+ {
+ _M_type = 0
+ };
+ };
+
+ // three specializations (float, double and 'long double')
+ template<>
+ struct __is_floating<float>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ template<>
+ struct __is_floating<double>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ template<>
+ struct __is_floating<long double>
+ {
+ enum
+ {
+ _M_type = 1
+ };
+ };
+
+ //
+ // An arithmetic type is an integer type or a floating point type
+ //
+ template<typename _Tp>
+ struct __is_arithmetic
+ {
+ enum
+ {
+ _M_type = __is_integer<_Tp>::_M_type || __is_floating<_Tp>::_M_type
+ };
+ };
+
+ //
+ // A fundamental type is `void' or and arithmetic type
+ //
+ template<typename _Tp>
+ struct __is_fundamental
+ {
+ enum
+ {
+ _M_type = __is_void<_Tp>::_M_type || __is_arithmetic<_Tp>::_M_type
+ };
+ };
+
+ //
+ // For the immediate use, the following is a good approximation
+ //
+ template<typename _Tp>
+ struct __is_pod
+ {
+ enum
+ {
+ _M_type = __is_fundamental<_Tp>::_M_type
+ };
+ };
+
+} // namespace std
+
+
+#endif //_CPP_BITS_CPP_TYPE_TRAITS_H
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/exception_support.h b/libstdc++-v3/bits/exception_support.h
new file mode 100644
index 0000000..e4d033c
--- /dev/null
+++ b/libstdc++-v3/bits/exception_support.h
@@ -0,0 +1,79 @@
+// Methods and support infrastructure for exceptions -*- C++ -*-
+
+// Copyright (C) 2000 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 15 Exception handling
+//
+
+// This file declares functions whose only purpose is to throw an
+// exception. They help break a circularity between <string> and
+// <stdexcept>. See src/stdexcept.cc, where these functions are
+// defined.
+
+// XXX: These functions serve a similar purpose to those in
+// stl/bits/stl_range_errors.h . Eventually the two approaches should
+// be merged.
+
+#ifndef _CPP_EXCEPTION_SUPPORT_H
+#define _CPP_EXCEPTION_SUPPORT_H 1
+
+namespace std {
+
+#if _GLIBCPP_USE_EXCEPTIONS
+ // Internal functions for string implementation.
+ extern void __out_of_range(const char *__str);
+ extern void __length_error(const char *__str);
+
+# define __OUTOFRANGE(__cond) \
+ do { if (__cond) __out_of_range(#__cond); } while (0)
+# define __LENGTHERROR(__cond) \
+ do { if (__cond) __length_error(#__cond); } while (0)
+#else
+# include <bits/std_cassert.h>
+# define __OUTOFRANGE(__cond) assert(!(__cond))
+# define __LENGTHERROR(__cond) assert(!(__cond))
+#endif
+
+} // namespace std
+
+#endif /* _CPP_EXCEPTION_SUPPORT_H */
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/fpos.h b/libstdc++-v3/bits/fpos.h
new file mode 100644
index 0000000..27792b0
--- /dev/null
+++ b/libstdc++-v3/bits/fpos.h
@@ -0,0 +1,121 @@
+// File position object and stream types
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27 Input/output library
+//
+
+#ifndef _CPP_BITS_FPOS_H
+#define _CPP_BITS_FPOS_H 1
+
+// Need this here as well as in std_ios because fpos is used in
+// char_traits, and char_traits is used by string, which may or may
+// not have included the std_ios file.
+#include <bits/c++io.h>
+
+namespace std {
+
+ // 27.4.1 Types
+
+ // 27.4.3 Template class fpos
+ template<typename _StateT>
+ class fpos
+ {
+ public:
+
+ // Types:
+ typedef _StateT __state_type;
+
+ __state_type
+ state() const { return _M_st; }
+
+ void
+ state(__state_type __st) { _M_st = __st; }
+
+ // NB: The standard defines only the implicit copy ctor and the
+ // previous two members. The rest is a "conforming extension".
+ fpos(): _M_st(__state_type()), _M_pos(streamoff()) { }
+
+ fpos(streamoff __pos, __state_type __st)
+ : _M_st(__st), _M_pos(__pos) { }
+
+ fpos(streamoff __pos)
+ : _M_st(), _M_pos(__pos) { }
+
+ operator streamoff() const { return _M_pos; }
+
+ fpos&
+ operator+=(streamoff __off) { _M_pos += __off; return *this; }
+
+ fpos&
+ operator-=(streamoff __off) { _M_pos -= __off; return *this; }
+
+ bool
+ operator==(const fpos& __pos2) const { return _M_pos == __pos2._M_pos; }
+
+ bool
+ operator!=(const fpos& __pos2) const { return _M_pos != __pos2._M_pos; }
+
+ streamoff
+ _M_position() const { return _M_pos; }
+
+ void
+ _M_position(streamoff __pos) { _M_pos = __pos; }
+
+ private:
+ __state_type _M_st;
+ streamoff _M_pos;
+ };
+
+ template<typename _State>
+ inline fpos<_State>
+ operator+(const fpos<_State>& __pos, streamoff __off)
+ {
+ fpos<_State> t(__pos);
+ return t += __off;
+ }
+
+ template<typename _State>
+ inline fpos<_State>
+ operator-(const fpos<_State>& __pos, streamoff __off)
+ {
+ fpos<_State> t(__pos);
+ return t -= __off;
+ }
+
+ template<typename _State>
+ inline streamoff
+ operator-(const fpos<_State>& __pos1, const fpos<_State>& __pos2)
+ { return __pos1._M_position() - __pos2._M_position(); }
+
+} // namespace std
+
+#endif /* _CPP_BITS_FPOS_H */
+
+
diff --git a/libstdc++-v3/bits/fstream.tcc b/libstdc++-v3/bits/fstream.tcc
new file mode 100644
index 0000000..52d71f5
--- /dev/null
+++ b/libstdc++-v3/bits/fstream.tcc
@@ -0,0 +1,568 @@
+// File based streams -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.8 File-based streams
+//
+
+#ifndef _CPP_BITS_FSTREAM_TCC
+#define _CPP_BITS_FSTREAM_TCC 1
+
+namespace std
+{
+ template<typename _CharT, typename _Traits>
+ void
+ basic_filebuf<_CharT, _Traits>::
+ _M_init_filebuf(void)
+ {
+ _M_buf_unified = true; // Tie input to output for basic_filebuf.
+ _M_buf_size = static_cast<int_type>(BUFSIZ * sizeof(char_type));
+ try {
+ _M_file = new __file_type(&_M_lock);
+ }
+ catch(...) {
+ delete _M_file;
+ throw;
+ }
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_filebuf<_CharT, _Traits>::
+ basic_filebuf()
+ : __streambuf_type(), _M_file(NULL), _M_last_overflowed(false),
+ _M_state_cur(), _M_state_beg()
+ { _M_fcvt = &use_facet<__codecvt_type>(this->getloc()); }
+
+
+ template<typename _CharT, typename _Traits>
+ basic_filebuf<_CharT, _Traits>::
+ basic_filebuf(int __fd, const char* /*__name*/, ios_base::openmode __mode)
+ : __streambuf_type(), _M_last_overflowed(false),
+ _M_state_cur(), _M_state_beg()
+ {
+ _M_fcvt = &use_facet<__codecvt_type>(this->getloc());
+ _M_init_filebuf();
+ _M_file->sys_open(__fd, __mode);
+ if (this->is_open() && _M_buf_size)
+ {
+ _M_mode = __mode;
+ // XXX So that istream::getc() will only need to get 1 char,
+ // as opposed to BUF_SIZE.
+ if (__fd == 0)
+ _M_buf_size = 1;
+
+ try {
+ _M_buf = new char_type[_M_buf_size];
+ }
+ catch(...) {
+ delete [] _M_buf;
+ throw;
+ }
+
+ this->_M_set_indeterminate();
+ }
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_filebuf<_CharT, _Traits>::__filebuf_type*
+ basic_filebuf<_CharT, _Traits>::
+ open(const char* __s, ios_base::openmode __mode)
+ {
+ __filebuf_type *__retval = NULL;
+ if (!this->is_open())
+ {
+ _M_init_filebuf();
+ _M_file->open(__s, __mode);
+ if (this->is_open() && _M_buf_size)
+ {
+ _M_mode = __mode;
+
+ try {
+ _M_buf = new char_type[_M_buf_size];
+ }
+ catch(...) {
+ delete [] _M_buf;
+ throw;
+ }
+
+ // For time being, set both (in/out) sets of pointers.
+ _M_set_indeterminate();
+ if (__mode & ios_base::ate
+ && this->seekoff(0, ios_base::end, __mode) < 0)
+ this->close();
+ __retval = this;
+ }
+ }
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_filebuf<_CharT, _Traits>::__filebuf_type*
+ basic_filebuf<_CharT, _Traits>::
+ close()
+ {
+ __filebuf_type *__retval = NULL;
+ if (this->is_open())
+ {
+ bool __testput = _M_out_cur && _M_out_beg < _M_out_end;
+ if (__testput)
+ _M_really_overflow(traits_type::eof());
+
+#if 0
+ // XXX not done
+ if (_M_last_overflowed)
+ {
+ _M_output_unshift();
+ _M_really_overflow(traits_type::eof());
+ }
+#endif
+
+ if (_M_file->close())
+ {
+ _M_mode = ios_base::openmode(0);
+ if (_M_buf_size)
+ delete [] _M_buf;
+ _M_buf = NULL;
+ this->setg(NULL, NULL, NULL);
+ this->setp(NULL, NULL);
+ __retval = this;
+ }
+ }
+ _M_last_overflowed = false;
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ streamsize
+ basic_filebuf<_CharT, _Traits>::
+ showmanyc()
+ {
+ streamsize __retval = -1;
+ bool __testin = _M_mode & ios_base::in;
+
+ if (__testin)
+ {
+ bool __testeof = false;
+ if (_M_in_cur >= _M_in_end)
+ __testeof = this->underflow() == traits_type::eof();
+ if (!__testeof)
+ __retval = (_M_in_end - _M_in_cur) / sizeof(char_type);
+ }
+ _M_last_overflowed = false;
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_filebuf<_CharT, _Traits>::int_type
+ basic_filebuf<_CharT, _Traits>::
+ underflow()
+ {
+ int_type __retval = traits_type::eof();
+ bool __testget = _M_in_cur && _M_in_beg < _M_in_cur;
+ bool __testinit = _M_is_indeterminate();
+ bool __testout = _M_mode & ios_base::out;
+ bool __testin = _M_mode & ios_base::in;
+
+ if (__testin)
+ {
+ // Sync internal and external buffers.
+ // NB: __testget -> __testput as _M_buf_unified here.
+ if (__testget)
+ {
+ if (__testout)
+ _M_really_overflow();
+ else
+ _M_file->seekoff(_M_in_cur - _M_in_beg, ios_base::cur,
+ ios_base::in);
+ }
+
+ if (__testinit || __testget)
+ {
+ // Part one: (Re)fill external buf (_M_file->_IO_*) from
+ // external byte sequence (whatever physical byte sink or
+ // FILE actually is.)
+ char __conv_buf[_M_buf_size];
+ int_type __size = _M_file->xsgetn(__conv_buf, _M_buf_size);
+
+ // Part two: (Re)fill internal buf contents from external buf.
+ if (0 < __size)
+ {
+ _M_set_determinate(__size);
+
+ char* __conv_cur = __conv_buf;
+ _M_state_beg = _M_state_cur;
+ __res_type __r = _M_fcvt->in(_M_state_cur,
+ __conv_buf,
+ __conv_buf + __size,
+ const_cast<const char*&>(__conv_cur),
+ _M_in_beg, _M_in_end, _M_in_cur);
+
+ if (__r == codecvt_base::partial)
+ {
+ // XXX Retry with larger _M_buf size.
+ }
+
+ // Set pointers to internal and external buffers
+ // correctly. . .
+ if (__r != codecvt_base::error)
+ {
+ if (__testout)
+ _M_out_cur = _M_in_cur;
+ __retval = traits_type::to_int_type(*_M_in_cur);
+ }
+
+ // Part three: Sync the current internal buffer
+ // position with the (now overshot) external buffer
+ // position.
+ pos_type __p = _M_file->seekoff(0 - __size, ios_base::cur,
+ ios_base::in);
+ if (__p._M_position() == -1)
+ {
+ // XXX Something is wrong, do error checking.
+ }
+ }
+ }
+ }
+ _M_last_overflowed = false;
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_filebuf<_CharT, _Traits>::int_type
+ basic_filebuf<_CharT, _Traits>::
+ pbackfail(int_type __i)
+ {
+ int_type __retval = traits_type::eof();
+ char_type __c = traits_type::to_char_type(__i);
+ bool __testeof = traits_type::eq_int_type(__i, traits_type::eof());
+ bool __testout = _M_mode & ios_base::out;
+ bool __testin = _M_mode & ios_base::in;
+
+ if (__testin)
+ {
+ if (!_M_is_indeterminate())
+ {
+ bool __testpb = _M_in_beg < _M_in_cur;
+ bool __testeq = traits_type::eq(__c, this->gptr()[-1]);
+
+ // Try to put back __c into input sequence in one of three ways.
+ // Order these tests done in is unspecified by the standard.
+ if (!__testeof && __testpb && __testeq)
+ {
+ --_M_in_cur;
+ if (__testout)
+ --_M_out_cur;
+ __retval = __i;
+ }
+ else if (!__testeof && __testpb && __testout)
+ {
+ --_M_in_cur;
+ if (__testout)
+ --_M_out_cur;
+ *_M_in_cur = __c;
+ __retval = __i;
+ }
+ else if (__testeof && __testpb)
+ {
+ --_M_in_cur;
+ if (__testout)
+ --_M_out_cur;
+ __retval = traits_type::not_eof(__i);
+ }
+ }
+ else
+ {
+ // Need to make a putback position available.
+ this->seekoff(-1, ios_base::cur);
+ this->underflow();
+ if (!__testeof)
+ {
+ *_M_in_cur = __c;
+ __retval = __c;
+ }
+ else
+ __retval = traits_type::not_eof(__i);
+ }
+ }
+ _M_last_overflowed = false;
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_filebuf<_CharT, _Traits>::int_type
+ basic_filebuf<_CharT, _Traits>::
+ overflow(int_type __c)
+ {
+ int_type __retval = traits_type::eof();
+ bool __testpos = _M_out_cur && _M_out_cur >= _M_buf + _M_buf_size;
+ bool __testout = _M_mode & ios_base::out;
+
+ if (__testout)
+ {
+ if (!__testpos)
+ {
+ *_M_out_cur = traits_type::to_char_type(__c);
+ _M_buf_bump(1);
+ __retval = traits_type::not_eof(__c);
+ }
+ else
+ __retval = this->_M_really_overflow(__c);
+ }
+
+ _M_last_overflowed = false; // Set in _M_really_overflow, below.
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_filebuf<_CharT, _Traits>::int_type
+ basic_filebuf<_CharT, _Traits>::
+ _M_really_overflow(int_type __c)
+ {
+ int_type __retval = traits_type::eof();
+ bool __testput = _M_out_cur && _M_out_beg < _M_out_end;
+ bool __testeof = traits_type::eq_int_type(__c, traits_type::eof());
+
+ if (__testput)
+ {
+ // Part one: Allocate temporary conversion buffer on
+ // stack. Convert internal buffer plus __c (ie,
+ // "pending sequence") to temporary conversion buffer.
+ int __plen = _M_out_end - _M_out_beg;
+ char_type __pbuf[__plen + sizeof(char_type)];
+ traits_type::copy(__pbuf, this->pbase(), __plen);
+ if (!__testeof)
+ {
+ __pbuf[__plen] = traits_type::to_char_type(__c);
+ ++__plen;
+ }
+
+ char_type* __pend;
+ char __conv_buf[__plen];
+ char* __conv_end;
+ _M_state_beg = _M_state_cur;
+
+ __res_type __r = _M_fcvt->out(_M_state_cur,
+ __pbuf, __pbuf + __plen,
+ const_cast<const char_type*&>(__pend),
+ __conv_buf, __conv_buf + __plen,
+ __conv_end);
+
+ // Part two: (Re)spill converted "pending sequence"
+ // contents (now in temporary conversion buffer) to
+ // external buffer (_M_file->_IO_*) using
+ // _M_file->sys_write(), and do error (minimal) checking.
+ if (__r != codecvt_base::error)
+ {
+ streamsize __r = _M_file->xsputn(__conv_buf, __plen);
+ // NB: Need this so that external byte sequence reflects
+ // internal buffer.
+ _M_file->sync();
+ if (__r == __plen)
+ {
+ _M_set_indeterminate();
+ __retval = traits_type::not_eof(__c);
+ }
+ }
+ }
+ _M_last_overflowed = true;
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_filebuf<_CharT, _Traits>::pos_type
+ basic_filebuf<_CharT, _Traits>::
+ seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode)
+ {
+ pos_type __retval = pos_type(off_type(-1));
+ bool __testopen = this->is_open();
+ bool __testin = __mode & ios_base::in && _M_mode & ios_base::in;
+ bool __testout = __mode & ios_base::out && _M_mode & ios_base::out;
+ int __width = _M_fcvt->encoding();
+ if (__width < 0)
+ __width = 0;
+ bool __testfail = __off != 0 && __width <= 0;
+
+ if (__testopen && !__testfail && (__testin || __testout))
+ {
+ if (__way != ios_base::cur || __off != 0)
+ {
+ off_type __computed_off = __width * __off;
+
+ bool __testget = _M_in_cur && _M_in_beg < _M_in_end;
+ bool __testput = _M_out_cur && _M_out_beg < _M_out_end;
+ // Sync the internal and external streams.
+ // out
+ if (__testput || _M_last_overflowed)
+ {
+ // Part one: update the output sequence.
+ this->sync();
+ // Part two: output unshift sequence.
+ _M_output_unshift();
+ }
+ //in
+ // NB: underflow() rewinds the external buffer.
+ else if (__testget && __way == ios_base::cur)
+ __computed_off += _M_in_cur - _M_in_beg;
+
+ __retval = _M_file->seekoff(__computed_off, __way, __mode);
+ if (__retval._M_position() == -1)
+ __retval == pos_type(off_type(-1));
+ _M_set_indeterminate();
+ }
+ // NB: Need to do this in case _M_file in indeterminate
+ // state, ie _M_file->_offset == -1
+ else
+ {
+ __retval = _M_file->seekoff(__off, ios_base::cur, __mode);
+ __retval += max(_M_out_cur, _M_in_cur) - _M_buf;
+ }
+ }
+ _M_last_overflowed = false;
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_filebuf<_CharT, _Traits>::pos_type
+ basic_filebuf<_CharT, _Traits>::
+ seekpos(pos_type __pos, ios_base::openmode __mode)
+ {
+ pos_type __retval;
+ off_type __off = __pos;
+
+ __retval = this->seekoff(__off, ios_base::beg, __mode);
+
+ _M_last_overflowed = false;
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ void
+ basic_filebuf<_CharT, _Traits>::
+ _M_output_unshift()
+ {
+#if 0
+ // XXX Not complete, or correct.
+ int __width = _M_fcvt->encoding();
+
+ if (__width < 0)
+ {
+ // Part one: call codecvt::unshift
+ int __unsft_len = 0;
+ char_type __unsft_buf[_M_buf_size];
+ char_type* __unsft_cur; // XXX Set to external buf.
+ _M_state_beg = _M_state_cur;
+ __res_type __r = _M_fcvt->unshift(_M_state_cur,
+ __unsft_buf,
+ __unsft_buf + _M_buf_size,
+ __unsft_cur);
+
+ // Note, for char_type == char, wchar_t unshift
+ // should store no charachers.
+ if (__r == codecvt_base::ok || __r == codecvt_base::noconv)
+ __unsft_len = __unsft_cur - __unsft_buf;
+
+ // "Output the resulting sequence."
+ if (__unsft_len)
+ {
+ int __plen = _M_out_cur - _M_out_beg;
+ int __rlen = __plen + __unsft_len;
+ char_type __rbuf[__rlen];
+ char_type* __rend;
+ traits_type::copy(__rbuf, this->pbase(), __plen);
+ traits_type::copy(__rbuf + __plen, __unsft_buf,
+ __unsft_len);
+
+ char __conv_buf[__rlen];
+ char* __conv_end;
+
+ _M_state_beg = _M_state_cur; // XXX Needed?
+ __r = _M_fcvt->out(_M_state_cur,
+ __rbuf, __rbuf + __rlen,
+ const_cast<const char_type*&>(__rend),
+ __conv_buf,
+ __conv_buf + __rlen,
+ __conv_end);
+
+ if (__r != codecvt_base::error)
+ {
+ streamsize __r = _M_file->xsputn(__conv_buf,
+ __rlen);
+ if (__r == __rlen)
+ {
+ _M_out_cur = _M_out_beg;
+ if (_M_mode & ios_base::in)
+ _M_in_cur = _M_out_cur;
+ }
+ else
+ {
+ // XXX Throw "wig out and die exception?"
+ }
+ }
+ }
+ }
+#endif
+ }
+
+ template<typename _CharT, typename _Traits>
+ void
+ basic_filebuf<_CharT, _Traits>::
+ imbue(const locale& __loc)
+ {
+ bool __testbeg = gptr() == eback() && pptr() == pbase();
+ bool __teststate = _M_fcvt->encoding() == -1;
+
+ _M_locale_set = true;
+ if (__testbeg && !__teststate && _M_locale_buf != __loc)
+ {
+ // XXX Will need to save these older values.
+ _M_locale_buf = __loc;
+ _M_fcvt = &use_facet<__codecvt_type>(_M_locale_buf);
+ // XXX Necessary?
+ _M_fctype_buf = &use_facet<__ctype_type>(_M_locale_buf);
+ }
+ // NB this may require the reconversion of previously
+ // converted chars. This in turn may cause the reconstruction
+ // of the original file. YIKES!!
+ // XXX The part in the above comment is not done.
+ _M_last_overflowed = false;
+ }
+
+} // namespace std
+
+#endif // _CPP_BITS_FSTREAM_TCC
+
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/generic_shadow.h b/libstdc++-v3/bits/generic_shadow.h
new file mode 100644
index 0000000..4aa3d4a
--- /dev/null
+++ b/libstdc++-v3/bits/generic_shadow.h
@@ -0,0 +1,57 @@
+// generic C header shadow file -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+// This file is included by all the standard C <foo.h> headers
+// after defining _SHADOW_NAME.
+
+#ifdef _IN_C_SWAMP_ /* sub-included by a C header */
+
+ // get out of the "swamp"
+ } // close extern "C"
+ } // close namespace _C_Swamp::
+
+# undef _IN_C_SWAMP_
+# include _SHADOW_NAME
+
+ // dive back into the "swamp"
+ namespace _C_Swamp {
+ extern "C" {
+# define _IN_C_SWAMP_
+
+#else /* not _IN_C_SWAMP_: directly included by user program */
+
+# include _SHADOW_NAME
+
+ // expose global C names, including non-standard ones, but shadow
+ // some names and types with the std:: C++ version.
+
+ using namespace ::_C_Swamp::_C_Shadow;
+
+#endif /* _IN_C_SWAMP_ */
+
diff --git a/libstdc++-v3/bits/gslice.h b/libstdc++-v3/bits/gslice.h
new file mode 100644
index 0000000..737254c
--- /dev/null
+++ b/libstdc++-v3/bits/gslice.h
@@ -0,0 +1,117 @@
+// The template and inlines for the -*- C++ -*- gslice class.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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 Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
+
+#ifndef _CPP_BITS_GSLICE_H
+#define _CPP_BITS_GSLICE_H
+
+namespace std {
+
+ class gslice
+ {
+ public:
+ gslice ();
+ gslice (size_t, const valarray<size_t>&, const valarray<size_t>&);
+ // XXX: the IS says the copy-ctor and copy-assignment operators are
+ // synthetized by the compiler but they are just unsuitable
+ // for a ref-counted semantic
+ gslice(const gslice&);
+ ~gslice();
+
+ // XXX: See the note above.
+ gslice& operator= (const gslice&);
+
+ size_t start () const;
+ valarray<size_t> size () const;
+ valarray<size_t> stride () const;
+
+ private:
+ struct _Indexer {
+ size_t _M_count;
+ size_t _M_start;
+ valarray<size_t> _M_size;
+ valarray<size_t> _M_stride;
+ valarray<size_t> _M_index;
+ _Indexer(size_t, const valarray<size_t>&,
+ const valarray<size_t>&);
+ void _M_increment_use() { ++_M_count; }
+ size_t _M_decrement_use() { return --_M_count; }
+ };
+
+ _Indexer* _M_index;
+
+ template<typename _Tp> friend class valarray;
+ };
+
+ inline size_t
+ gslice::start () const
+ { return _M_index ? _M_index->_M_start : 0; }
+
+ inline valarray<size_t>
+ gslice::size () const
+ { return _M_index ? _M_index->_M_size : valarray<size_t>(); }
+
+ inline valarray<size_t>
+ gslice::stride () const
+ { return _M_index ? _M_index->_M_stride : valarray<size_t>(); }
+
+ inline gslice::gslice () : _M_index(0) {}
+
+ inline
+ gslice::gslice(size_t __o, const valarray<size_t>& __l,
+ const valarray<size_t>& __s)
+ : _M_index(new gslice::_Indexer(__o, __l, __s)) {}
+
+ inline
+ gslice::gslice(const gslice& __g) : _M_index(__g._M_index)
+ { if (_M_index) _M_index->_M_increment_use(); }
+
+ inline
+ gslice::~gslice()
+ { if (_M_index && _M_index->_M_decrement_use() == 0) delete _M_index; }
+
+ inline gslice&
+ gslice::operator= (const gslice& __g)
+ {
+ if (__g._M_index) __g._M_index->_M_increment_use();
+ if (_M_index && _M_index->_M_decrement_use() == 0) delete _M_index;
+ _M_index = __g._M_index;
+ return *this;
+ }
+
+
+} // std::
+
+
+#endif /* _CPP_BITS_GSLICE_H */
+
+// Local Variables:
+// mode:c++
+// End:
diff --git a/libstdc++-v3/bits/gslice_array.h b/libstdc++-v3/bits/gslice_array.h
new file mode 100644
index 0000000..cad3485
--- /dev/null
+++ b/libstdc++-v3/bits/gslice_array.h
@@ -0,0 +1,169 @@
+// The template and inlines for the -*- C++ -*- gslice_array class.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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 Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
+
+#ifndef _CPP_BITS_GSLICE_ARRAY
+#define _CPP_BITS_GSLICE_ARRAY 1
+
+namespace std {
+
+ template<typename _Tp> class gslice_array
+ {
+ public:
+ typedef _Tp value_type;
+
+ void operator= (const valarray<_Tp>&) const;
+ void operator*= (const valarray<_Tp>&) const;
+ void operator/= (const valarray<_Tp>&) const;
+ void operator%= (const valarray<_Tp>&) const;
+ void operator+= (const valarray<_Tp>&) const;
+ void operator-= (const valarray<_Tp>&) const;
+ void operator^= (const valarray<_Tp>&) const;
+ void operator&= (const valarray<_Tp>&) const;
+ void operator|= (const valarray<_Tp>&) const;
+ void operator<<=(const valarray<_Tp>&) const;
+ void operator>>=(const valarray<_Tp>&) const;
+ void operator=(const _Tp&);
+
+ template<class _Dom>
+ void operator= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator*= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator/= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator%= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator+= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator-= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator^= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator&= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator|= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator<<= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator>>= (const _Expr<_Dom,_Tp>&) const;
+
+ private:
+ _Array<_Tp> _M_array;
+ const valarray<size_t>& _M_index;
+
+ friend class valarray<_Tp>;
+
+ gslice_array (_Array<_Tp>, const valarray<size_t>&);
+
+ // this constructor needs to be implemented.
+ gslice_array (const gslice_array&);
+
+ // not implemented
+ gslice_array();
+ gslice_array& operator= (const gslice_array&);
+ };
+
+ template<typename _Tp>
+ inline
+ gslice_array<_Tp>::gslice_array (_Array<_Tp> __a,
+ const valarray<size_t>& __i)
+ : _M_array (__a), _M_index (__i) {}
+
+
+ template<typename _Tp>
+ inline
+ gslice_array<_Tp>::gslice_array (const gslice_array<_Tp>& __a)
+ : _M_array (__a._M_array), _M_index (__a._M_index) {}
+
+
+ template<typename _Tp>
+ inline void
+ gslice_array<_Tp>::operator= (const _Tp& __t)
+ {
+ __valarray_fill (_M_array, _Array<size_t>(_M_index),
+ _M_index.size(), __t);
+ }
+
+ template<typename _Tp>
+ inline void
+ gslice_array<_Tp>::operator= (const valarray<_Tp>& __v) const
+ {
+ __valarray_copy (_Array<_Tp> (__v), __v.size (),
+ _M_array, _Array<size_t>(_M_index));
+ }
+
+ template<typename _Tp>
+ template<class E>
+ inline void
+ gslice_array<_Tp>::operator= (const _Expr<E, _Tp>& __e) const
+ {
+ __valarray_copy (__e, _M_index.size(), _M_array,
+ _Array<size_t>(_M_index));
+ }
+
+#undef _DEFINE_VALARRAY_OPERATOR
+#define _DEFINE_VALARRAY_OPERATOR(op, name) \
+template<typename _Tp> \
+inline void \
+gslice_array<_Tp>::operator##op##= (const valarray<_Tp>& __v) const \
+{ \
+ _Array_augmented_##name (_M_array, _Array<size_t>(_M_index), \
+ _Array<_Tp> (__v), __v.size ()); \
+} \
+ \
+template<typename _Tp> template<class E> \
+inline void \
+gslice_array<_Tp>::operator##op##= (const _Expr<E, _Tp>& __e) const \
+{ \
+ _Array_augmented_##name (_M_array, _Array<size_t>(_M_index), __e, \
+ _M_index.size()); \
+}
+
+_DEFINE_VALARRAY_OPERATOR(*, multiplies)
+_DEFINE_VALARRAY_OPERATOR(/, divides)
+_DEFINE_VALARRAY_OPERATOR(%, modulus)
+_DEFINE_VALARRAY_OPERATOR(+, plus)
+_DEFINE_VALARRAY_OPERATOR(-, minus)
+_DEFINE_VALARRAY_OPERATOR(^, xor)
+_DEFINE_VALARRAY_OPERATOR(&, and)
+_DEFINE_VALARRAY_OPERATOR(|, or)
+_DEFINE_VALARRAY_OPERATOR(<<, shift_left)
+_DEFINE_VALARRAY_OPERATOR(>>, shift_right)
+
+#undef _DEFINE_VALARRAY_OPERATOR
+
+} // std::
+
+#endif /* _CPP_BITS_GSLICE_ARRAY */
+
+// Local Variables:
+// mode:c++
+// End:
diff --git a/libstdc++-v3/bits/indirect_array.h b/libstdc++-v3/bits/indirect_array.h
new file mode 100644
index 0000000..73d382a
--- /dev/null
+++ b/libstdc++-v3/bits/indirect_array.h
@@ -0,0 +1,160 @@
+// The template and inlines for the -*- C++ -*- indirect_array class.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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 Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
+
+#ifndef _CPP_BITS_INDIRECT_ARRAY_H
+#define _CPP_BITS_INDIRECT_ARRAY_H
+
+namespace std {
+
+ template <class _Tp> class indirect_array
+ {
+ public:
+ typedef _Tp value_type;
+
+ void operator= (const valarray<_Tp>&) const;
+ void operator*= (const valarray<_Tp>&) const;
+ void operator/= (const valarray<_Tp>&) const;
+ void operator%= (const valarray<_Tp>&) const;
+ void operator+= (const valarray<_Tp>&) const;
+ void operator-= (const valarray<_Tp>&) const;
+ void operator^= (const valarray<_Tp>&) const;
+ void operator&= (const valarray<_Tp>&) const;
+ void operator|= (const valarray<_Tp>&) const;
+ void operator<<= (const valarray<_Tp>&) const;
+ void operator>>= (const valarray<_Tp>&) const;
+ void operator= (const _Tp&);
+ // ~indirect_array();
+
+ template<class _Dom>
+ void operator= (const _Expr<_Dom, _Tp>&) const;
+ template<class _Dom>
+ void operator*= (const _Expr<_Dom, _Tp>&) const;
+ template<class _Dom>
+ void operator/= (const _Expr<_Dom, _Tp>&) const;
+ template<class _Dom>
+ void operator%= (const _Expr<_Dom, _Tp>&) const;
+ template<class _Dom>
+ void operator+= (const _Expr<_Dom, _Tp>&) const;
+ template<class _Dom>
+ void operator-= (const _Expr<_Dom, _Tp>&) const;
+ template<class _Dom>
+ void operator^= (const _Expr<_Dom, _Tp>&) const;
+ template<class _Dom>
+ void operator&= (const _Expr<_Dom, _Tp>&) const;
+ template<class _Dom>
+ void operator|= (const _Expr<_Dom, _Tp>&) const;
+ template<class _Dom>
+ void operator<<= (const _Expr<_Dom, _Tp>&) const;
+ template<class _Dom>
+ void operator>>= (const _Expr<_Dom, _Tp>&) const;
+
+ private:
+ indirect_array (const indirect_array&);
+ indirect_array (_Array<_Tp>, size_t, _Array<size_t>);
+
+ friend class valarray<_Tp>;
+ friend class gslice_array<_Tp>;
+
+ const size_t _M_sz;
+ const _Array<size_t> _M_index;
+ const _Array<_Tp> _M_array;
+
+ // not implemented
+ indirect_array ();
+ indirect_array& operator= (const indirect_array&);
+ };
+
+ template<typename _Tp>
+ inline indirect_array<_Tp>::indirect_array(const indirect_array<_Tp>& __a)
+ : _M_sz (__a._M_sz), _M_index (__a._M_index),
+ _M_array (__a._M_array) {}
+
+ template<typename _Tp>
+ inline
+ indirect_array<_Tp>::indirect_array (_Array<_Tp> __a, size_t __s,
+ _Array<size_t> __i)
+ : _M_sz (__s), _M_index (__i), _M_array (__a) {}
+
+ // template<typename _Tp>
+ // inline indirect_array<_Tp>::~indirect_array() {}
+
+ template<typename _Tp>
+ inline void
+ indirect_array<_Tp>::operator= (const _Tp& __t)
+ { __valarray_fill(_M_array, _M_index, _M_sz, __t); }
+
+ template<typename _Tp>
+ inline void
+ indirect_array<_Tp>::operator= (const valarray<_Tp>& __v) const
+ { __valarray_copy (_Array<_Tp> (__v), _M_sz, _M_array, _M_index); }
+
+ template<typename _Tp>
+ template<class _Dom>
+ inline void
+ indirect_array<_Tp>::operator= (const _Expr<_Dom,_Tp>& __e) const
+ { __valarray_copy (__e, _M_sz, _M_array, _M_index); }
+
+#undef _DEFINE_VALARRAY_OPERATOR
+#define _DEFINE_VALARRAY_OPERATOR(op, name) \
+template<typename _Tp> \
+inline void \
+indirect_array<_Tp>::operator##op##= (const valarray<_Tp>& __v) const \
+{ \
+ _Array_augmented_##name (_M_array, _M_index, _Array<_Tp> (__v), _M_sz); \
+} \
+ \
+template<typename _Tp> template<class _Dom> \
+inline void \
+indirect_array<_Tp>::operator##op##= (const _Expr<_Dom,_Tp>& __e) const \
+{ \
+ _Array_augmented_##name (_M_array, _M_index, __e, _M_sz); \
+}
+
+_DEFINE_VALARRAY_OPERATOR(*, multiplies)
+_DEFINE_VALARRAY_OPERATOR(/, divides)
+_DEFINE_VALARRAY_OPERATOR(%, modulus)
+_DEFINE_VALARRAY_OPERATOR(+, plus)
+_DEFINE_VALARRAY_OPERATOR(-, minus)
+_DEFINE_VALARRAY_OPERATOR(^, xor)
+_DEFINE_VALARRAY_OPERATOR(&, and)
+_DEFINE_VALARRAY_OPERATOR(|, or)
+_DEFINE_VALARRAY_OPERATOR(<<, shift_left)
+_DEFINE_VALARRAY_OPERATOR(>>, shift_right)
+
+#undef _DEFINE_VALARRAY_OPERATOR
+
+} // std::
+
+#endif /* _CPP_BITS_INDIRECT_ARRAY_H */
+
+// Local Variables:
+// mode:c++
+// End:
diff --git a/libstdc++-v3/bits/ios_base.h b/libstdc++-v3/bits/ios_base.h
new file mode 100644
index 0000000..ee257c6
--- /dev/null
+++ b/libstdc++-v3/bits/ios_base.h
@@ -0,0 +1,576 @@
+// Iostreams base classes -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.8 File-based streams
+//
+
+#ifndef _CPP_BITS_IOSBASE_H
+#define _CPP_BITS_IOSBASE_H 1
+
+namespace std {
+
+ // The following definitions of bitmask types are enums, not ints,
+ // as permitted (but not required) in the standard, in order to provide
+ // better type safety in iostream calls. A side effect is that
+ // expressions involving them are no longer compile-time constants.
+ enum _Ios_Fmtflags { _S_ios_fmtflags_end = 1<<16 };
+
+ inline _Ios_Fmtflags
+ operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
+ { return _Ios_Fmtflags(static_cast<int>(__a) & static_cast<int>(__b)); }
+
+ inline _Ios_Fmtflags
+ operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
+ { return _Ios_Fmtflags(static_cast<int>(__a) | static_cast<int>(__b)); }
+
+ inline _Ios_Fmtflags
+ operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
+ { return _Ios_Fmtflags(static_cast<int>(__a) ^ static_cast<int>(__b)); }
+
+ inline _Ios_Fmtflags
+ operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
+ { return __a = __a | __b; }
+
+ inline _Ios_Fmtflags
+ operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
+ { return __a = __a & __b; }
+
+ inline _Ios_Fmtflags
+ operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
+ { return __a = __a ^ __b; }
+
+ inline _Ios_Fmtflags
+ operator~(_Ios_Fmtflags __a)
+ { return _Ios_Fmtflags(~static_cast<int>(__a)); }
+
+
+ enum _Ios_Openmode { _S_ios_openmode_end = 1<<16 };
+
+ inline _Ios_Openmode
+ operator&(_Ios_Openmode __a, _Ios_Openmode __b)
+ { return _Ios_Openmode(static_cast<int>(__a) & static_cast<int>(__b)); }
+
+ inline _Ios_Openmode
+ operator|(_Ios_Openmode __a, _Ios_Openmode __b)
+ { return _Ios_Openmode(static_cast<int>(__a) | static_cast<int>(__b)); }
+
+ inline _Ios_Openmode
+ operator^(_Ios_Openmode __a, _Ios_Openmode __b)
+ { return _Ios_Openmode(static_cast<int>(__a) ^ static_cast<int>(__b)); }
+
+ inline _Ios_Openmode
+ operator|=(_Ios_Openmode& __a, _Ios_Openmode __b)
+ { return __a = __a | __b; }
+
+ inline _Ios_Openmode
+ operator&=(_Ios_Openmode& __a, _Ios_Openmode __b)
+ { return __a = __a & __b; }
+
+ inline _Ios_Openmode
+ operator^=(_Ios_Openmode& __a, _Ios_Openmode __b)
+ { return __a = __a ^ __b; }
+
+ inline _Ios_Openmode
+ operator~(_Ios_Openmode __a)
+ { return _Ios_Openmode(~static_cast<int>(__a)); }
+
+
+ enum _Ios_Iostate { _S_ios_iostate_end = 1<<16 };
+
+ inline _Ios_Iostate
+ operator&(_Ios_Iostate __a, _Ios_Iostate __b)
+ { return _Ios_Iostate(static_cast<int>(__a) & static_cast<int>(__b)); }
+
+ inline _Ios_Iostate
+ operator|(_Ios_Iostate __a, _Ios_Iostate __b)
+ { return _Ios_Iostate(static_cast<int>(__a) | static_cast<int>(__b)); }
+
+ inline _Ios_Iostate
+ operator^(_Ios_Iostate __a, _Ios_Iostate __b)
+ { return _Ios_Iostate(static_cast<int>(__a) ^ static_cast<int>(__b)); }
+
+ inline _Ios_Iostate
+ operator|=(_Ios_Iostate& __a, _Ios_Iostate __b)
+ { return __a = __a | __b; }
+
+ inline _Ios_Iostate
+ operator&=(_Ios_Iostate& __a, _Ios_Iostate __b)
+ { return __a = __a & __b; }
+
+ inline _Ios_Iostate
+ operator^=(_Ios_Iostate& __a, _Ios_Iostate __b)
+ { return __a = __a ^ __b; }
+
+ inline _Ios_Iostate
+ operator~(_Ios_Iostate __a)
+ { return _Ios_Iostate(~static_cast<int>(__a)); }
+
+ enum _Ios_Seekdir { _S_ios_Seekdir_end = 1<<16 };
+
+ // 27.4.2 Class ios_base
+ class ios_base
+ {
+ public:
+
+ // 27.4.2.1.1 Class ios_base::failure
+ class failure : public exception
+ {
+ public:
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ // Can't do exception(_msg) as defined in 27.4.2.1.1
+ explicit
+ failure(const string& __str);
+
+ virtual
+ ~failure() { };
+
+ virtual const
+ char* what() const throw() { return _M_name; }
+
+ private:
+ enum { _M_bufsize = 256 };
+ char _M_name[_M_bufsize];
+#endif
+ };
+
+ // 27.4.2.1.2 Type ios_base::fmtflags
+ typedef _Ios_Fmtflags fmtflags;
+ // 27.4.2.1.2 Type fmtflags
+ static const fmtflags boolalpha = fmtflags(__ios_flags::_S_boolalpha);
+ static const fmtflags dec = fmtflags(__ios_flags::_S_dec);
+ static const fmtflags fixed = fmtflags(__ios_flags::_S_fixed);
+ static const fmtflags hex = fmtflags(__ios_flags::_S_hex);
+ static const fmtflags internal = fmtflags(__ios_flags::_S_internal);
+ static const fmtflags left = fmtflags(__ios_flags::_S_left);
+ static const fmtflags oct = fmtflags(__ios_flags::_S_oct);
+ static const fmtflags right = fmtflags(__ios_flags::_S_right);
+ static const fmtflags scientific = fmtflags(__ios_flags::_S_scientific);
+ static const fmtflags showbase = fmtflags(__ios_flags::_S_showbase);
+ static const fmtflags showpoint = fmtflags(__ios_flags::_S_showpoint);
+ static const fmtflags showpos = fmtflags(__ios_flags::_S_showpos);
+ static const fmtflags skipws = fmtflags(__ios_flags::_S_skipws);
+ static const fmtflags unitbuf = fmtflags(__ios_flags::_S_unitbuf);
+ static const fmtflags uppercase = fmtflags(__ios_flags::_S_uppercase);
+ static const fmtflags adjustfield = fmtflags(__ios_flags::_S_adjustfield);
+ static const fmtflags basefield = fmtflags(__ios_flags::_S_basefield);
+ static const fmtflags floatfield = fmtflags(__ios_flags::_S_floatfield);
+
+ // 27.4.2.1.3 Type ios_base::iostate
+ typedef _Ios_Iostate iostate;
+ static const iostate badbit = iostate(__ios_flags::_S_badbit);
+ static const iostate eofbit = iostate(__ios_flags::_S_eofbit);
+ static const iostate failbit = iostate(__ios_flags::_S_failbit);
+ static const iostate goodbit = iostate(0);
+
+ // 27.4.2.1.4 Type openmode
+ typedef _Ios_Openmode openmode;
+ static const openmode app = openmode(__ios_flags::_S_app);
+ static const openmode ate = openmode(__ios_flags::_S_ate);
+ static const openmode binary = openmode(__ios_flags::_S_bin);
+ static const openmode in = openmode(__ios_flags::_S_in);
+ static const openmode out = openmode(__ios_flags::_S_out);
+ static const openmode trunc = openmode(__ios_flags::_S_trunc);
+
+ // 27.4.2.1.5 Type seekdir
+ typedef _Ios_Seekdir seekdir;
+ static const seekdir beg = seekdir(0);
+ static const seekdir cur = seekdir(SEEK_CUR);
+ static const seekdir end = seekdir(SEEK_END);
+
+#ifdef _GLIBCPP_DEPRICATED
+ typedef int io_state;
+ typedef int open_mode;
+ typedef int seek_dir;
+#endif
+
+ // Callbacks;
+ enum event
+ {
+ erase_event,
+ imbue_event,
+ copyfmt_event
+ };
+
+ typedef void (*event_callback) (event, ios_base&, int);
+
+ void
+ register_callback(event_callback __fn, int __index);
+
+ protected:
+ // Data Members
+ streamsize _M_precision;
+ streamsize _M_width;
+ fmtflags _M_flags;
+
+ // 27.4.2.6 Members for callbacks
+ // 27.4.2.6 ios_base callbacks
+
+ struct _Callback_list
+ {
+ // Data Members
+ _Callback_list* _M_next;
+ ios_base::event_callback _M_fn;
+ int _M_index;
+ int _M_refcount; // 0 means one reference.
+
+ _Callback_list(ios_base::event_callback __fn, int __index,
+ _Callback_list* __cb)
+ : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
+
+ void
+ _M_add_reference() { ++_M_refcount; } // XXX MT
+
+ int
+ _M_remove_reference() { return _M_refcount--; } // 0 => OK to delete
+ };
+
+ _Callback_list* _M_callbacks;
+
+ void
+ _M_call_callbacks(event __ev) throw();
+
+ void
+ _M_dispose_callbacks(void);
+
+ // 27.4.2.5 Members for iword/pword storage
+ struct _Words
+ {
+ void* _M_pword;
+ long _M_iword;
+ };
+
+ static const int _S_local_words = 8;
+ _Words _M_word_array[_S_local_words]; // Guaranteed storage
+ _Words _M_dummy; // Only for failed iword/pword calls.
+ _Words* _M_words;
+ int _M_word_limit;
+
+ _Words&
+ _M_grow_words(int __index);
+
+ // Members for locale and locale caching.
+ locale _M_locale_ios;
+
+ void
+ _M_init();
+
+ public:
+ // 27.4.2.1.6 Class ios_base::Init
+ // Used to initialize standard streams. In theory, g++ could use
+ // -finit-priority to order this stuff correctly without going
+ // through these machinations.
+
+ class Init
+ {
+ friend class ios_base;
+ public:
+ Init();
+ ~Init();
+ private:
+ static int _M_ios_base_init;
+ filebuf* _M_cout;
+ filebuf* _M_cin;
+ filebuf* _M_cerr;
+#ifdef _GLIBCPP_USE_WCHAR_T
+ wfilebuf* _M_wcout;
+ wfilebuf* _M_wcin;
+ wfilebuf* _M_wcerr;
+#endif
+ };
+
+ // Fmtflags state:
+ inline fmtflags
+ flags() const { return _M_flags; }
+
+ inline fmtflags
+ flags(fmtflags __fmtfl)
+ {
+ fmtflags __old = _M_flags;
+ _M_flags = __fmtfl;
+ return __old;
+ }
+
+ inline fmtflags
+ setf(fmtflags __fmtfl)
+ {
+ fmtflags __old = _M_flags;
+ _M_flags |= __fmtfl;
+ return __old;
+ }
+
+ inline fmtflags
+ setf(fmtflags __fmtfl, fmtflags __mask)
+ {
+ fmtflags __old = _M_flags;
+ _M_flags &= ~__mask;
+ _M_flags |= (__fmtfl & __mask);
+ return __old;
+ }
+
+ inline void
+ unsetf(fmtflags __mask) { _M_flags &= ~__mask; }
+
+ inline streamsize
+ precision() const { return _M_precision; }
+
+ inline streamsize
+ precision(streamsize __prec)
+ {
+ streamsize __old = _M_precision;
+ _M_precision = __prec;
+ return __old;
+ }
+
+ inline streamsize
+ width() const { return _M_width; }
+
+ inline streamsize
+ width(streamsize __wide)
+ {
+ streamsize __old = _M_width;
+ _M_width = __wide;
+ return __old;
+ }
+
+ static bool
+ sync_with_stdio(bool __sync = true);
+
+ // Locales:
+ locale
+ imbue(const locale& __loc);
+
+ inline locale
+ getloc() const { return _M_locale_ios; }
+
+ // Storage:
+ static int
+ xalloc() throw();
+
+ inline long&
+ iword(int __ix)
+ {
+ _Words& __word = (__ix < _M_word_limit)
+ ? _M_words[__ix] : _M_grow_words(__ix);
+ return __word._M_iword;
+ }
+
+ inline void*&
+ pword(int __ix)
+ {
+ _Words& __word = (__ix < _M_word_limit)
+ ? _M_words[__ix] : _M_grow_words(__ix);
+ return __word._M_pword;
+ }
+
+ // Destructor
+ ~ios_base();
+
+ protected:
+ ios_base();
+
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ private:
+ ios_base(const ios_base&);
+
+ ios_base&
+ operator=(const ios_base&);
+#endif
+ };
+
+ // 27.4.5.1 fmtflags manipulators:
+ inline ios_base&
+ boolalpha(ios_base& __base)
+ {
+ __base.setf(ios_base::boolalpha);
+ return __base;
+ }
+
+ inline ios_base&
+ noboolalpha(ios_base& __base)
+ {
+ __base.unsetf(ios_base::boolalpha);
+ return __base;
+ }
+
+ inline ios_base&
+ showbase(ios_base& __base)
+ {
+ __base.setf(ios_base::showbase);
+ return __base;
+ }
+
+ inline ios_base&
+ noshowbase(ios_base& __base)
+ {
+ __base.unsetf(ios_base::showbase);
+ return __base;
+ }
+
+ inline ios_base&
+ showpoint(ios_base& __base)
+ {
+ __base.setf(ios_base::showpoint);
+ return __base;
+ }
+
+ inline ios_base&
+ noshowpoint(ios_base& __base)
+ {
+ __base.unsetf(ios_base::showpoint);
+ return __base;
+ }
+
+ inline ios_base&
+ showpos(ios_base& __base)
+ {
+ __base.setf(ios_base::showpos);
+ return __base;
+ }
+
+ inline ios_base&
+ noshowpos(ios_base& __base)
+ {
+ __base.unsetf(ios_base::showpos);
+ return __base;
+ }
+
+ inline ios_base&
+ skipws(ios_base& __base)
+ {
+ __base.setf(ios_base::skipws);
+ return __base;
+ }
+
+ inline ios_base&
+ noskipws(ios_base& __base)
+ {
+ __base.unsetf(ios_base::skipws);
+ return __base;
+ }
+
+ inline ios_base&
+ uppercase(ios_base& __base)
+ {
+ __base.setf(ios_base::uppercase);
+ return __base;
+ }
+
+ inline ios_base&
+ nouppercase(ios_base& __base)
+ {
+ __base.unsetf(ios_base::uppercase);
+ return __base;
+ }
+
+ inline ios_base&
+ unitbuf(ios_base& __base)
+ {
+ __base.setf(ios_base::unitbuf);
+ return __base;
+ }
+
+ inline ios_base&
+ nounitbuf(ios_base& __base)
+ {
+ __base.unsetf(ios_base::unitbuf);
+ return __base;
+ }
+
+ // 27.4.5.2 adjustfield anipulators:
+ inline ios_base&
+ internal(ios_base& __base)
+ {
+ __base.setf(ios_base::internal, ios_base::adjustfield);
+ return __base;
+ }
+
+ inline ios_base&
+ left(ios_base& __base)
+ {
+ __base.setf(ios_base::left, ios_base::adjustfield);
+ return __base;
+ }
+
+ inline ios_base&
+ right(ios_base& __base)
+ {
+ __base.setf(ios_base::right, ios_base::adjustfield);
+ return __base;
+ }
+
+ // 27.4.5.3 basefield anipulators:
+ inline ios_base&
+ dec(ios_base& __base)
+ {
+ __base.setf(ios_base::dec, ios_base::basefield);
+ return __base;
+ }
+
+ inline ios_base&
+ hex(ios_base& __base)
+ {
+ __base.setf(ios_base::hex, ios_base::basefield);
+ return __base;
+ }
+
+ inline ios_base&
+ oct(ios_base& __base)
+ {
+ __base.setf(ios_base::oct, ios_base::basefield);
+ return __base;
+ }
+
+ // 27.4.5.4 floatfield anipulators:
+ inline ios_base&
+ fixed(ios_base& __base)
+ {
+ __base.setf(ios_base::fixed, ios_base::floatfield);
+ return __base;
+ }
+
+ inline ios_base&
+ scientific(ios_base& __base)
+ {
+ __base.setf(ios_base::scientific, ios_base::floatfield);
+ return __base;
+ }
+
+} // namespace std
+
+#endif /* _CPP_BITS_IOSBASE_H */
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/istream.tcc b/libstdc++-v3/bits/istream.tcc
new file mode 100644
index 0000000..71cc961
--- /dev/null
+++ b/libstdc++-v3/bits/istream.tcc
@@ -0,0 +1,1216 @@
+// Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.6.2 Output streams
+//
+
+#include <bits/std_locale.h>
+
+namespace std {
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>::sentry::
+ sentry(basic_istream<_CharT, _Traits>& __in, bool __noskipws)
+ {
+ if (__in.good())
+ {
+ if (__in.tie())
+ __in.tie()->flush();
+ if (!__noskipws && (__in.flags() & ios_base::skipws))
+ {
+ const __int_type __eof = traits_type::eof();
+ __int_type __c = __int_type(0);
+ __streambuf_type* __sb = __in.rdbuf();
+ const __ctype_type* __ctype = __in._M_get_fctype_ios();
+ bool __testsp = true;
+ bool __testeof = false;
+
+ while (!__testeof && __testsp)
+ {
+ __c = __sb->sbumpc();
+ __testeof = __c == __eof;
+ __testsp = __ctype->is(ctype_base::space, __c);
+ }
+
+ if (!__testeof && !__testsp)
+ __sb->sputbackc(__c);
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+//195. Should basic_istream::sentry's constructor ever set eofbit?
+ else
+ __in.setstate(ios_base::eofbit);
+#endif
+ }
+ }
+ _M_ok = __in.good();
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(__istream_type& (*__pf)(__istream_type&))
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ __pf(*this);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(__ios_type& (*__pf)(__ios_type&))
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ __pf(*this);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(ios_base& (*__pf)(ios_base&))
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ __pf(*this);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(bool& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(short& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(unsigned short& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(int& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(unsigned int& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(long& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(unsigned long& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(long long& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(unsigned long long& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+#endif
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(float& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(double& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(long double& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(void*& __n)
+ {
+ sentry __cerb(*this, false);
+ if (__cerb)
+ {
+ try {
+ iostate __err = iostate(ios_base::goodbit);
+ _M_fnumget->get(*this, 0, *this, __err, __n);
+ this->setstate(__err);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ operator>>(__streambuf_type* __sbout)
+ {
+ streamsize __xtrct = 0;
+ __streambuf_type* __sbin = this->rdbuf();
+ sentry __cerb(*this, false);
+ if (__sbout && __cerb)
+ __xtrct = _S_copy_streambufs(*this, __sbin, __sbout);
+ if (!__sbout || !__xtrct)
+ this->setstate(ios_base::failbit);
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>::int_type
+ basic_istream<_CharT, _Traits>::
+ get(void)
+ {
+ const int_type __eof = traits_type::eof();
+ int_type __c = __eof;
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ try {
+ __c = this->rdbuf()->sbumpc();
+ // 27.6.1.1 paragraph 3
+ if (__c != __eof)
+ _M_gcount = 1;
+ else
+ this->setstate(ios_base::eofbit | ios_base::failbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return __c;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ get(char_type& __c)
+ {
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ const int_type __eof = traits_type::eof();
+ int_type __bufval;
+ try {
+ __bufval = this->rdbuf()->sbumpc();
+ // 27.6.1.1 paragraph 3
+ if (__bufval != __eof)
+ {
+ _M_gcount = 1;
+ __c = traits_type::to_char_type(__bufval);
+ }
+ else
+ this->setstate(ios_base::eofbit | ios_base::failbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ get(char_type* __s, streamsize __n, char_type __delim)
+ {
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb && __n > 1)
+ {
+ try {
+ int_type __idelim = traits_type::to_int_type(__delim);
+ __streambuf_type* __sb = this->rdbuf();
+ int_type __c = __sb->sbumpc();
+ const int_type __eof = traits_type::eof();
+ bool __testdelim = __c == __idelim;
+ bool __testeof = __c == __eof;
+
+ while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
+ {
+ *__s++ = traits_type::to_char_type(__c);
+ ++_M_gcount;
+ __c = __sb->sbumpc();
+ __testeof = __c == __eof;
+ __testdelim = __c == __idelim;
+ }
+ if (__testdelim || _M_gcount == __n - 1)
+ __sb->sputbackc(__c);
+ if (__testeof)
+ this->setstate(ios_base::eofbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ *__s = char_type(NULL);
+ if (!_M_gcount)
+ this->setstate(ios_base::failbit);
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ get(__streambuf_type& __sb, char_type __delim)
+ {
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ __streambuf_type* __this_sb = this->rdbuf();
+ int_type __c;
+ try {
+ int_type __idelim = traits_type::to_int_type(__delim);
+ __c = __this_sb->sbumpc();
+ const int_type __eof = traits_type::eof();
+ bool __testdelim = __c == __idelim;
+ bool __testeof = __c == __eof;
+ bool __testput = true;
+ streamsize __n = __this_sb->in_avail();
+
+ while (_M_gcount <= __n
+ && !__testeof
+ && !__testdelim
+ && (__testput = __sb.sputc(traits_type::to_char_type(__c))
+ != __eof))
+ {
+ ++_M_gcount;
+ __c = __this_sb->sbumpc();
+ __testeof = __c == __eof;
+ __testdelim = __c == __idelim;
+ }
+ if (__testdelim || !__testput)
+ __this_sb->sputbackc(traits_type::to_char_type(__c));
+ if (__testeof)
+ this->setstate(ios_base::eofbit);
+ }
+ catch(exception& __fail){
+ // Exception may result from sputc->overflow.
+ __this_sb->sputbackc(traits_type::to_char_type(__c));
+ }
+ }
+ if (!_M_gcount)
+ this->setstate(ios_base::failbit);
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ getline(char_type* __s, streamsize __n, char_type __delim)
+ {
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ try {
+ int_type __idelim = traits_type::to_int_type(__delim);
+ __streambuf_type* __sb = this->rdbuf();
+ int_type __c = __sb->sbumpc();
+ const int_type __eof = traits_type::eof();
+ bool __testdelim = __c == __idelim;
+ bool __testeof = __c == __eof;
+
+ while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
+ {
+ *__s++ = traits_type::to_char_type(__c);
+ ++_M_gcount;
+ __c = __sb->sbumpc();
+ __testeof = __c == __eof;
+ __testdelim = __c == __idelim;
+ }
+ if (_M_gcount == __n - 1 && !__testeof && !__testdelim)
+ {
+ __sb->sputbackc(traits_type::to_char_type(__c));
+ this->setstate(ios_base::failbit);
+ }
+ if (__testdelim)
+ ++_M_gcount;
+ if (__testeof)
+ this->setstate(ios_base::eofbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ *__s = char_type(NULL);
+ if (!_M_gcount || _M_gcount == __n - 1)
+ this->setstate(ios_base::failbit);
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ ignore(streamsize __n, int_type __delim)
+ {
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb && __n > 0)
+ {
+ try {
+ int_type __idelim = traits_type::to_int_type(__delim);
+ __streambuf_type* __sb = this->rdbuf();
+ int_type __c = __sb->sbumpc();
+ const int_type __eof = traits_type::eof();
+ bool __testdelim = __c == __idelim;
+ bool __testeof = __c == __eof;
+
+ __n = min(__n, numeric_limits<streamsize>::max());
+ while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
+ {
+ ++_M_gcount;
+ __c = __sb->sbumpc();
+ __testeof = __c == __eof;
+ __testdelim = __c == __idelim;
+ }
+ if ((_M_gcount == __n - 1 && !__testeof) || __testdelim)
+ ++_M_gcount;
+ if (__testeof)
+ this->setstate(ios_base::eofbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>::int_type
+ basic_istream<_CharT, _Traits>::
+ peek(void)
+ {
+ int_type __c = traits_type::eof();
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ try {
+ __c = this->rdbuf()->sgetc();
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return __c;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ read(char_type* __s, streamsize __n)
+ {
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ if (__n > 0)
+ {
+ try {
+ __streambuf_type* __sb = this->rdbuf();
+ int_type __c = __sb->sbumpc();
+ const int_type __eof = traits_type::eof();
+ bool __testeof = __c == __eof;
+
+ while (_M_gcount < __n - 1 && !__testeof)
+ {
+ *__s++ = traits_type::to_char_type(__c);
+ ++_M_gcount;
+ __c = __sb->sbumpc();
+ __testeof = __c == __eof;
+ }
+ if (__testeof)
+ this->setstate(ios_base::eofbit | ios_base::failbit);
+ else
+ {
+ // _M_gcount == __n - 1
+ *__s++ = traits_type::to_char_type(__c);
+ ++_M_gcount;
+ }
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ }
+ else
+ this->setstate(ios_base::failbit);
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ streamsize
+ basic_istream<_CharT, _Traits>::
+ readsome(char_type* __s, streamsize __n)
+ {
+ const int_type __eof = traits_type::eof();
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ if (__n > 0)
+ {
+ try {
+ streamsize __num = this->rdbuf()->in_avail();
+ if (__num != static_cast<streamsize>(__eof))
+ {
+ __num = min(__num, __n);
+ _M_gcount = this->rdbuf()->sgetn(__s, __num);
+ }
+ else
+ this->setstate(ios_base::eofbit);
+ }
+
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ }
+ else
+ this->setstate(ios_base::failbit);
+ return _M_gcount;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ putback(char_type __c)
+ {
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ try {
+ const int_type __eof = traits_type::eof();
+ __streambuf_type* __sb = this->rdbuf();
+ if (!__sb || __sb->sputbackc(__c) == __eof)
+ this->setstate(ios_base::badbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ else
+ this->setstate(ios_base::failbit);
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ unget(void)
+ {
+ const int_type __eof = traits_type::eof();
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ try {
+ __streambuf_type* __sb = this->rdbuf();
+ if (!__sb || __eof == __sb->sungetc())
+ this->setstate(ios_base::badbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ else
+ this->setstate(ios_base::failbit);
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ int
+ basic_istream<_CharT, _Traits>::
+ sync(void)
+ {
+ int __retval = traits_type::eof();
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ try {
+ __streambuf_type* __sb = this->rdbuf();
+ if (!__sb || __retval == __sb->pubsync())
+ this->setstate(ios_base::badbit);
+ else
+ __retval = 0;
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ typename basic_istream<_CharT, _Traits>::pos_type
+ basic_istream<_CharT, _Traits>::
+ tellg(void)
+ {
+ pos_type __retval = pos_type(-1);
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ try {
+ __retval = this->rdbuf()->pubseekoff(0, ios_base::cur,
+ ios_base::in);
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return __retval;
+ }
+
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ seekg(pos_type __pos)
+ {
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ try {
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+// 136. seekp, seekg setting wrong streams?
+ this->rdbuf()->pubseekpos(__pos, ios_base::in);
+#endif
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ basic_istream<_CharT, _Traits>::
+ seekg(off_type __off, ios_base::seekdir __dir)
+ {
+ _M_gcount = 0;
+ sentry __cerb(*this, true);
+ if (__cerb)
+ {
+ try {
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+// 136. seekp, seekg setting wrong streams?
+ this->rdbuf()->pubseekoff(__off, __dir, ios_base::in);
+#endif
+ }
+ catch(exception& __fail){
+ // 27.6.1.3 paragraph 1
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ // 27.6.1.2.3 Character extraction templates
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
+ {
+ typedef basic_istream<_CharT, _Traits> __istream_type;
+ __istream_type::sentry __cerb(__in, false);
+ if (__cerb)
+ {
+ try {
+ __in.get(__c);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ __in.setstate(ios_base::badbit);
+ if ((__in.exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ else
+ __in.setstate(ios_base::failbit);
+ return __in;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
+ {
+ typedef basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::__streambuf_type __streambuf_type;
+ typedef typename _Traits::int_type int_type;
+ typedef _CharT char_type;
+ typedef ctype<_CharT> __ctype_type;
+ int_type __extracted = 0;
+
+ __istream_type::sentry __cerb(__in, false);
+ if (__cerb)
+ {
+ try {
+ // Figure out how many characters to extract.
+ int_type __num = static_cast<int_type>(__in.width());
+ if (__num <= 0)
+ __num = basic_string<_CharT, _Traits>::npos;
+
+ __streambuf_type* __sb = __in.rdbuf();
+ const __ctype_type* __ctype = __in._M_get_fctype_ios();
+ int_type __c = __sb->sbumpc();
+ const int_type __eof = _Traits::eof();
+ bool __testsp = __ctype->is(ctype_base::space, __c);
+ bool __testeof = __c == __eof;
+
+ while (__extracted < __num - 1 && !__testeof && !__testsp)
+ {
+ *__s++ = __c;
+ ++__extracted;
+ __c = __sb->sbumpc();
+ __testeof = __c == __eof;
+ __testsp = __ctype->is(ctype_base::space, __c);
+ }
+
+ if (!__testeof)
+ __sb->sputbackc(__c);
+ else
+ __in.setstate(ios_base::eofbit);
+
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+//68. Extractors for char* should store null at end
+ *__s = char_type();
+#endif
+ __in.width(0);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ __in.setstate(ios_base::badbit);
+ if ((__in.exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ if (!__extracted)
+ __in.setstate(ios_base::failbit);
+ return __in;
+ }
+
+ // 27.6.1.4 Standard basic_istream manipulators
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT,_Traits>&
+ ws(basic_istream<_CharT,_Traits>& __in)
+ {
+ typedef basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::__streambuf_type __streambuf_type;
+ typedef typename __istream_type::__ctype_type __ctype_type;
+ typedef typename __istream_type::int_type __int_type;
+ typedef typename __istream_type::char_type __char_type;
+
+ __streambuf_type* __sb = __in.rdbuf();
+ const __ctype_type* __ctype = __in._M_get_fctype_ios();
+ const __int_type __eof = _Traits::eof();
+ __int_type __c;
+ bool __testeof;
+ bool __testsp;
+
+ do
+ {
+ __c = __sb->sbumpc();
+ __testeof = __c == __eof;
+ __testsp = __ctype->is(ctype_base::space, __c);
+ }
+ while (!__testeof && __testsp);
+
+ if (!__testeof && !__testsp)
+ __sb->sputbackc(__c);
+ else
+ __in.setstate(ios_base::eofbit);
+
+ return __in;
+ }
+
+ // 21.3.7.8 basic_string::getline and operators
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_istream<_CharT, _Traits>&
+ operator>>(basic_istream<_CharT, _Traits>& __in,
+ basic_string<_CharT, _Traits, _Alloc>& __str)
+ {
+ typedef basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::int_type __int_type;
+ typedef typename __istream_type::__streambuf_type __streambuf_type;
+ typedef typename __istream_type::__ctype_type __ctype_type;
+ typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
+ typedef typename __string_type::size_type __size_type;
+ __int_type __extracted = 0;
+
+ __istream_type::sentry __cerb(__in, false);
+ if (__cerb)
+ {
+ __str.erase();
+ streamsize __w = __in.width();
+ __size_type __n;
+ __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
+
+ __streambuf_type* __sb = __in.rdbuf();
+ const __ctype_type* __ctype = __in._M_get_fctype_ios();
+ __int_type __c = __sb->sbumpc();
+ const __int_type __eof = _Traits::eof();
+ bool __testsp = __ctype->is(ctype_base::space, __c);
+ bool __testeof = __c == __eof;
+
+ while (__extracted <= __n && !__testeof && !__testsp)
+ {
+ __str += _Traits::to_char_type(__c);
+ ++__extracted;
+ __c = __sb->sbumpc();
+ __testeof = __c == __eof;
+ __testsp = __ctype->is(ctype_base::space, __c);
+ }
+ if (!__testeof)
+ __sb->sputbackc(__c);
+ else
+ __in.setstate(ios_base::eofbit);
+ __in.width(0);
+ }
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+// 2000-02-01 Number to be determined
+ if (!__extracted)
+ __in.setstate (ios_base::failbit);
+#endif
+ return __in;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_istream<_CharT, _Traits>&
+ getline(basic_istream<_CharT, _Traits>& __in,
+ basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
+ {
+ typedef basic_istream<_CharT, _Traits> __istream_type;
+ typedef typename __istream_type::int_type __int_type;
+ typedef typename __istream_type::__streambuf_type __streambuf_type;
+ typedef typename __istream_type::__ctype_type __ctype_type;
+ typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
+ typedef typename __string_type::size_type __size_type;
+
+ __size_type __extracted = 0;
+ bool __testdelim = false;
+ __istream_type::sentry __cerb(__in, true);
+ if (__cerb)
+ {
+ __str.erase();
+ __size_type __n = __str.max_size();
+
+ __int_type __idelim = _Traits::to_int_type(__delim);
+ __streambuf_type* __sb = __in.rdbuf();
+ __int_type __c = __sb->sbumpc();
+ const __int_type __eof = _Traits::eof();
+ __testdelim = __c == __idelim;
+ bool __testeof = __c == __eof;
+
+ while (__extracted <= __n && !__testeof && !__testdelim)
+ {
+ __str += _Traits::to_char_type(__c);
+ ++__extracted;
+ __c = __sb->sbumpc();
+ __testeof = __c == __eof;
+ __testdelim = __c == __idelim;
+ }
+ if (__testeof)
+ __in.setstate(ios_base::eofbit);
+ }
+ if (!__extracted && !__testdelim)
+ __in.setstate(ios_base::failbit);
+ return __in;
+ }
+
+ template<class _CharT, class _Traits, class _Alloc>
+ inline basic_istream<_CharT,_Traits>&
+ getline(basic_istream<_CharT, _Traits>& __in,
+ basic_string<_CharT,_Traits,_Alloc>& __str)
+ { return getline(__in, __str, __in.widen('\n')); }
+
+} // namespace std
+
+// Local Variables:
+// mode:C++
+// End:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/limits_generic.h b/libstdc++-v3/bits/limits_generic.h
new file mode 100644
index 0000000..4538e21
--- /dev/null
+++ b/libstdc++-v3/bits/limits_generic.h
@@ -0,0 +1,786 @@
+// The template and inlines for the -*- C++ -*- numeric_limits classes.
+
+// Copyright (C) 2000 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+// Note: this is not a conforming implementation.
+// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@cmla.ens-cachan.fr>
+
+//
+// ISO 14882:1998
+// 18.2.1
+//
+
+#ifndef _CPP_NUMERIC_LIMITS
+#define _CPP_NUMERIC_LIMITS 1
+
+#include <bits/c++config.h>
+#include <bits/std_cfloat.h>
+#include <bits/std_climits.h>
+#if defined( _GLIBCPP_USE_WCHAR_T) && defined(_GLIBCPP_HAS_WCHAR_MIN_MAX)
+#include <bits/std_cwchar.h>
+#endif
+
+namespace std {
+
+ enum float_round_style {
+ round_indeterminate = -1,
+ round_toward_zero = 0,
+ round_to_nearest = 1,
+ round_toward_infinity = 2,
+ round_toward_neg_infinity = 3
+ };
+
+ enum float_denorm_style {
+ denorm_indeterminate = -1,
+ denorm_absent = 0,
+ denorm_present = 1
+ };
+
+ template<typename _T> struct numeric_limits {
+ static const bool is_specialized = false;
+
+ static _T min() throw() { return static_cast<_T>(0); }
+ static _T max() throw() { return static_cast<_T>(0); }
+
+ static const int digits = 0;
+ static const int digits10 = 0;
+ static const bool is_signed = false;
+ static const bool is_integer = false;
+ static const bool is_exact = false;
+ static const int radix = 0;
+
+ static _T epsilon() throw() { return static_cast<_T>(0); }
+ static _T round_error() throw() { return static_cast<_T>(0); }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static _T infinity() throw() { return static_cast<_T>(0); }
+ static _T quiet_NaN() throw() { return static_cast<_T>(0); }
+ static _T signaling_NaN() throw() { return static_cast<_T>(0); }
+ static _T denorm_min() throw() { return static_cast<_T>(0); }
+
+ static const bool is_iec559 = false;
+ static const bool is_bounded = false;
+ static const bool is_modulo = false;
+
+ static const bool traps = false;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<typename _T> _T __limits_infinity();
+ template<typename _T> _T __limits_quiet_NaN();
+ template<typename _T> _T __limits_signaling_NaN();
+ template<typename _T> _T __limits_denorm_min();
+
+ template<> struct numeric_limits<bool> {
+ static const bool is_specialized = true;
+
+ static bool min() throw()
+ { return false; }
+ static bool max() throw()
+ { return true; }
+
+ static const int digits = 8;
+ static const int digits10 = 2;
+ static const bool is_signed = false;
+ static const bool is_integer = true;
+ static const bool is_exact = true;
+ static const int radix = 2;
+ static bool epsilon() throw()
+ { return 0; }
+ static bool round_error() throw()
+ { return 0; }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static bool infinity() throw()
+ { return static_cast<bool>(0); }
+ static bool quiet_NaN() throw()
+ { return static_cast<bool>(0); }
+ static bool signaling_NaN() throw()
+ { return static_cast<bool>(0); }
+ static bool denorm_min() throw()
+ { return static_cast<bool>(0); }
+
+ static const bool is_iec559 = true;
+ static const bool is_bounded = true;
+ static const bool is_modulo = true;
+
+ static const bool traps = false;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<> struct numeric_limits<char> {
+ static const bool is_specialized = true;
+
+ static char min() throw()
+ { return CHAR_MIN; }
+ static char max() throw()
+ { return CHAR_MAX; }
+
+ static const int digits = 7;
+ static const int digits10 = 2;
+ static const bool is_signed = true;
+ static const bool is_integer = true;
+ static const bool is_exact = true;
+ static const int radix = 2;
+ static char epsilon() throw()
+ { return 0; }
+ static char round_error() throw()
+ { return 0; }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static char infinity() throw()
+ { return static_cast<char>(0); }
+ static char quiet_NaN() throw()
+ { return static_cast<char>(0); }
+ static char signaling_NaN() throw()
+ { return static_cast<char>(0); }
+ static char denorm_min() throw()
+ { return static_cast<char>(0); }
+
+ static const bool is_iec559 = false;
+ static const bool is_bounded = true;
+ static const bool is_modulo = false;
+
+ static const bool traps = false;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<> struct numeric_limits<signed char> {
+ static const bool is_specialized = true;
+
+ static signed char min() throw()
+ { return SCHAR_MIN; }
+ static signed char max() throw()
+ { return SCHAR_MAX; }
+
+ static const int digits = 7;
+ static const int digits10 = 2;
+ static const bool is_signed = true;
+ static const bool is_integer = true;
+ static const bool is_exact = true;
+ static const int radix = 2;
+ static signed char epsilon() throw()
+ { return 0; }
+ static signed char round_error() throw()
+ { return 0; }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static signed char infinity() throw()
+ { return static_cast<signed char>(0); }
+ static signed char quiet_NaN() throw()
+ { return static_cast<signed char>(0); }
+ static signed char signaling_NaN() throw()
+ { return static_cast<signed char>(0); }
+ static signed char denorm_min() throw()
+ { return static_cast<signed char>(0); }
+
+ static const bool is_iec559 = false;
+ static const bool is_bounded = true;
+ static const bool is_modulo = false;
+
+ static const bool traps = false;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<> struct numeric_limits<unsigned char> {
+ static const bool is_specialized = true;
+
+ static unsigned char min() throw()
+ { return 0; }
+ static unsigned char max() throw()
+ { return UCHAR_MAX; }
+
+ static const int digits = 8;
+ static const int digits10 = 2;
+ static const bool is_signed = false;
+ static const bool is_integer = true;
+ static const bool is_exact = true;
+ static const int radix = 2;
+ static unsigned char epsilon() throw()
+ { return 0; }
+ static unsigned char round_error() throw()
+ { return 0; }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static unsigned char infinity() throw()
+ { return static_cast<unsigned char>(0); }
+ static unsigned char quiet_NaN() throw()
+ { return static_cast<unsigned char>(0); }
+ static unsigned char signaling_NaN() throw()
+ { return static_cast<unsigned char>(0); }
+ static unsigned char denorm_min() throw()
+ { return static_cast<unsigned char>(0); }
+
+ static const bool is_iec559 = false;
+ static const bool is_bounded = true;
+ static const bool is_modulo = true;
+
+ static const bool traps = true;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+#if defined( _GLIBCPP_USE_WCHAR_T) && defined(_GLIBCPP_HAS_WCHAR_MIN_MAX)
+ template<> struct numeric_limits<wchar_t> {
+ static const bool is_specialized = true;
+
+ static wchar_t min() throw()
+ { return WCHART_MIN; }
+ static wchar_t max() throw()
+ { return WCHART_MAX; }
+
+ static const int digits = 31;
+ static const int digits10 = 9;
+ static const bool is_signed = true;
+ static const bool is_integer = true;
+ static const bool is_exact = true;
+ static const int radix = 2;
+ static wchar_t epsilon() throw()
+ { return 0; }
+ static wchar_t round_error() throw()
+ { return 0; }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static wchar_t infinity() throw()
+ { return static_cast<wchar_t>(0); }
+ static wchar_t quiet_NaN() throw()
+ { return static_cast<wchar_t>(0); }
+ static wchar_t signaling_NaN() throw()
+ { return static_cast<wchar_t>(0); }
+ static wchar_t denorm_min() throw()
+ { return static_cast<wchar_t>(0); }
+
+ static const bool is_iec559 = false;
+ static const bool is_bounded = true;
+ static const bool is_modulo = false;
+
+ static const bool traps = false;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+#endif
+
+ template<> struct numeric_limits<short> {
+ static const bool is_specialized = true;
+
+ static short min() throw()
+ { return SHRT_MIN; }
+ static short max() throw()
+ { return SHRT_MAX; }
+
+ static const int digits = 15;
+ static const int digits10 = 4;
+ static const bool is_signed = true;
+ static const bool is_integer = true;
+ static const bool is_exact = true;
+ static const int radix = 2;
+ static short epsilon() throw()
+ { return 0; }
+ static short round_error() throw()
+ { return 0; }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static short infinity() throw()
+ { return static_cast<short>(0); }
+ static short quiet_NaN() throw()
+ { return static_cast<short>(0); }
+ static short signaling_NaN() throw()
+ { return static_cast<short>(0); }
+ static short denorm_min() throw()
+ { return static_cast<short>(0); }
+
+ static const bool is_iec559 = false;
+ static const bool is_bounded = true;
+ static const bool is_modulo = false;
+
+ static const bool traps = false;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<> struct numeric_limits<unsigned short> {
+ static const bool is_specialized = true;
+
+ static unsigned short min() throw()
+ { return 0; }
+ static unsigned short max() throw()
+ { return USHRT_MAX; }
+
+ static const int digits = 16;
+ static const int digits10 = 4;
+ static const bool is_signed = false;
+ static const bool is_integer = true;
+ static const bool is_exact = true;
+ static const int radix = 2;
+ static unsigned short epsilon() throw()
+ { return 0; }
+ static unsigned short round_error() throw()
+ { return 0; }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static unsigned short infinity() throw()
+ { return static_cast<unsigned short>(0); }
+ static unsigned short quiet_NaN() throw()
+ { return static_cast<unsigned short>(0); }
+ static unsigned short signaling_NaN() throw()
+ { return static_cast<unsigned short>(0); }
+ static unsigned short denorm_min() throw()
+ { return static_cast<unsigned short>(0); }
+
+ static const bool is_iec559 = false;
+ static const bool is_bounded = true;
+ static const bool is_modulo = true;
+
+ static const bool traps = true;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<> struct numeric_limits<int> {
+ static const bool is_specialized = true;
+
+ static int min() throw()
+ { return INT_MIN; }
+ static int max() throw()
+ { return INT_MAX; }
+
+ static const int digits = 31;
+ static const int digits10 = 9;
+ static const bool is_signed = true;
+ static const bool is_integer = true;
+ static const bool is_exact = true;
+ static const int radix = 2;
+ static int epsilon() throw()
+ { return 0; }
+ static int round_error() throw()
+ { return 0; }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static int infinity() throw()
+ { return static_cast<int>(0); }
+ static int quiet_NaN() throw()
+ { return static_cast<int>(0); }
+ static int signaling_NaN() throw()
+ { return static_cast<int>(0); }
+ static int denorm_min() throw()
+ { return static_cast<int>(0); }
+
+ static const bool is_iec559 = true;
+ static const bool is_bounded = true;
+ static const bool is_modulo = false;
+
+ static const bool traps = false;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<> struct numeric_limits<unsigned int> {
+ static const bool is_specialized = true;
+
+ static unsigned int min() throw()
+ { return 0; }
+ static unsigned int max() throw()
+ { return UINT_MAX; }
+
+ static const int digits = 32;
+ static const int digits10 = 9;
+ static const bool is_signed = false;
+ static const bool is_integer = true;
+ static const bool is_exact = true;
+ static const int radix = 2;
+ static unsigned int epsilon() throw()
+ { return 0; }
+ static unsigned int round_error() throw()
+ { return 0; }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static unsigned int infinity() throw()
+ { return static_cast<unsigned int>(0); }
+ static unsigned int quiet_NaN() throw()
+ { return static_cast<unsigned int>(0); }
+ static unsigned int signaling_NaN() throw()
+ { return static_cast<unsigned int>(0); }
+ static unsigned int denorm_min() throw()
+ { return static_cast<unsigned int>(0); }
+
+ static const bool is_iec559 = true;
+ static const bool is_bounded = true;
+ static const bool is_modulo = true;
+
+ static const bool traps = true;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<> struct numeric_limits<long> {
+ static const bool is_specialized = true;
+
+ static long min() throw()
+ { return LONG_MIN; }
+ static long max() throw()
+ { return LONG_MAX; }
+
+ static const int digits = 31;
+ static const int digits10 = 9;
+ static const bool is_signed = true;
+ static const bool is_integer = true;
+ static const bool is_exact = true;
+ static const int radix = 2;
+ static long epsilon() throw()
+ { return 0; }
+ static long round_error() throw()
+ { return 0; }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static long infinity() throw()
+ { return static_cast<long>(0); }
+ static long quiet_NaN() throw()
+ { return static_cast<long>(0); }
+ static long signaling_NaN() throw()
+ { return static_cast<long>(0); }
+ static long denorm_min() throw()
+ { return static_cast<long>(0); }
+
+ static const bool is_iec559 = true;
+ static const bool is_bounded = true;
+ static const bool is_modulo = false;
+
+ static const bool traps = false;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<> struct numeric_limits<unsigned long> {
+ static const bool is_specialized = true;
+
+ static unsigned long min() throw()
+ { return 0; }
+ static unsigned long max() throw()
+ { return ULONG_MAX; }
+
+ static const int digits = 32;
+ static const int digits10 = 9;
+ static const bool is_signed = false;
+ static const bool is_integer = true;
+ static const bool is_exact = true;
+ static const int radix = 2;
+ static unsigned long epsilon() throw()
+ { return 0; }
+ static unsigned long round_error() throw()
+ { return 0; }
+
+ static const int min_exponent = 0;
+ static const int min_exponent10 = 0;
+ static const int max_exponent = 0;
+ static const int max_exponent10 = 0;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static unsigned long infinity() throw()
+ { return static_cast<unsigned long>(0); }
+ static unsigned long quiet_NaN() throw()
+ { return static_cast<unsigned long>(0); }
+ static unsigned long signaling_NaN() throw()
+ { return static_cast<unsigned long>(0); }
+ static unsigned long denorm_min() throw()
+ { return static_cast<unsigned long>(0); }
+
+ static const bool is_iec559 = true;
+ static const bool is_bounded = true;
+ static const bool is_modulo = true;
+
+ static const bool traps = true;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<> struct numeric_limits<float> {
+ static const bool is_specialized = true;
+
+ static float min() throw()
+ { return FLT_MIN; }
+ static float max() throw()
+ { return FLT_MAX; }
+
+ static const int digits = FLT_MANT_DIG;
+ static const int digits10 = FLT_DIG;
+ static const bool is_signed = true;
+ static const bool is_integer = false;
+ static const bool is_exact = false;
+ static const int radix = FLT_RADIX;
+ static float epsilon() throw()
+ { return FLT_EPSILON; }
+ static float round_error() throw()
+ { return FLT_ROUNDS; }
+
+ static const int min_exponent = FLT_MIN_EXP;
+ static const int min_exponent10 = FLT_MIN_10_EXP;
+ static const int max_exponent = FLT_MAX_EXP;
+ static const int max_exponent10 = FLT_MAX_10_EXP;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static float infinity() throw()
+ { return static_cast<float>(0); }
+ static float quiet_NaN() throw()
+ { return static_cast<float>(0); }
+ static float signaling_NaN() throw()
+ { return static_cast<float>(0); }
+ static float denorm_min() throw()
+ { return static_cast<float>(0); }
+
+ static const bool is_iec559 = false;
+ static const bool is_bounded = true;
+ static const bool is_modulo = false;
+
+ static const bool traps = false;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<> struct numeric_limits<double> {
+ static const bool is_specialized = true;
+
+ static double min() throw()
+ { return DBL_MIN; }
+ static double max() throw()
+ { return DBL_MAX; }
+
+ static const int digits = DBL_MANT_DIG;
+ static const int digits10 = DBL_DIG;
+ static const bool is_signed = true;
+ static const bool is_integer = false;
+ static const bool is_exact = false;
+ static const int radix = 2;
+ static double epsilon() throw()
+ { return DBL_EPSILON; }
+ static double round_error() throw()
+ { return 1.0; }
+
+ static const int min_exponent = DBL_MIN_EXP;
+ static const int min_exponent10 = DBL_MIN_10_EXP;
+ static const int max_exponent = DBL_MAX_EXP;
+ static const int max_exponent10 = DBL_MAX_10_EXP;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static double infinity() throw()
+ { return static_cast<double>(0); }
+ static double quiet_NaN() throw()
+ { return static_cast<double>(0); }
+ static double signaling_NaN() throw()
+ { return static_cast<double>(0); }
+ static double denorm_min() throw()
+ { return static_cast<double>(0); }
+
+ static const bool is_iec559 = false;
+ static const bool is_bounded = true;
+ static const bool is_modulo = false;
+
+ static const bool traps = false;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+ template<> struct numeric_limits<long double> {
+ static const bool is_specialized = true;
+
+ static double min() throw()
+ { return LDBL_MIN; }
+ static double max() throw()
+ { return LDBL_MAX; }
+
+ static const int digits = LDBL_MANT_DIG;
+ static const int digits10 = LDBL_DIG;
+ static const bool is_signed = true;
+ static const bool is_integer = false;
+ static const bool is_exact = false;
+ static const int radix = 2;
+ static double epsilon() throw()
+ { return LDBL_EPSILON; }
+ static double round_error() throw()
+ { return 1.0L; }
+
+ static const int min_exponent = LDBL_MIN_EXP;
+ static const int min_exponent10 = LDBL_MIN_10_EXP;
+ static const int max_exponent = LDBL_MAX_EXP;
+ static const int max_exponent10 = LDBL_MAX_10_EXP;
+
+ static const bool has_infinity = false;
+ static const bool has_quiet_NaN = false;
+ static const bool has_signaling_NaN = false;
+ static const float_denorm_style has_denorm = denorm_absent;
+ static const bool has_denorm_loss = false;
+
+ static double infinity() throw()
+ { return static_cast<double>(0); }
+ static double quiet_NaN() throw()
+ { return static_cast<double>(0); }
+ static double signaling_NaN() throw()
+ { return static_cast<double>(0); }
+ static double denorm_min() throw()
+ { return static_cast<double>(0); }
+
+ static const bool is_iec559 = false;
+ static const bool is_bounded = true;
+ static const bool is_modulo = false;
+
+ static const bool traps = false;
+ static const bool tinyness_before = false;
+ static const float_round_style round_style = round_toward_zero;
+ };
+
+} // namespace std
+
+#endif // _CPP_NUMERIC_LIMITS
diff --git a/libstdc++-v3/bits/locale_facets.h b/libstdc++-v3/bits/locale_facets.h
new file mode 100644
index 0000000..ec40d0f
--- /dev/null
+++ b/libstdc++-v3/bits/locale_facets.h
@@ -0,0 +1,1935 @@
+// Locale support -*- C++ -*-
+
+// Copyright (C) 1997-2000 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 22.1 Locales
+//
+
+// Warning: this file is not meant for user inclusion. Use <locale>.
+
+#ifndef _CPP_BITS_LOCFACETS_H
+#define _CPP_BITS_LOCFACETS_H 1
+
+#include <bits/std_ctime.h> // For struct tm
+#include <bits/std_typeinfo.h> // For bad_cast, which shouldn't be here.
+#include <bits/std_ios.h> // For ios_base
+
+namespace std
+{
+
+ // XXX This function is to be specialized for the "required" facets to
+ // be constructed lazily. The specializations must be declared after
+ // the definitions of the facets themselves; but they shouldn't be
+ // inline. Corresponding new's in locale::classic() should then be
+ // eliminated. Note that ctype<> should not get this treatment;
+ // see the use_facet<> specializations below.
+ //
+ struct _Bad_use_facet : public bad_cast
+ {
+ _Bad_use_facet() throw() {}
+
+ _Bad_use_facet(_Bad_use_facet const& __b) throw()
+ : bad_cast(__b) { }
+
+ _Bad_use_facet&
+ operator=(_Bad_use_facet const& __b) throw()
+ {
+ static_cast<bad_cast*>(this)->operator=(__b);
+ return *this;
+ }
+
+ virtual char const*
+ what() const throw();
+
+ virtual
+ ~_Bad_use_facet() throw();
+ };
+
+ template<typename _Facet>
+ const _Facet&
+ _Use_facet_failure_handler(const locale&)
+ { throw _Bad_use_facet(); }
+
+ // 22.2.1 The ctype category
+ // Include host-specific ctype enums for ctype_base.
+ #include <bits/ctype_base.h>
+
+ // 22.2.1.1 Template class ctype
+ // _Ctype_nois is the common base for ctype<char>. It lacks "do_is"
+ // and related virtuals. These are filled in by _Ctype, below.
+ template<typename _CharT>
+ class _Ctype_nois : public locale::facet, public ctype_base
+ {
+ // Types:
+ typedef _CharT char_type;
+
+ public:
+ char_type
+ toupper(char_type __c) const
+ { return this->do_toupper(__c); }
+
+ const char_type*
+ toupper(char_type *__low, const char_type* __high) const
+ { return this->do_toupper(__low, __high); }
+
+ char_type
+ tolower(char_type __c) const
+ { return this->do_tolower(__c); }
+
+ const char_type*
+ tolower(char_type* __low, const char_type* __high) const
+ { return this->do_tolower(__low, __high); }
+
+ char_type
+ widen(char __c) const
+ { return this->do_widen(__c); }
+
+ const char*
+ widen(const char* __low, const char* __high, char_type* __to) const
+ { return this->do_widen(__low, __high, __to); }
+
+ char
+ narrow(char_type __c, char __dfault) const
+ { return this->do_narrow(__c, __dfault); }
+
+ const char_type*
+ narrow(const char_type* __low, const char_type* __high,
+ char __dfault, char *__to) const
+ { return this->do_narrow(__low, __high, __dfault, __to); }
+
+ protected:
+ explicit
+ _Ctype_nois(size_t __refs = 0): locale::facet(__refs) { }
+
+ virtual
+ ~_Ctype_nois() { }
+
+ virtual char_type
+ do_toupper(char_type) const = 0;
+
+ virtual const char_type*
+ do_toupper(char_type* __low, const char_type* __high) const = 0;
+
+ virtual char_type
+ do_tolower(char_type) const = 0;
+
+ virtual const char_type*
+ do_tolower(char_type* __low, const char_type* __high) const = 0;
+
+ virtual char_type
+ do_widen(char) const = 0;
+
+ virtual const char*
+ do_widen(const char* __low, const char* __high,
+ char_type* __dest) const = 0;
+
+ virtual char
+ do_narrow(char_type, char __dfault) const = 0;
+
+ virtual const char_type*
+ do_narrow(const char_type* __low, const char_type* __high,
+ char __dfault, char* __dest) const = 0;
+ };
+
+
+ template<typename _CharT>
+ class _Ctype : public _Ctype_nois<_CharT>
+ {
+ public:
+
+ // Types:
+ typedef _CharT char_type;
+ typedef typename _Ctype_nois<_CharT>::mask mask;
+
+ bool
+ is(mask __m, char_type __c) const
+ { return this->do_is(__m, __c); }
+
+ const char_type*
+ is(const char_type *__lo, const char_type *__hi, mask *__vec) const
+ { return this->do_is(__lo, __hi, __vec); }
+
+ const char_type*
+ scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
+ { return this->do_scan_is(__m, __lo, __hi); }
+
+ const char_type*
+ scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
+ { return this->do_scan_not(__m, __lo, __hi); }
+
+ protected:
+ explicit
+ _Ctype(size_t __refs = 0) : _Ctype_nois<_CharT>(__refs) { }
+
+ virtual
+ ~_Ctype() { }
+
+ virtual bool
+ do_is(mask __m, char_type __c) const = 0;
+
+ virtual const char_type*
+ do_is(const char_type* __lo, const char_type* __hi,
+ mask* __vec) const = 0;
+
+ virtual const char_type*
+ do_scan_is(mask __m, const char_type* __lo,
+ const char_type* __hi) const = 0;
+
+ virtual const char_type*
+ do_scan_not(mask __m, const char_type* __lo,
+ const char_type* __hi) const = 0;
+ };
+
+ template<typename _CharT>
+ class ctype : public _Ctype<_CharT>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef typename ctype::mask mask;
+
+ explicit
+ ctype(size_t __refs = 0) : _Ctype<_CharT>(__refs) { }
+
+ static locale::id id;
+
+ protected:
+ virtual
+ ~ctype() { }
+
+ virtual bool
+ do_is(mask, char_type) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+
+ virtual const char_type*
+ do_is(const char_type*, const char_type*, mask*) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+
+ virtual const char_type*
+ do_scan_is(mask, const char_type*, const char_type*) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+
+ virtual const char_type*
+ do_scan_not(mask, const char_type*, const char_type*) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+
+ virtual char_type
+ do_toupper(char_type) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+
+ virtual const char_type*
+ do_toupper(char_type*, const char_type*) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+
+ virtual char_type
+ do_tolower(char_type) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+
+ virtual const char_type*
+ do_tolower(char_type*, const char_type*) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+
+ virtual char_type
+ do_widen(char) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+
+ virtual const char*
+ do_widen(const char*, const char*, char_type*) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+
+ virtual char
+ do_narrow(char_type, char) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+
+ virtual const char_type*
+ do_narrow(const char_type*, const char_type*, char, char*) const
+ {
+ // XXX Need definitions for these abstract mf's.
+ }
+ };
+
+
+ // 22.2.1.3 ctype specializations
+ // NB: Can use _Ctype_nois to actually implement the is
+ // functionality in the non-virtual (thus inline-able) member
+ // fuctions.
+ template<>
+ class ctype<char> : public _Ctype_nois<char>
+ {
+ public:
+ // Types:
+ typedef char char_type;
+ typedef ctype::mask mask;
+ typedef size_t __table_type;
+
+ private:
+ // Data Members:
+ bool _M_del;
+ __to_type const& _M_toupper;
+ __to_type const& _M_tolower;
+ const mask* const& _M_ctable;
+ const mask* _M_table;
+
+ public:
+ static locale::id id;
+ static const __table_type table_size = 1 +static_cast<unsigned char>(-1);
+
+ explicit
+ ctype(const mask* __table = 0, bool __del = false,
+ size_t __refs = 0) throw();
+
+ inline bool
+ is(mask __m, char __c) const throw();
+
+ inline const char*
+ is(const char* __low, const char* __high, mask* __vec) const throw();
+
+ inline const char*
+ scan_is(mask __m, const char* __low, const char* __high) const throw();
+
+ inline const char*
+ scan_not(mask __m, const char* __low, const char* __high) const throw();
+
+ protected:
+ virtual
+ ~ctype();
+
+ inline const mask*
+ table() const throw()
+ { return _M_table; }
+
+ inline const mask*
+ classic_table() throw()
+ { return _M_ctable; }
+
+ virtual char_type
+ do_toupper(char_type) const;
+
+ virtual const char_type*
+ do_toupper(char_type* __low, const char_type* __high) const;
+
+ virtual char_type
+ do_tolower(char_type) const;
+
+ virtual const char_type*
+ do_tolower(char_type* __low, const char_type* __high) const;
+
+ virtual char_type
+ do_widen(char) const;
+
+ virtual const char*
+ do_widen(const char* __low, const char* __high,
+ char_type* __dest) const;
+
+ virtual char
+ do_narrow(char_type, char __dfault) const;
+
+ virtual const char_type*
+ do_narrow(const char_type* __low, const char_type* __high,
+ char __dfault, char* __dest) const;
+ };
+
+ template<>
+ const ctype<char>&
+ use_facet<const ctype<char> > (const locale& __loc);
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+ // ctype<wchar_t> specialization
+ template<>
+ class ctype<wchar_t> : public _Ctype<wchar_t>
+ {
+ public:
+ // Types:
+ typedef wchar_t char_type;
+ typedef ctype::mask mask;
+ typedef size_t __table_type;
+
+ private:
+ __to_type const& _M_toupper;
+ __to_type const& _M_tolower;
+ const mask* const& _M_ctable;
+ static const __table_type _S_table_size = ctype<char>::table_size;
+
+ public:
+ static locale::id id;
+
+ explicit
+ ctype(size_t __refs = 0) throw();
+
+ protected:
+ virtual
+ ~ctype();
+
+ virtual bool
+ do_is(mask __m, char_type __c) const;
+
+ virtual const char_type*
+ do_is(const char_type* __lo, const char_type* __hi,
+ mask* __vec) const;
+
+ virtual const char_type*
+ do_scan_is(mask __m, const char_type* __lo,
+ const char_type* __hi) const;
+
+ virtual const char_type*
+ do_scan_not(mask __m, const char_type* __lo,
+ const char_type* __hi) const;
+
+ virtual char_type
+ do_toupper(char_type) const;
+
+ virtual const char_type*
+ do_toupper(char_type* __low, const char_type* __high) const;
+
+ virtual char_type
+ do_tolower(char_type) const;
+
+ virtual const char_type*
+ do_tolower(char_type* __low, const char_type* __high) const;
+
+ virtual char_type
+ do_widen(char) const;
+
+ virtual const char*
+ do_widen(const char* __low, const char* __high,
+ char_type* __dest) const;
+
+ virtual char
+ do_narrow(char_type, char __dfault) const;
+
+ virtual const char_type*
+ do_narrow(const char_type* __low, const char_type* __high,
+ char __dfault, char* __dest) const;
+
+ };
+
+ template<>
+ const ctype<wchar_t>&
+ use_facet< const ctype<wchar_t> > (const locale& __loc);
+#endif //_GLIBCPP_USE_WCHAR_T
+
+ // Include host-specific ctype specializations.
+ #include <bits/ctype_specializations.h>
+
+ // 22.2.1.2 Template class ctype_byname
+ template<typename _CharT>
+ class ctype_byname : public ctype<_CharT>
+ {
+ public:
+ typedef _CharT char_type;
+
+ explicit
+ ctype_byname(const char*, size_t __refs = 0);
+
+ protected:
+ virtual
+ ~ctype_byname() { }
+ };
+
+ // 22.2.1.4 Class ctype_byname specializations
+ template<>
+ ctype_byname<char>::ctype_byname(const char*, size_t refs);
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs);
+#endif
+
+
+ // 22.2.1.5 Template class codecvt
+ class codecvt_base
+ {
+ public:
+ enum result
+ {
+ ok,
+ partial,
+ error,
+ noconv
+ };
+ };
+
+ template<typename _InternT, typename _ExternT, typename _StateT>
+ class _Codecvt : public locale::facet, public codecvt_base
+ {
+ public:
+ // Types:
+ typedef _InternT intern_type;
+ typedef _ExternT extern_type;
+ typedef _StateT state_type;
+
+ protected:
+ explicit
+ _Codecvt (size_t __refs = 0) : locale::facet(__refs) { }
+
+ public:
+ result
+ out(state_type& __state, const intern_type* __from,
+ const intern_type* __from_end, const intern_type* &__from_next,
+ extern_type* __to, extern_type* __to_limit,
+ extern_type*& __to_next) const
+ {
+ return do_out(__state, __from, __from_end, __from_next, __to,
+ __to_limit, __to_next);
+ }
+
+ result
+ unshift(state_type& __state, extern_type* __to, extern_type* __to_limit,
+ extern_type*& __to_next) const
+ { return do_unshift(__state, __to,__to_limit,__to_next); }
+
+ result
+ in(state_type& __state, const extern_type* __from,
+ const extern_type* __from_end, const extern_type*& __from_next,
+ intern_type* __to, intern_type* __to_limit,
+ intern_type*& __to_next) const
+ {
+ return do_in(__state, __from, __from_end, __from_next,
+ __to, __to_limit, __to_next);
+ }
+
+ int
+ encoding() const throw()
+ { return do_encoding(); }
+
+ bool
+ always_noconv() const throw()
+ { return do_always_noconv(); }
+
+ int
+ length(const state_type& __state, const extern_type* __from,
+ const extern_type* __end, size_t __max) const
+ { return do_length(__state, __from, __end, __max); }
+
+ int
+ max_length() const throw()
+ { return do_max_length(); }
+
+ protected:
+ virtual
+ ~_Codecvt() { }
+
+ virtual result
+ do_out(state_type& __state,
+ const intern_type* __from, const intern_type* __from_end,
+ const intern_type*& __from_next,
+ extern_type* __to, extern_type* __to_limit,
+ extern_type*& __to_next) const = 0;
+
+ virtual result
+ do_unshift(state_type& __state,
+ extern_type* __to, extern_type* __to_limit,
+ extern_type*& __to_next) const = 0;
+
+ virtual result
+ do_in(state_type& __state,
+ const extern_type* __from, const extern_type* __from_end,
+ const extern_type*& __from_next,
+ intern_type* __to, intern_type* __to_limit,
+ intern_type*& __to_next) const = 0;
+
+ virtual int
+ do_encoding() const throw() = 0;
+
+ virtual bool
+ do_always_noconv() const throw() = 0;
+
+ virtual int
+ do_length(const state_type&, const extern_type* __from,
+ const extern_type* __end, size_t __max) const = 0;
+
+ virtual int
+ do_max_length() const throw() = 0;
+ };
+
+
+ template<typename _InternT, typename _ExternT, typename _StateT>
+ class codecvt : public _Codecvt<_InternT,_ExternT,_StateT>
+ {
+ public:
+ // Types:
+ typedef _InternT intern_type;
+ typedef _ExternT extern_type;
+ typedef _StateT state_type;
+
+ // Data Members:
+ static locale::id id;
+
+ explicit
+ codecvt(size_t __refs = 0)
+ : _Codecvt<_InternT,_ExternT,_StateT> (__refs) { }
+
+ protected:
+ virtual
+ ~codecvt() { }
+ };
+
+ // codecvt<char,char,mbstate_t> specialization
+ template<>
+ class codecvt<char, char, mbstate_t>
+ : public _Codecvt<char, char, mbstate_t>
+ {
+ public:
+ // Types:
+ typedef char intern_type;
+ typedef char extern_type;
+ typedef mbstate_t state_type;
+
+ explicit codecvt (size_t __refs = 0);
+ static locale::id id;
+
+ protected:
+ virtual ~codecvt();
+ virtual result
+ do_out(state_type& __state, const intern_type* __from,
+ const intern_type* __from_end, const intern_type*& __from_next,
+ extern_type* __to, extern_type* __to_limit,
+ extern_type*& __to_next) const;
+
+ virtual result
+ do_unshift(state_type& __state, extern_type* __to,
+ extern_type* __to_limit, extern_type*& __to_next) const;
+
+ virtual result
+ do_in(state_type& __state, const extern_type* __from,
+ const extern_type* __from_end, const extern_type*& __from_next,
+ intern_type* __to, intern_type* __to_limit,
+ intern_type*& __to_next) const;
+
+ virtual int do_encoding() const throw();
+ virtual bool do_always_noconv() const throw();
+ virtual int do_length(const state_type&, const extern_type* __from,
+ const extern_type* __end, size_t __max) const;
+ virtual int do_max_length() const throw();
+ };
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ class codecvt<wchar_t,char,mbstate_t>
+ : public _Codecvt<wchar_t,char,mbstate_t>
+ {
+ public:
+ // Types:
+ typedef wchar_t intern_type;
+ typedef char extern_type;
+ typedef mbstate_t state_type;
+
+ explicit codecvt(size_t __refs = 0);
+ static locale::id id;
+
+ protected:
+ virtual ~codecvt();
+ virtual result
+ do_out(state_type& __state, const intern_type* __from,
+ const intern_type* __from_end, const intern_type*& __from_next,
+ extern_type* __to, extern_type* __to_limit,
+ extern_type*& __to_next) const;
+
+ virtual result
+ do_unshift(state_type& __state,
+ extern_type* __to, extern_type* __to_limit,
+ extern_type*& __to_next) const;
+
+ virtual result
+ do_in(state_type& __state,
+ const extern_type* __from, const extern_type* __from_end,
+ const extern_type*& __from_next,
+ intern_type* __to, intern_type* __to_limit,
+ intern_type*& __to_next) const;
+
+ virtual int do_encoding() const throw();
+ virtual bool do_always_noconv() const throw();
+ virtual int do_length(const state_type&, const extern_type* __from,
+ const extern_type* __end, size_t __max) const;
+ virtual int do_max_length() const throw();
+ };
+#endif //_GLIBCPP_USE_WCHAR_T
+
+
+ // 22.2.1.6 Template class codecvt_byname
+ template<typename _InternT, typename _ExternT, typename _StateT>
+ class codecvt_byname : public codecvt<_InternT,_ExternT,_StateT>
+ {
+ public:
+ explicit
+ codecvt_byname(const char*, size_t __refs = 0)
+ : codecvt<_InternT,_ExternT,_StateT> (__refs) { }
+ protected:
+ virtual
+ ~codecvt_byname() { }
+ };
+
+ template<>
+ class codecvt_byname<char,char,mbstate_t>
+ : public codecvt<char,char,mbstate_t>
+ {
+ public:
+ explicit
+ codecvt_byname(const char*, size_t __refs = 0);
+
+ protected:
+ virtual
+ ~codecvt_byname();
+ };
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ class codecvt_byname<wchar_t,char,mbstate_t>
+ : public codecvt<wchar_t,char,mbstate_t>
+ {
+ public:
+ explicit
+ codecvt_byname(const char*, size_t __refs = 0);
+
+ protected:
+ virtual
+ ~codecvt_byname();
+ };
+#endif
+
+ template<typename _CharT, typename _InIter>
+ class _Numeric_get; // forward
+
+ // _Format_cache holds the information extracted from the numpunct<>
+ // and moneypunct<> facets in a form optimized for parsing and
+ // formatting. It is stored via a void* pointer in the pword()
+ // array of an iosbase object passed to the _get and _put facets.
+ // NB: contains no user-serviceable parts.
+ template<typename _CharT>
+ class _Format_cache
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef char_traits<_CharT> traits_type;
+ typedef basic_string<_CharT> string_type;
+ typedef string_type::size_type size_type;
+
+ // Forward decls and Friends:
+ friend class locale;
+ template<typename _Char, typename _InIter>
+ friend class _Numeric_get;
+ friend class num_get<_CharT>;
+ friend class num_put<_CharT>;
+ friend class time_get<_CharT>;
+ friend class money_get<_CharT>;
+ friend class time_put<_CharT>;
+ friend class money_put<_CharT>;
+
+ // Data Members:
+
+ // ios_base::pword() reserved cell
+ static int _S_pword_ix;
+
+ // True iff data members are consistent with the current locale,
+ // ie imbue sets this to false.
+ bool _M_valid;
+
+ // A list of valid numeric literals: for the standard "C" locale,
+ // this would usually be: "-+xX0123456789abcdef0123456789ABCDEF"
+ static const char _S_literals[];
+
+ // NB: Code depends on the order of definitions of the names
+ // these are indices into _S_literals, above.
+ // This string is formatted for putting, not getting. (output, not input)
+ enum
+ {
+ _S_minus,
+ _S_plus,
+ _S_ecks,
+ _S_Ecks,
+ _S_digits,
+ _S_digits_end = _S_digits + 16,
+ _S_udigits = _S_digits_end,
+ _S_udigits_end = _S_udigits + 16,
+ _S_ee = _S_digits + 14, // For scientific notation, 'E'
+ _S_Ee = _S_udigits + 14 // For scientific notation, 'e'
+ };
+
+ // The sign used to separate decimal values: for standard US
+ // locales, this would usually be: "."
+ // Abstracted from numpunct::decimal_point().
+ char_type _M_decimal_point;
+
+ // The sign used to separate groups of digits into smaller
+ // strings that the eye can parse with less difficulty: for
+ // standard US locales, this would usually be: ","
+ // Abstracted from numpunct::thousands_sep().
+ char_type _M_thousands_sep;
+
+ // However the US's "false" and "true" are translated.
+ // From numpunct::truename() and numpunct::falsename(), respectively.
+ string_type _M_truename;
+ string_type _M_falsename;
+
+ // If we are checking groupings. This should be equivalent to
+ // numpunct::groupings().size() != 0
+ bool _M_use_grouping;
+
+ // If we are using numpunct's groupings, this is the current
+ // grouping string in effect (from numpunct::grouping()).
+ string _M_grouping;
+
+ _Format_cache();
+
+ ~_Format_cache() throw() { }
+
+ // Given a member of the ios heirarchy as an argument, extract
+ // out all the current formatting information into a
+ // _Format_cache object and return a pointer to it.
+ static _Format_cache<_CharT>*
+ _S_get(ios_base& __ios);
+
+ void
+ _M_populate(ios_base&);
+
+ static void
+ _S_callback(ios_base::event __event, ios_base& __ios, int __ix) throw();
+ };
+
+ template<> _Format_cache<char>::_Format_cache();
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<> _Format_cache<wchar_t>::_Format_cache();
+#endif
+
+ // _Numeric_get is used by num_get, money_get, and time_get to help
+ // in parsing out numbers.
+ template<typename _CharT, typename _InIter>
+ class _Numeric_get
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef _InIter iter_type;
+
+ // Forward decls and Friends:
+ template<typename _Char, typename _InIterT>
+ friend class num_get;
+ template<typename _Char, typename _InIterT>
+ friend class time_get;
+ template<typename _Char, typename _InIterT>
+ friend class money_get;
+ template<typename _Char, typename _InIterT>
+ friend class num_put;
+ template<typename _Char, typename _InIterT>
+ friend class time_put;
+ template<typename _Char, typename _InIterT>
+ friend class money_put;
+
+ private:
+ explicit
+ _Numeric_get() { }
+
+ virtual
+ ~_Numeric_get() { }
+
+ iter_type
+ _M_get_digits(iter_type __in, iter_type __end) const;
+ };
+
+ template<typename _CharT, typename _InIter>
+ class num_get : public locale::facet
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef _InIter iter_type;
+ typedef char_traits<_CharT> __traits_type;
+
+ explicit
+ num_get(size_t __refs = 0) : locale::facet(__refs) { }
+
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, bool& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, short& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, int& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+#endif
+
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, long& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, long long& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+#endif
+
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, unsigned short& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, unsigned int& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, unsigned long& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, unsigned long long& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+#endif
+
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, float& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, double& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, long double& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+
+ iter_type
+ get(iter_type __in, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, void*& __v) const
+ { return do_get(__in, __end, __io, __err, __v); }
+ static locale::id id;
+
+ protected:
+ virtual ~num_get() { }
+
+ // This consolidates the extraction, storage and
+ // error-processing parts of the do_get(...) overloaded member
+ // functions. NB: this is specialized for char.
+ void
+ _M_extract(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, char* __xtrc,
+ int& __base, bool __fp = true) const;
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, bool&) const;
+
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, short&) const;
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate&, int&) const;
+#endif
+ virtual iter_type
+ do_get (iter_type, iter_type, ios_base&, ios_base::iostate&, long&) const;
+#ifdef _GLIBCPP_USE_LONG_LONG
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ long long&) const;
+#endif
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ unsigned short&) const;
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&,
+ ios_base::iostate& __err, unsigned int&) const;
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&,
+ ios_base::iostate& __err, unsigned long&) const;
+#ifdef _GLIBCPP_USE_LONG_LONG
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&,
+ ios_base::iostate& __err, unsigned long long&) const;
+#endif
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ float&) const;
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ double&) const;
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&,
+ ios_base::iostate& __err, long double&) const;
+
+ virtual iter_type
+ do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err,
+ void*&) const;
+ };
+
+ // Declare specialized extraction member function.
+ template<>
+ void
+ num_get<char, istreambuf_iterator<char> >::
+ _M_extract(istreambuf_iterator<char> __beg,
+ istreambuf_iterator<char> __end, ios_base& __io,
+ ios_base::iostate& __err, char* __xtrc,
+ int& __base, bool __fp) const;
+
+ // _Numeric_put is used by num_put, money_put, and time_put
+ // to help in formatting out numbers.
+ template<typename _CharT, typename _OutIter>
+ class _Numeric_put
+ {
+ public:
+ typedef _CharT char_type;
+ typedef _OutIter iter_type;
+ protected:
+ explicit
+ _Numeric_put() { }
+
+ virtual
+ ~_Numeric_put() { }
+ };
+
+ template<typename _CharT, typename _OutIter>
+ class num_put : public locale::facet
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef _OutIter iter_type;
+
+ explicit
+ num_put(size_t __refs = 0) : locale::facet(__refs) { }
+
+ iter_type
+ put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
+ { return do_put(__s, __f, __fill, __v); }
+
+ iter_type
+ put(iter_type __s, ios_base& __f, char_type __fill, long __v) const
+ { return do_put(__s, __f, __fill, __v); }
+
+ iter_type
+ put(iter_type __s, ios_base& __f, char_type __fill,
+ unsigned long __v) const
+ { return do_put(__s, __f, __fill, __v); }
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ iter_type
+ put(iter_type __s, ios_base& __f, char_type __fill, long long __v) const
+ { return do_put(__s, __f, __fill, __v); }
+
+ iter_type
+ put(iter_type __s, ios_base& __f, char_type __fill,
+ unsigned long long __v) const
+ { return do_put(__s, __f, __fill, __v); }
+#endif
+
+ iter_type
+ put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
+ { return do_put(__s, __f, __fill, __v); }
+
+ iter_type
+ put(iter_type __s, ios_base& __f, char_type __fill,
+ long double __v) const
+ { return do_put(__s, __f, __fill, __v); }
+
+ iter_type
+ put(iter_type __s, ios_base& __f, char_type __fill,
+ const void* __v) const
+ { return do_put(__s, __f, __fill, __v); }
+
+ static locale::id id;
+
+ protected:
+ virtual
+ ~num_put() { };
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, bool __v) const;
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, long __v) const;
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, long long __v) const;
+#endif
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
+#endif
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, double __v) const;
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, long double __v) const;
+
+ virtual iter_type
+ do_put(iter_type, ios_base&, char_type __fill, const void* __v) const;
+ };
+
+ template<typename _CharT>
+ class _Punct : public locale::facet
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+
+ char_type
+ decimal_point() const
+ { return do_decimal_point(); }
+
+ char_type
+ thousands_sep() const
+ { return do_thousands_sep(); }
+
+ string
+ grouping() const
+ { return do_grouping(); }
+ protected:
+
+ explicit
+ _Punct(size_t __refs = 0) : locale::facet(__refs) { }
+
+ virtual
+ ~_Punct() { }
+
+ virtual char_type
+ do_decimal_point() const
+ { return _M_decimal_point; }
+
+ virtual char_type
+ do_thousands_sep() const
+ { return _M_thousands_sep; }
+
+ virtual string
+ do_grouping() const
+ { return _M_grouping; }
+
+ private:
+ char_type _M_decimal_point;
+ char_type _M_thousands_sep;
+ string _M_grouping;
+
+ protected:
+ // for use at construction time only:
+ void
+ _M_init(char_type __d, char_type __t, const string& __g)
+ {
+ _M_decimal_point = __d;
+ _M_thousands_sep = __t;
+ _M_grouping = __g;
+ }
+
+ };
+
+ template<typename _CharT>
+ class _Numpunct : public _Punct<_CharT>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+
+ string_type
+ truename() const
+ { return do_truename(); }
+
+ string_type
+ falsename() const
+ { return do_falsename(); }
+
+ protected:
+ explicit
+ _Numpunct(size_t __refs = 0) : _Punct<_CharT> (__refs) { }
+
+ virtual
+ ~_Numpunct() { }
+
+ virtual string_type
+ do_truename() const
+ { return _M_truename; }
+
+ virtual string_type
+ do_falsename() const
+ { return _M_falsename; }
+
+ private:
+ string_type _M_truename;
+ string_type _M_falsename;
+
+ protected:
+ // For use only during construction
+ void
+ _M_init_boolnames(const string_type& __t, const string_type& __f)
+ {
+ _M_truename = __t;
+ _M_falsename = __f;
+ }
+
+ };
+
+ template<typename _CharT>
+ class numpunct : public _Numpunct<_CharT>
+ {
+ public:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+
+ static locale::id id;
+
+ explicit
+ numpunct(size_t __refs = 0) : _Numpunct<_CharT>(__refs) { }
+ protected:
+
+ virtual
+ ~numpunct() { }
+ };
+
+ template<>
+ numpunct<char>::numpunct(size_t __refs): _Numpunct<char>(__refs)
+ {
+ _M_init('.', ',', "");
+ _M_init_boolnames("true", "false");
+ }
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ numpunct<wchar_t>::numpunct(size_t __refs): _Numpunct<wchar_t>(__refs)
+ {
+ _M_init(L'.', L',', "");
+ _M_init_boolnames(L"true", L"false");
+ }
+#endif
+
+ template<typename _CharT>
+ class numpunct_byname : public numpunct<_CharT>
+ {
+ public:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+
+ explicit
+ numpunct_byname(const char*, size_t __refs = 0);
+
+ protected:
+ virtual
+ ~numpunct_byname() { }
+ };
+
+ template<>
+ numpunct_byname<char>::numpunct_byname(const char*, size_t __refs);
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ numpunct_byname<wchar_t>::numpunct_byname(const char*, size_t __refs);
+#endif
+
+ template<typename _CharT>
+ class _Collate : public locale::facet
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+
+ int
+ compare(const _CharT* __lo1, const _CharT* __hi1,
+ const _CharT* __lo2, const _CharT* __hi2) const
+ { return do_compare(__lo1, __hi1, __lo2, __hi2); }
+
+ string_type
+ transform(const _CharT* __lo, const _CharT* __hi) const
+ { return do_transform(__lo, __hi); }
+
+ long
+ hash(const _CharT* __lo, const _CharT* __hi) const
+ { return do_hash(__lo, __hi); }
+
+ protected:
+ explicit
+ _Collate(size_t __refs = 0) : locale::facet(__refs) { }
+
+ ~_Collate() { } // virtual
+
+ virtual int
+ do_compare(const _CharT* __lo1, const _CharT* __hi1,
+ const _CharT* __lo2, const _CharT* __hi2) const = 0;
+
+ virtual string_type
+ do_transform(const _CharT* __lo, const _CharT* __hi) const = 0;
+
+ virtual long
+ do_hash(const _CharT* __lo, const _CharT* __hi) const = 0;
+ };
+
+ template<typename _CharT>
+ class collate : public _Collate<_CharT>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+
+ explicit
+ collate(size_t __refs = 0) : _Collate<_CharT> (__refs) { }
+
+ static locale::id id;
+
+ protected:
+ virtual
+ ~collate() { }
+ };
+
+ template<>
+ class collate<char> : public _Collate<char>
+ {
+ public:
+ // Types:
+ typedef char char_type;
+ typedef basic_string<char> string_type;
+
+ explicit
+ collate(size_t __refs = 0);
+
+ static locale::id id;
+
+ protected:
+ virtual
+ ~collate();
+
+ virtual int
+ do_compare(const char* __lo1, const char* __hi1,
+ const char* __lo2, const char* __hi2) const;
+
+ virtual string_type
+ do_transform(const char* __lo, const char* __hi) const;
+
+ virtual long
+ do_hash(const char* __lo, const char* __hi) const;
+ };
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ class collate<wchar_t> : public _Collate<wchar_t>
+ {
+ public:
+ // Types:
+ typedef wchar_t char_type;
+ typedef basic_string<wchar_t> string_type;
+
+ explicit
+ collate(size_t __refs = 0);
+
+ static locale::id id;
+
+ protected:
+ virtual
+ ~collate();
+
+ virtual int
+ do_compare(const wchar_t* __lo1, const wchar_t* __hi1,
+ const wchar_t* __lo2, const wchar_t* __hi2) const;
+
+ virtual string_type
+ do_transform(const wchar_t* __lo, const wchar_t* __hi) const;
+
+ virtual long
+ do_hash(const wchar_t* __lo, const wchar_t* __hi) const;
+ };
+#endif
+
+ template<typename _CharT>
+ class collate_byname : public collate<_CharT>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+
+ explicit
+ collate_byname(const char*, size_t __refs = 0);
+
+ protected:
+ virtual
+ ~collate_byname() { }
+ };
+
+ template<>
+ collate_byname<char>::collate_byname(const char*, size_t __refs);
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ collate_byname<wchar_t>::collate_byname(const char*, size_t __refs);
+#endif
+
+ class time_base
+ {
+ public:
+ enum dateorder { no_order, dmy, mdy, ymd, ydm };
+ };
+
+ template<typename _CharT, typename _InIter>
+ class time_get : public locale::facet, public time_base
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef _InIter iter_type;
+
+ explicit
+ time_get(size_t __refs = 0)
+ : locale::facet (__refs), _M_daynames(0), _M_monthnames(0) { }
+
+ dateorder
+ date_order() const
+ { return do_date_order(); }
+
+ iter_type
+ get_time(iter_type __s, iter_type __end, ios_base& __f,
+ ios_base::iostate& __err, tm* __t) const
+ { return do_get_time(__s, __end, __f, __err, __t); }
+
+ iter_type
+ get_date(iter_type __s, iter_type __end, ios_base& __f,
+ ios_base::iostate& __err, tm* __t) const
+ { return do_get_date(__s, __end, __f, __err, __t); }
+
+ iter_type
+ get_weekday(iter_type __s, iter_type __end, ios_base& __f,
+ ios_base::iostate& __err, tm* __t) const
+ { return do_get_weekday(__s,__end,__f,__err,__t); }
+
+ iter_type
+ get_monthname(iter_type __s, iter_type __end, ios_base& __f,
+ ios_base::iostate& __err, tm* __t) const
+ { return do_get_monthname(__s,__end,__f,__err,__t); }
+
+ iter_type
+ get_year(iter_type __s, iter_type __end, ios_base& __f,
+ ios_base::iostate& __err, tm* __t) const
+ { return do_get_year(__s,__end,__f,__err,__t); }
+
+ static locale::id id;
+
+ protected:
+ virtual
+ ~time_get()
+ {
+ delete [] _M_monthnames;
+ delete [] _M_daynames;
+ }
+
+ virtual dateorder
+ do_date_order() const
+ { return time_base::ymd; }
+
+ virtual iter_type
+ do_get_time(iter_type __s, iter_type /*__end*/, ios_base&,
+ ios_base::iostate& /*__err*/, tm* /*__t*/) const
+ { return __s; }
+
+ virtual iter_type
+ do_get_date(iter_type __s, iter_type /*__end*/, ios_base&,
+ ios_base::iostate& /*__err*/, tm* /*__t*/) const
+ { return __s; }
+
+ virtual iter_type
+ do_get_weekday(iter_type __s, iter_type __end, ios_base&,
+ ios_base::iostate& __err, tm* __t) const;
+
+ virtual iter_type
+ do_get_monthname(iter_type __s, iter_type __end, ios_base&,
+ ios_base::iostate& __err, tm* __t) const;
+
+ virtual iter_type
+ do_get_year(iter_type __s, iter_type /*__end*/, ios_base&,
+ ios_base::iostate& /*__err*/, tm* /*__t*/) const
+ { return __s; }
+
+ mutable basic_string<_CharT>* _M_daynames;
+ mutable basic_string<_CharT>* _M_monthnames;
+ };
+
+ template<typename _CharT, typename _InIter>
+ class time_get_byname : public time_get<_CharT, _InIter>
+ {
+ public:
+ typedef _CharT char_type;
+ typedef _InIter iter_type;
+
+ explicit
+ time_get_byname(const char*, size_t __refs = 0)
+ : time_get<_CharT, _InIter>(__refs) { }
+ protected:
+ virtual
+ ~time_get_byname() { }
+ };
+
+ template<typename _CharT, typename _OutIter>
+ class time_put : public locale::facet, public time_base
+ {
+ public:
+ typedef _CharT char_type;
+ typedef _OutIter iter_type;
+
+ explicit
+ time_put(size_t __refs = 0) : locale::facet (__refs) { }
+
+ // NB: this is a nonvirtual, calls do_put in a loop.
+ iter_type
+ put(iter_type __s, ios_base& /*__f*/, char_type /*__fill*/,
+ const tm* /*__tmb*/, const _CharT* /*__pattern*/,
+ const _CharT* /*__pat_end*/) const
+ { return __s; }
+
+ iter_type
+ put(iter_type __s, ios_base& __f, char_type __fill,
+ const tm* __tmb, char __format, char __modifier = 0) const
+ { return do_put(__s, __f, __fill, __tmb, __format, __modifier); }
+
+ static locale::id id;
+
+ protected:
+ virtual
+ ~time_put() { }
+
+ virtual iter_type
+ do_put(iter_type __s, ios_base&, char_type, const tm* /*__t*/,
+ char /*__format*/, char /*__mod*/) const
+ { return __s; }
+ };
+
+ template<typename _CharT, typename _OutIter>
+ class time_put_byname : time_put<_CharT, _OutIter>
+ {
+ public:
+ typedef _CharT char_type;
+ typedef _OutIter iter_type;
+
+ explicit
+ time_put_byname(const char*, size_t __refs = 0)
+ : time_put<_CharT, _OutIter> (__refs) { }
+ protected:
+ virtual
+ ~time_put_byname() { }
+ };
+
+
+ template<typename _CharT, typename _InIter>
+ class money_get : public locale::facet
+ {
+ public:
+ typedef _CharT char_type;
+ typedef _InIter iter_type;
+ typedef basic_string<_CharT> string_type;
+
+ explicit
+ money_get(size_t __refs = 0) : locale::facet(__refs) { }
+
+ iter_type
+ get(iter_type __s, iter_type __end, bool __intl,
+ ios_base& __f, ios_base::iostate& __err, long double& __units) const
+ { return do_get(__s, __end, __intl, __f, __err, __units); }
+
+ iter_type
+ get(iter_type __s, iter_type __end, bool __intl, ios_base& __f,
+ ios_base::iostate& __err, string_type& __digits) const
+ { return do_get(__s, __end, __intl, __f, __err, __digits); }
+
+ static locale::id id;
+
+ protected:
+ virtual
+ ~money_get() { }
+
+ virtual iter_type
+ do_get(iter_type __s, iter_type /*__end*/, bool /*__intl*/,
+ ios_base& /*__io*/, ios_base::iostate& /*__err*/,
+ long double& /*__units*/) const
+ { return __s; }
+
+ virtual iter_type
+ do_get(iter_type __s, iter_type /*__end*/, bool /*__intl*/,
+ ios_base& /*__io*/, ios_base::iostate& /*__err*/,
+ string_type& /*__digits*/) const
+ { return __s; }
+ };
+
+ template<typename _CharT, typename _OutIter>
+ class money_put : public locale::facet
+ {
+ public:
+ typedef _CharT char_type;
+ typedef _OutIter iter_type;
+ typedef basic_string<_CharT> string_type;
+
+ explicit
+ money_put(size_t __refs = 0) : locale::facet(__refs) { }
+
+ iter_type
+ put(iter_type __s, bool __intl, ios_base& __f,
+ char_type __fill, long double __units) const
+ { return do_put(__s, __intl, __f, __fill, __units); }
+
+ iter_type
+ put(iter_type __s, bool __intl, ios_base& __f,
+ char_type __fill, const string_type& __digits) const
+ { return do_put(__s, __intl, __f, __fill, __digits); }
+
+ static locale::id id;
+
+ protected:
+ virtual
+ ~money_put() { }
+
+ virtual iter_type
+ do_put(iter_type __s, bool, ios_base& /*__io*/, char_type /*__fill*/,
+ long double /*__units*/) const
+ { return __s; }
+
+ virtual iter_type
+ do_put(iter_type __s, bool, ios_base& /*__io*/, char_type /*__fill*/,
+ const string_type& /*__digits*/) const
+ { return __s; }
+ };
+
+ struct money_base
+ {
+ enum part { none, space, symbol, sign, value };
+ struct pattern { char field[4]; };
+
+ static const pattern __default_pattern;
+ };
+
+ template<typename _CharT>
+ class _Moneypunct : public _Punct<_CharT>, public money_base
+ {
+ public:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+
+ string_type
+ curr_symbol() const
+ { return do_curr_symbol(); }
+
+ string_type
+ positive_sign() const
+ { return do_positive_sign(); }
+
+ string_type
+ negative_sign() const
+ { return do_negative_sign(); }
+
+ int
+ frac_digits() const
+ { return do_frac_digits(); }
+
+ pattern
+ pos_format() const
+ { return do_pos_format(); }
+
+ pattern
+ neg_format() const
+ { return do_neg_format(); }
+
+ protected:
+ explicit
+ _Moneypunct(size_t __refs = 0) : _Punct<_CharT> (__refs) { }
+
+ virtual
+ ~_Moneypunct() { }
+
+ virtual string_type
+ do_curr_symbol() const
+ { return basic_string<_CharT>(); }
+
+ virtual string_type
+ do_positive_sign() const
+ { return basic_string<_CharT>(); }
+
+ virtual string_type
+ do_negative_sign() const
+ { return basic_string<_CharT>(); }
+
+ virtual int
+ do_frac_digits() const
+ { return 0; }
+
+ virtual pattern
+ do_pos_format() const
+ {
+ return money_base::__default_pattern;
+ }
+
+ virtual pattern
+ do_neg_format() const
+ {
+ return money_base::__default_pattern;
+ }
+
+ };
+
+ template<typename _CharT, bool _Intl>
+ class moneypunct : public _Moneypunct<_CharT>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+
+ static const bool intl = _Intl;
+ static locale::id id;
+
+ explicit
+ moneypunct(size_t __refs = 0) : _Moneypunct<_CharT> (__refs) { }
+ protected:
+ virtual
+ ~moneypunct() { }
+ };
+
+ template<typename _CharT, bool _Intl>
+ class moneypunct_byname : public moneypunct<_CharT,_Intl>
+ {
+ public:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+ static const bool intl = _Intl;
+
+ explicit
+ moneypunct_byname(const char*, size_t __refs = 0);
+
+ protected:
+ virtual
+ ~moneypunct_byname() { }
+ };
+
+ template<>
+ moneypunct_byname<char, false>::
+ moneypunct_byname(const char*, size_t __refs);
+ template<>
+ moneypunct_byname<char, true>::
+ moneypunct_byname(const char*, size_t __refs);
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ moneypunct_byname<wchar_t,false>::
+ moneypunct_byname(const char*, size_t __refs);
+ template<>
+ moneypunct_byname<wchar_t,true>::
+ moneypunct_byname (const char*, size_t __refs);
+#endif
+
+ struct messages_base
+ {
+ typedef int catalog;
+ };
+
+ template<typename _CharT>
+ class _Messages : public locale::facet, public messages_base
+ {
+ public:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+
+ catalog
+ open(const basic_string<char>& __s, const locale& __loc) const
+ { return do_open(__s, __loc); }
+
+ string_type
+ get(catalog __c, int __set, int __msgid, const string_type& __s) const
+ { return do_get(__c,__set,__msgid,__s); }
+
+ void
+ close(catalog __c) const
+ { return do_close(__c); }
+
+ protected:
+ explicit
+ _Messages(size_t __refs = 0) : locale::facet(__refs) { }
+
+ virtual
+ ~_Messages() { }
+
+ // NB: Probably these should be pure, and implemented only in
+ // specializations of messages<>. But for now...
+ virtual catalog
+ do_open(const basic_string<char>&, const locale&) const
+ { return 0; }
+
+ virtual string_type
+ do_get(catalog, int, int /*__msgid*/, const string_type& __dfault) const
+ { return __dfault; }
+
+ virtual void
+ do_close (catalog) const { }
+ };
+
+ template<typename _CharT>
+ class messages : public _Messages<_CharT>
+ {
+ public:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+ static locale::id id;
+
+ explicit
+ messages(size_t __refs = 0) : _Messages<_CharT> (__refs) { }
+ protected:
+ virtual
+ ~messages() { }
+ };
+
+ template<typename _CharT>
+ class messages_byname : public messages<_CharT>
+ {
+ public:
+ typedef _CharT char_type;
+ typedef basic_string<_CharT> string_type;
+
+ explicit
+ messages_byname(const char*, size_t __refs = 0);
+
+ protected:
+ virtual
+ ~messages_byname() { }
+ };
+
+ template<>
+ messages_byname<char>::messages_byname(const char*, size_t __refs);
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ messages_byname<wchar_t>::messages_byname(const char*, size_t __refs);
+#endif
+
+ // Subclause convenience interfaces, inlines
+ // NB: these are inline
+ // because, when used in a loop, some compilers can hoist the body
+ // out of the loop; then it's just as fast as the C is*() function.
+ template<typename _CharT>
+ inline bool
+ isspace(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).is(ctype_base::space, __c); }
+
+ template<typename _CharT>
+ inline bool
+ isprint(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).is(ctype_base::print, __c); }
+
+ template<typename _CharT>
+ inline bool
+ iscntrl(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).is(ctype_base::cntrl, __c); }
+
+ template<typename _CharT>
+ inline bool
+ isupper(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).is(ctype_base::upper, __c); }
+
+ template<typename _CharT>
+ inline bool islower(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).is(ctype_base::lower, __c); }
+
+ template<typename _CharT>
+ inline bool
+ isalpha(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).is(ctype_base::alpha, __c); }
+
+ template<typename _CharT>
+ inline bool
+ isdigit(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).is(ctype_base::digit, __c); }
+
+ template<typename _CharT>
+ inline bool
+ ispunct(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).is(ctype_base::punct, __c); }
+
+ template<typename _CharT>
+ inline bool
+ isxdigit(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).is(ctype_base::xdigit, __c); }
+
+ template<typename _CharT>
+ inline bool
+ isalnum(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).is(ctype_base::alnum, __c); }
+
+ template<typename _CharT>
+ inline bool
+ isgraph(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).is(ctype_base::graph, __c); }
+
+ template<typename _CharT>
+ inline _CharT
+ toupper(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).toupper(__c); }
+
+ template<typename _CharT>
+ inline _CharT
+ tolower(_CharT __c, const locale& __loc)
+ { return use_facet<ctype<_CharT> > (__loc).tolower(__c); }
+
+} // namespace std
+
+#endif /* _CPP_BITS_LOCFACETS_H */
+
+// Local Variables:
+// mode:c++
+// End:
+
diff --git a/libstdc++-v3/bits/locale_facets.tcc b/libstdc++-v3/bits/locale_facets.tcc
new file mode 100644
index 0000000..3772f06
--- /dev/null
+++ b/libstdc++-v3/bits/locale_facets.tcc
@@ -0,0 +1,1440 @@
+// Locale support -*- C++ -*-
+
+// Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+// Warning: this file is not meant for user inclusion. Use <locale>.
+
+#ifndef _CPP_BITS_LOCFACETS_TCC
+#define _CPP_BITS_LOCFACETS_TCC 1
+
+#include <bits/std_cerrno.h>
+#include <bits/std_cstdlib.h> // For strof, strtold
+#include <bits/std_limits.h> // For numeric_limits
+#include <bits/std_vector.h>
+#include <bits/std_memory.h> // For auto_ptr
+#include <bits/sbuf_iter.h> // For streambuf_iterators
+
+namespace std
+{
+ template<typename _Facet>
+ locale
+ locale::combine(const locale& __other)
+ {
+ locale __copy(*this);
+ __copy._M_impl->_M_replace_facet(__other._M_impl, &_Facet::id);
+ __copy._M_impl->_M_has_name = false;
+ return __copy;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ bool
+ locale::operator()(const basic_string<_CharT,_Traits,_Alloc>& __s1,
+ const basic_string<_CharT,_Traits,_Alloc>& __s2) const
+ {
+ // XXX should not need to qualify here.
+ // typedef collate<_CharT> __collate_type;
+ typedef std::collate<_CharT> __collate_type;
+ const __collate_type* __fcoll = &use_facet<__collate_type>(*this);
+ return (__fcoll->compare(__s1.data(), __s1.data() + __s1.length(),
+ __s2.data(), __s2.data() + __s2.length()) < 0);
+ }
+
+ template<typename _Facet>
+ const _Facet&
+ use_facet(const locale& __loc)
+ {
+ const locale::facet* __fp = (const _Facet*)0; // check derivation
+ locale::id& __id = _Facet::id; // check member id
+ size_t __i = __id._M_index;
+ const locale::_Impl* __tmp = __loc._M_impl;
+ if (__id._M_index >= __loc._M_impl->_M_facets->size()
+ || (__fp = (*(__tmp->_M_facets))[__i]) == 0)
+ return _Use_facet_failure_handler<_Facet>(__loc);
+ return static_cast<const _Facet&>(*__fp);
+ }
+
+ template<typename _Facet>
+ bool
+ has_facet(const locale& __loc) throw()
+ {
+ typedef locale::_Impl::__vec_facet __vec_facet;
+ locale::id& __id = _Facet::id; // check member id
+ size_t __i = __id._M_index;
+ __vec_facet* __tmpv = __loc._M_impl->_M_facets;
+ return (__i < __tmpv->size() && (*__tmpv)[__i] != 0);
+ }
+
+ // __match_parallel
+ // matches input __s against a set of __ntargs strings in __targets,
+ // placing in __matches a vector of indices into __targets which
+ // match, and in __remain the number of such matches. If it hits
+ // end of sequence before it minimizes the set, sets __eof.
+ // Empty strings are never matched.
+ template<typename _InIter, typename _CharT>
+ _InIter
+ __match_parallel(_InIter __s, _InIter __end, int __ntargs,
+ const basic_string<_CharT>* __targets,
+ int* __matches, int& __remain, bool& __eof)
+ {
+ typedef basic_string<_CharT> __string_type;
+ __eof = false;
+ for (int __ti = 0; __ti < __ntargs; ++__ti)
+ __matches[__ti] = __ti;
+ __remain = __ntargs;
+ size_t __pos = 0;
+ do
+ {
+ {
+ int __ti = 0;
+ for (;__ti < __remain &&
+ __pos == __targets[__matches[__ti]].size(); ++__ti)
+ { }
+ if (__ti == __remain)
+ {
+ if (__pos == 0) __remain = 0;
+ return __s;
+ }
+ }
+ if (__s == __end)
+ __eof = true;
+ bool __matched = false;
+ for (int __ti = 0; __ti < __remain; )
+ {
+ const __string_type& __target = __targets[__matches[__ti]];
+ if (__pos < __target.size())
+ {
+ if (__eof || __target[__pos] != *__s)
+ {
+ __matches[__ti] = __matches[--__remain];
+ continue;
+ }
+ __matched = true;
+ }
+ ++__ti;
+ }
+ if (__matched)
+ {
+ ++__s;
+ ++__pos;
+ }
+ for (int __ti = 0; __ti < __remain;)
+ {
+ if (__pos > __targets[__matches[__ti]].size())
+ {
+ __matches[__ti] = __matches[--__remain];
+ continue;
+ }
+ ++__ti;
+ }
+ }
+ while (__remain);
+ return __s;
+ }
+
+ template<typename _CharT>
+ locale::id ctype<_CharT>::id;
+
+ template<typename _InternT, typename _ExternT, typename _StateT>
+ locale::id codecvt<_InternT,_ExternT,_StateT>::id;
+
+ template<typename _CharT>
+ int _Format_cache<_CharT>::_S_pword_ix;
+
+ template<typename _CharT>
+ const char _Format_cache<_CharT>::
+ _S_literals[] = "-+xX0123456789abcdef0123456789ABCDEF";
+
+ template<typename _CharT>
+ _Format_cache<_CharT>::_Format_cache()
+ : _M_valid(true), _M_use_grouping(false)
+ { }
+
+ template<>
+ _Format_cache<char>::_Format_cache()
+ : _M_valid(true),
+ _M_decimal_point('.'), _M_thousands_sep(','),
+ _M_truename("true"), _M_falsename("false"), _M_use_grouping(false)
+ { }
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ _Format_cache<wchar_t>::_Format_cache()
+ : _M_valid(true),
+ _M_decimal_point(L'.'), _M_thousands_sep(L','),
+ _M_truename(L"true"), _M_falsename(L"false"), _M_use_grouping(false)
+ { }
+#endif
+
+ template<typename _CharT>
+ void
+ _Format_cache<_CharT>::_M_populate(ios_base& __io)
+ {
+ locale __loc = __io.getloc ();
+ numpunct<_CharT> const& __np = use_facet<numpunct<_CharT> >(__loc);
+ _M_truename = __np.truename();
+ _M_falsename = __np.falsename();
+ _M_thousands_sep = __np.thousands_sep();
+ _M_decimal_point = __np.decimal_point();
+ _M_grouping = __np.grouping();
+ _M_use_grouping = _M_grouping.size() != 0 && _M_grouping.data()[0] != 0;
+ _M_valid = true;
+ }
+
+ // This function is always called via a pointer installed in
+ // an ios_base by ios_base::register_callback.
+ template<typename _CharT>
+ void
+ _Format_cache<_CharT>::
+ _S_callback(ios_base::event __ev, ios_base& __ios, int __ix) throw()
+ {
+ void*& __p = __ios.pword(__ix);
+ switch (__ev)
+ {
+ case ios_base::erase_event:
+ delete static_cast<_Format_cache<_CharT>*> (__p); __p = 0;
+ break;
+ case ios_base::copyfmt_event:
+ // If just stored zero, the callback would get registered again.
+ try {
+ __p = new _Format_cache<_CharT>;
+ }
+ catch(...) {
+ }
+ break;
+ case ios_base::imbue_event:
+ static_cast<_Format_cache<_CharT>*>(__p)->_M_valid = false;
+ break;
+ }
+ }
+
+ template<typename _CharT>
+ _Format_cache<_CharT>*
+ _Format_cache<_CharT>::_S_get(ios_base& __ios)
+ {
+ if (!_S_pword_ix)
+ _S_pword_ix = ios_base::xalloc(); // XXX MT
+ void*& __p = __ios.pword(_S_pword_ix);
+
+ // XXX What if pword fails? must check failbit, throw.
+ if (__p == 0) // XXX MT? maybe sentry takes care of it
+ {
+ auto_ptr<_Format_cache<_CharT> > __ap(new _Format_cache<_CharT>);
+ __ios.register_callback(&_Format_cache<_CharT>::_S_callback,
+ _S_pword_ix);
+ __p = __ap.release();
+ }
+ _Format_cache<_CharT>* __ncp = static_cast<_Format_cache<_CharT>*>(__p);
+ if (!__ncp->_M_valid)
+ __ncp->_M_populate(__ios);
+
+ return __ncp;
+ }
+
+ template<typename _CharT, typename _InIter>
+ locale::id num_get<_CharT, _InIter>::id;
+
+ // This member function takes an (w)istreambuf_iterator object and
+ // parses it into a generic char array suitable for parsing with
+ // strto[l,ll,f,d]. The thought was to encapsulate the conversion
+ // into this one function, and thus the num_get::do_get member
+ // functions can just adjust for the type of the overloaded
+ // argument and process the char array returned from _M_extract.
+ // Other things were also considered, including a fused
+ // multiply-add loop that would obviate the need for any call to
+ // strto... at all: however, it would b e a bit of a pain, because
+ // you'd have to be able to return either floating or integral
+ // types, etc etc. The current approach seems to be smack dab in
+ // the middle between an unoptimized approach using sscanf, and
+ // some kind of hyper-optimized approach alluded to above.
+
+ // XXX
+ // Need to do partial specialization to account for differences
+ // between character sets. For char, this is pretty
+ // straightforward, but for wchar_t, the conversion to a plain-jane
+ // char type is a bit more involved.
+ template<typename _CharT, typename _InIter>
+ void
+ num_get<_CharT, _InIter>::
+ _M_extract(iter_type /*__beg*/, iter_type /*__end*/, ios_base& /*__io*/,
+ ios_base::iostate& /*__err*/, char* /*__xtrc*/,
+ int& /*__base*/, bool /*__fp*/) const
+ {
+ // XXX Not currently done: need to expand upon char version below.
+ }
+
+ template<>
+ void
+ num_get<char, istreambuf_iterator<char> >::
+ _M_extract(istreambuf_iterator<char> __beg,
+ istreambuf_iterator<char> __end, ios_base& __io,
+ ios_base::iostate& __err, char* __xtrc,
+ int& __base, bool __fp) const
+ {
+ typedef _Format_cache<char> __cache_type;
+
+ // Stage 1: determine a conversion specifier.
+ ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield;
+ if (__basefield == ios_base::oct)
+ __base = 8;
+ else if (__basefield == ios_base::hex)
+ __base = 16;
+ else
+ __base = 10;
+
+ // Stage 2: extract characters.
+ __cache_type const* __fmt = __cache_type::_S_get(__io);
+ bool __valid = __beg != __end;
+ string __grp;
+ int __sep_pos = 0;
+ int __pos = 0;
+ bool __testdec = false;
+ const char* __lits = __fmt->_S_literals;
+
+ while (__valid && __beg != __end)
+ {
+ __valid = false;
+ char __c = *__beg;
+ char* __p = strchr(__fmt->_S_literals, __c);
+
+ // NB: strchr returns true for __c == 0x0
+ if (__p && __c)
+ {
+ if ((__p >= &__lits[__cache_type::_S_digits + __base]
+ && __p < &__lits[__cache_type::_S_digits_end]) ||
+ (__p >= &__lits[__cache_type::_S_udigits+__base]
+ && __p < &__lits[__cache_type::_S_udigits_end]))
+ {
+ if (!(__fp && (__p == &__lits[__cache_type::_S_ee]
+ || __p == &__lits[__cache_type::_S_Ee])))
+ break;
+ }
+ __xtrc[__pos] = __c;
+ ++__pos;
+ ++__sep_pos;
+ __valid = true;
+ }
+ else if (__c == __fmt->_M_thousands_sep
+ && __fmt->_M_use_grouping && !__testdec)
+ {
+ // NB: Thousands separator at the beginning of a string
+ // is a no-no, as is two consecutive thousands
+ // separators, as is thousands separator to the right of
+ // a decimal point.
+ if (__sep_pos && !__testdec)
+ {
+ __grp += static_cast<char>(__sep_pos);
+ __sep_pos = 0;
+ __valid = true;
+ }
+ else
+ __err |= ios_base::failbit;
+ }
+ else if (__c == __fmt->_M_decimal_point
+ && __fp && !__testdec)
+ {
+ __xtrc[__pos] = '.';
+ ++__pos;
+ if (__fmt->_M_use_grouping && !__grp.empty())
+ {
+ __grp += static_cast<char>(__sep_pos);
+ __sep_pos = 0;
+ }
+ __testdec = true;
+ __valid = true;
+ }
+ if (__valid)
+ ++__beg;
+ }
+ __xtrc[__pos] = '\0';
+ if (__beg == __end)
+ __err |= ios_base::eofbit;
+
+ // Digit grouping is checked. If _M_groupings() doesn't
+ // match, then get very very upset, and set failbit.
+ if (__fmt->_M_use_grouping && !__grp.empty())
+ {
+ // Add the ending grouping if the decimal point hasn't
+ // already delineated the end of the sequence that grouping
+ // cares about.
+ if (!__testdec)
+ __grp += static_cast<char>(__sep_pos);
+
+ // __grp is parsed L to R
+ // 1,222,444 == __grp of "/1/3/3"
+ // __fmt->_M_grouping is parsed R to L
+ // 1,222,444 == __fmt->_M_grouping of "/3" == "/3/3/3"
+ int __i = 0;
+ int __j = 0;
+ const int __len = __fmt->_M_grouping.size();
+ int __n = __grp.size();
+ bool __test = true;
+
+ // Parsed number groupings have to match the
+ // numpunct::grouping string exactly, starting at the
+ // right-most point of the parsed sequence of elements ...
+ while (__test && __i < __n - 1)
+ for (__j = 0; __test && __j < __len && __i < __n - 1; ++__j, ++__i)
+ __test &= __fmt->_M_grouping[__j] == __grp[__n - __i - 1];
+ // ... but the last parsed grouping can be <= numpunct
+ // grouping.
+ __j == __len ? __j = 0 : __j;
+ __test &= __fmt->_M_grouping[__j] >= __grp[__n - __i - 1];
+
+ if (!__test)
+ __err |= ios_base::failbit;
+ }
+ }
+
+ // NB: This is an unresolved library defect #17
+ // _GLIBCPP_RESOLVE_LIB_DEFECTS
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, bool& __v) const
+ {
+ // Parse bool values as long
+ if (!(__io.flags() & ios_base::boolalpha))
+ {
+ // NB: We can't just call do_get(long) here, as it might
+ // refer to a derived class.
+
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 32 for
+ // integral types.
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, false);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ long __l = strtol(__xtrc, &__sanity, __base);
+ if (!(__err & ios_base::failbit)
+ && __l <= 1
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0)
+ __v = __l;
+ else
+ __err |= ios_base::failbit;
+ }
+
+ // Parse bool values as alphanumeric
+ else
+ {
+ typedef _Format_cache<char_type> __fcache_type;
+ __fcache_type* __fmt = __fcache_type::_S_get(__io);
+ const char_type* __true = __fmt->_M_truename.c_str();
+ const char_type* __false = __fmt->_M_falsename.c_str();
+ const size_t __truelen = __traits_type::length(__true) - 1;
+ const size_t __falselen = __traits_type::length(__false) - 1;
+
+ for (size_t __pos = 0; __beg != __end; ++__pos)
+ {
+ char_type __c = *__beg++;
+ bool __testf = __c == __false[__pos];
+ bool __testt = __c == __true[__pos];
+ if (!(__testf || __testt))
+ {
+ __err |= ios_base::failbit;
+ break;
+ }
+ else if (__testf && __pos == __falselen)
+ {
+ __v = 0;
+ break;
+ }
+ else if (__testt && __pos == __truelen)
+ {
+ __v = 1;
+ break;
+ }
+ }
+ if (__beg == __end)
+ __err |= ios_base::eofbit;
+ }
+
+ return __beg;
+ }
+
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, short& __v) const
+ {
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 32 for
+ // integral types.
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, false);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ long __l = strtol(__xtrc, &__sanity, __base);
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0
+ && __l >= SHRT_MIN && __l <= SHRT_MAX)
+ __v = static_cast<short>(__l);
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, int& __v) const
+ {
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 32 for
+ // integral types.
+ char __xtrc[32] = {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, false);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ long __l = strtol(__xtrc, &__sanity, __base);
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0
+ && __l >= INT_MIN && __l <= INT_MAX)
+ __v = static_cast<int>(__l);
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+#endif
+
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, long& __v) const
+ {
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 32 for
+ // integral types.
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, false);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ long __l = strtol(__xtrc, &__sanity, __base);
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0)
+ __v = __l;
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, long long& __v) const
+ {
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 32 for
+ // integral types.
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, false);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ long long __ll = strtoll(__xtrc, &__sanity, __base);
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0)
+ __v = __ll;
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+#endif
+
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, unsigned short& __v) const
+ {
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 32 for
+ // integral types.
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, false);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ unsigned long __ul = strtoul(__xtrc, &__sanity, __base);
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0
+ && __ul <= USHRT_MAX)
+ __v = static_cast<unsigned short>(__ul);
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, unsigned int& __v) const
+ {
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 32 for
+ // integral types.
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, false);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ unsigned long __ul = strtoul(__xtrc, &__sanity, __base);
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0
+ && __ul <= UINT_MAX)
+ __v = static_cast<unsigned int>(__ul);
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, unsigned long& __v) const
+ {
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 32 for
+ // integral types.
+ char __xtrc[32] = {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, false);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ unsigned long __ul = strtoul(__xtrc, &__sanity, __base);
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0)
+ __v = __ul;
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, unsigned long long& __v) const
+ {
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 32 for
+ // integral types.
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, false);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ unsigned long long __ull = strtoull(__xtrc, &__sanity, __base);
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0)
+ __v = __ull;
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+#endif
+
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, float& __v) const
+ {
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 256 for
+ // floating-point types.
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, true);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+#ifdef _GLIBCPP_HAVE_STRTOF
+ float __f = strtof(__xtrc, &__sanity);
+#else
+ float __f = static_cast<float>(strtod(__xtrc, &__sanity));
+#endif
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0)
+ __v = __f;
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, double& __v) const
+ {
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 256 for
+ // floating-point types.
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, true);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ double __d = strtod(__xtrc, &__sanity);
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0)
+ __v = __d;
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+
+#if defined(_GLIBCPP_HAVE_STRTOLD) && !defined(__hpux)
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, long double& __v) const
+ {
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 256 for
+ // floating-point types.
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, true);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ long double __ld = strtold(__xtrc, &__sanity);
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0)
+ __v = __ld;
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+#else
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, long double& __v) const
+ {
+ // Stage 1: extract
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, true);
+
+ // Stage 2: determine a conversion specifier.
+ ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield;
+ const char* __conv;
+ if (__basefield == ios_base::oct)
+ __conv = "%Lo";
+ else if (__basefield == ios_base::hex)
+ __conv = "%LX";
+ else if (__basefield == 0)
+ __conv = "%Li";
+ else
+ __conv = "%Lg";
+
+ // Stage 3: store results.
+ long double __ld;
+ int __p = sscanf(__xtrc, __conv, &__ld);
+ if (__p
+ && static_cast<__traits_type::int_type>(__p) != __traits_type::eof())
+ __v = __ld;
+ else
+ __err |= ios_base::failbit;
+
+ return __beg;
+ }
+#endif
+
+ template<typename _CharT, typename _InIter>
+ _InIter
+ num_get<_CharT, _InIter>::
+ do_get(iter_type __beg, iter_type __end, ios_base& __io,
+ ios_base::iostate& __err, void*& __v) const
+ {
+ // Prepare for hex formatted input
+ typedef ios_base::fmtflags fmtflags;
+ fmtflags __fmt = __io.flags();
+ fmtflags __fmtmask = ~(ios_base::showpos | ios_base::basefield
+ | ios_base::uppercase | ios_base::internal);
+ __io.flags(__fmt & __fmtmask | (ios_base::hex | ios_base::showbase));
+
+ // Stage 1: extract and determine the conversion specifier.
+ // Assuming leading zeros eliminated, thus the size of 32 for
+ // integral types.
+ char __xtrc[32]= {'\0'};
+ int __base;
+ _M_extract(__beg, __end, __io, __err, __xtrc, __base, false);
+
+ // Stage 2: convert and store results.
+ char* __sanity;
+ errno = 0;
+ void* __vp = reinterpret_cast<void*>(strtoul(__xtrc, &__sanity, __base));
+ if (!(__err & ios_base::failbit)
+ && __sanity != __xtrc && *__sanity == '\0' && errno == 0)
+ __v = __vp;
+ else
+ __err |= ios_base::failbit;
+
+ // Reset from hex formatted input
+ __io.flags(__fmt);
+ return __beg;
+ }
+
+ template <typename _CharT, typename _OutIter>
+ locale::id num_put<_CharT, _OutIter>::id;
+
+ // _S_fill is specialized for ostreambuf_iterator, random access iterator.
+ template <typename _CharT, typename _OutIter>
+ inline _OutIter
+ _S_fill(_OutIter __s, _CharT __fill, int __padding);
+
+ template <typename _CharT, typename _RaIter>
+ _RaIter
+ _S_fill(_RaIter __s, _CharT __fill, int __padding,
+ random_access_iterator_tag)
+ {
+ fill_n(__s, __fill);
+ return __s + __padding;
+ }
+
+ template <typename _CharT, typename _OutIter, typename _Tag>
+ _OutIter
+ _S_fill(_OutIter __s, _CharT __fill, int __padding, _Tag)
+ {
+ while (--__padding >= 0) { *__s = __fill; ++__s; }
+ return __s;
+ }
+
+ template <typename _CharT, typename _OutIter>
+ inline _OutIter
+ _S_fill(_OutIter __s, _CharT __fill, int __padding)
+ {
+ return _S_fill(__s, __fill, __padding,
+ iterator_traits<_OutIter>::iterator_category());
+ }
+
+ template <typename _CharT, typename _OutIter>
+ _OutIter
+ _S_pad_numeric(_OutIter __s, ios_base::fmtflags __flags,
+ _CharT __fill, int __width, _CharT const* __first,
+ _CharT const* __middle, _CharT const* __last)
+ {
+ int __padding = __width - (__last - __first);
+ if (__padding < 0)
+ __padding = 0;
+ ios_base::fmtflags __aflags = __flags & ios_base::adjustfield;
+ bool __testfield = __padding == 0 || __aflags == ios_base::left
+ || __aflags == ios_base::internal;
+
+ // This was needlessly complicated.
+ if (__first != __middle)
+ {
+ if (!__testfield)
+ {
+ _S_fill(__s, __fill, __padding);
+ __padding = 0;
+ }
+ copy(__first, __middle, __s);
+ }
+ _OutIter __s2 = __s;
+
+ if (__padding && __aflags != ios_base::left)
+ {
+ _S_fill(__s2, __fill, __padding);
+ __padding = 0;
+ }
+ _OutIter __s3 = copy(__middle, __last, __s2);
+ if (__padding)
+ _S_fill(__s3, __fill, __padding);
+ return __s3;
+ }
+
+ template <typename _CharT, typename _OutIter>
+ _OutIter
+ num_put<_CharT, _OutIter>::
+ do_put(iter_type __s, ios_base& __io, char_type __fill, bool __v) const
+ {
+ const _Format_cache<_CharT>* __fmt = _Format_cache<_CharT>::_S_get(__io);
+ ios_base::fmtflags __flags = __io.flags();
+
+ if ((__flags & ios_base::boolalpha) == 0)
+ {
+ unsigned long __uv = __v;
+ return _S_format(__s, __io, __fill, false, __uv);
+ }
+ else
+ {
+ const char_type* __first;
+ const char_type* __last;
+ if (__v)
+ {
+ __first = __fmt->_M_truename.data();
+ __last = __first + __fmt->_M_truename.size();
+ }
+ else
+ {
+ __first = __fmt->_M_falsename.data();
+ __last = __first + __fmt->_M_falsename.size();
+ }
+ copy(__first, __last, __s);
+ }
+ return __s;
+ }
+
+ // _S_group_digits inserts "group separator" characters into an array
+ // of characters. It's recursive, one iteration per group. It moves
+ // the characters in the buffer this way: "xxxx12345" -> "12,345xxx".
+ // Call this only with __grouping != __grend.
+ template <typename _CharT>
+ _CharT*
+ _S_group_digits(_CharT* __s, _CharT __grsep, char const* __grouping,
+ char const* __grend, _CharT const* __first,
+ _CharT const* __last)
+ {
+ if (__last - __first > *__grouping)
+ {
+ __s = _S_group_digits(__s, __grsep,
+ (__grouping + 1 == __grend ? __grouping : __grouping + 1),
+ __grend, __first, __last - *__grouping);
+ __first = __last - *__grouping;
+ *__s++ = __grsep;
+ }
+ do
+ {
+ *__s++ = *__first++;
+ }
+ while (__first != __last);
+ return __s;
+ }
+
+ template <typename _CharT, typename _OutIter, typename _ValueT>
+ _OutIter
+ _S_format(_OutIter __s, ios_base& __io, _CharT __fill, bool __neg,
+ _ValueT __v)
+ {
+ // Leave room for "+/-," "0x," and commas.
+ const long _M_room = numeric_limits<_ValueT>::digits10 * 2 + 4;
+ _CharT __digits[_M_room];
+ _CharT* __front = __digits + _M_room;
+ ios_base::fmtflags __flags = __io.flags();
+ const _Format_cache<_CharT>* __fmt = _Format_cache<_CharT>::_S_get(__io);
+ char const* __table = __fmt->_S_literals + __fmt->_S_digits;
+
+ ios_base::fmtflags __basefield = (__flags & __io.basefield);
+ _CharT* __sign_end = __front;
+ if (__basefield == ios_base::hex)
+ {
+ if (__flags & ios_base::uppercase)
+ __table += 16; // use ABCDEF
+ do
+ *--__front = __table[__v & 15];
+ while ((__v >>= 4) != 0);
+ __sign_end = __front;
+ if (__flags & ios_base::showbase)
+ {
+ *--__front = __fmt->_S_literals[__fmt->_S_ecks +
+ ((__flags & ios_base::uppercase) ? 1 : 0)];
+ *--__front = __table[0];
+ }
+ }
+ else if (__basefield == ios_base::oct)
+ {
+ do
+ *--__front = __table[__v & 7];
+ while ((__v >>= 3) != 0);
+ if (__flags & ios_base::showbase
+ && static_cast<char>(*__front) != __table[0])
+ *--__front = __table[0];
+ __sign_end = __front;
+ }
+ else
+ {
+ // NB: This is _lots_ faster than using ldiv.
+ do
+ *--__front = __table[__v % 10];
+ while ((__v /= 10) != 0);
+ __sign_end = __front;
+ // NB: ios_base:hex || ios_base::oct assumed to be unsigned.
+ if (__neg || (__flags & ios_base::showpos))
+ *--__front = __fmt->_S_literals[__fmt->_S_plus - __neg];
+ }
+
+ // XXX should specialize!
+ if (!__fmt->_M_use_grouping && !__io.width())
+ return copy(__front, __digits + _M_room, __s);
+
+ if (!__fmt->_M_use_grouping)
+ return _S_pad_numeric(__s, __flags, __fill, __io.width(0),
+ __front, __sign_end, __digits + _M_room);
+
+ _CharT* __p = __digits;
+ while (__front < __sign_end)
+ *__p++ = *__front++;
+ const char* __gr = __fmt->_M_grouping.data();
+ __front = _S_group_digits(__p, __fmt->_M_thousands_sep, __gr,
+ __gr + __fmt->_M_grouping.size(), __sign_end, __digits + _M_room);
+ return _S_pad_numeric(__s, __flags, __fill, __io.width(0),
+ __digits, __p, __front);
+ }
+
+ template <typename _CharT, typename _OutIter>
+ _OutIter
+ num_put<_CharT, _OutIter>::
+ do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const
+ {
+ unsigned long __uv = __v;
+ bool __neg = false;
+ if (__v < 0)
+ {
+ __neg = true;
+ __uv = -__uv;
+ }
+ return _S_format(__s, __io, __fill, __neg, __uv);
+ }
+
+ template <typename _CharT, typename _OutIter>
+ _OutIter
+ num_put<_CharT, _OutIter>::
+ do_put(iter_type __s, ios_base& __io, char_type __fill,
+ unsigned long __v) const
+ { return _S_format(__s, __io, __fill, false, __v); }
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ template <typename _CharT, typename _OutIter>
+ _OutIter
+ num_put<_CharT, _OutIter>::
+ do_put(iter_type __s, ios_base& __b, char_type __fill, long long __v) const
+ {
+ unsigned long long __uv = __v;
+ bool __neg = false;
+ if (__v < 0)
+ {
+ __neg = true;
+ __uv = -__uv;
+ }
+ return _S_format(__s, __b, __fill, __neg, __uv);
+ }
+
+ template <typename _CharT, typename _OutIter>
+ _OutIter
+ num_put<_CharT, _OutIter>::
+ do_put(iter_type __s, ios_base& __io, char_type __fill,
+ unsigned long long __v) const
+ { return _S_format(__s, __io, __fill, false, __v); }
+#endif
+
+ // The following code uses sprintf() to convert floating point
+ // values for insertion into a stream. The current implementation
+ // replicates the code in _S_pad_numeric() (in _S_output_float()) in
+ // order to prevent having to create a "wide" buffer in addition to
+ // the "narrow" buffer passed to sprintf(). An optimization would be
+ // to replace sprintf() with code that works directly on a wide
+ // buffer and then use _S_pad_numeric() to do the padding. It would
+ // be good to replace sprintf() anyway to avoid accidental buffer
+ // overruns and to gain back the efficiency that C++ provides by
+ // knowing up front the type of the values to insert. This
+ // implementation follows the C++ standard fairly directly as
+ // outlined in 22.2.2.2 [lib.locale.num.put]
+ bool
+ _S_build_float_format(ios_base& __io, char* __fptr, char __modifier,
+ streamsize __prec)
+ {
+ bool __incl_prec = false;
+ ios_base::fmtflags __flags = __io.flags();
+ *__fptr++ = '%';
+ // [22.2.2.2.2] Table 60
+ if (__flags & ios_base::showpos)
+ *__fptr++ = '+';
+ if (__flags & ios_base::showpoint)
+ *__fptr++ = '#';
+ // As per [22.2.2.2.2.11]
+ if (__flags & ios_base::fixed || __prec > 0)
+ {
+ *__fptr++ = '.';
+ *__fptr++ = '*';
+ __incl_prec = true;
+ }
+ if (__modifier)
+ *__fptr++ = __modifier;
+ ios_base::fmtflags __fltfield = __flags & ios_base::floatfield;
+ // [22.2.2.2.2] Table 58
+ if (__fltfield == ios_base::fixed)
+ *__fptr++ = 'f';
+ else if (__fltfield == ios_base::scientific)
+ *__fptr++ = (__flags & ios_base::uppercase) ? 'E' : 'e';
+ else
+ *__fptr++ = (__flags & ios_base::uppercase) ? 'G' : 'g';
+ *__fptr = '\0';
+ return __incl_prec;
+ }
+
+ template<typename _CharT,typename _OutIter>
+ _OutIter
+ _S_output_float(_OutIter __s, ios_base& __io,_CharT __fill,
+ const char* __sptr, size_t __slen)
+ {
+ size_t __padding = __io.width() > streamsize(__slen) ?
+ __io.width() -__slen : 0;
+ locale __loc = __io.getloc();
+ ctype<_CharT> const& __ct = use_facet<ctype<_CharT> >(__loc);
+ ios_base::fmtflags __adjfield = __io.flags() & ios_base::adjustfield;
+ const char* const __eptr = __sptr + __slen;
+ // [22.2.2.2.2.19] Table 61
+ if (__adjfield == ios_base::internal)
+ {
+ // [22.2.2.2.2.14]; widen()
+ if (__sptr < __eptr && (*__sptr == '+' || *__sptr == '-'))
+ {
+ __s = __ct.widen(*__sptr);
+ ++__s;
+ ++__sptr;
+ }
+ __s = _S_fill(__s, __fill, __padding);
+ __padding = 0;
+ }
+ else if (__adjfield != ios_base::left)
+ {
+ __s = _S_fill(__s, __fill, __padding);
+ __padding = 0;
+ }
+ // the "C" locale decimal character
+ char __decimal_point = *(localeconv()->decimal_point);
+ const _Format_cache<_CharT>* __fmt = _Format_cache<_CharT>::_S_get(__io);
+ for (; __sptr != __eptr; ++__s, ++__sptr)
+ {
+ // [22.2.2.2.2.17]; decimal point conversion
+ if (*__sptr == __decimal_point)
+ __s = __fmt->_M_decimal_point;
+ // [22.2.2.2.2.14]; widen()
+ else
+ __s = __ct.widen(*__sptr);
+ }
+ // [22.2.2.2.2.19] Table 61
+ if (__padding)
+ _S_fill(__s, __fill, __padding);
+ __io.width(0);
+ return __s;
+ }
+
+ template <typename _CharT, typename _OutIter>
+ _OutIter
+ num_put<_CharT, _OutIter>::
+ do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const
+ {
+ const streamsize __max_prec = numeric_limits<double>::digits10 + 3;
+ streamsize __prec = __io.precision();
+ // Protect against sprintf() buffer overflows.
+ if (__prec > __max_prec)
+ __prec = __max_prec;
+ // The *2 provides for signs, exp, 'E', and pad.
+ char __sbuf[__max_prec*2];
+ size_t __slen;
+ // Long enough for the max format spec.
+ char __fbuf[16];
+ if (_S_build_float_format(__io, __fbuf, 0, __prec))
+ __slen = sprintf(__sbuf, __fbuf, __prec, __v);
+ else
+ __slen = sprintf(__sbuf, __fbuf, __v);
+ // [22.2.2.2.2] Stages 2-4.
+ return _S_output_float(__s, __io, __fill, __sbuf, __slen);
+ }
+
+ template <typename _CharT, typename _OutIter>
+ _OutIter
+ num_put<_CharT, _OutIter>::
+ do_put(iter_type __s, ios_base& __io, char_type __fill,
+ long double __v) const
+ {
+ const streamsize __max_prec = numeric_limits<long double>::digits10 + 3;
+ streamsize __prec = __io.precision();
+ // Protect against sprintf() buffer overflows.
+ if (__prec > __max_prec)
+ __prec = __max_prec;
+ // The *2 provides for signs, exp, 'E', and pad.
+ char __sbuf[__max_prec*2];
+ size_t __slen;
+ // Long enough for the max format spec.
+ char __fbuf[16];
+ // 'L' as per [22.2.2.2.2] Table 59
+ if ( _S_build_float_format(__io, __fbuf, 'L', __prec))
+ __slen = sprintf(__sbuf, __fbuf, __prec, __v);
+ else
+ __slen = sprintf(__sbuf, __fbuf, __v);
+ // [22.2.2.2.2] Stages 2-4
+ return _S_output_float(__s, __io, __fill, __sbuf, __slen);
+ }
+
+ template <typename _CharT, typename _OutIter>
+ _OutIter
+ num_put<_CharT, _OutIter>::
+ do_put(iter_type __s, ios_base& __io, char_type __fill,
+ const void* __v) const
+ {
+ typedef ios_base::fmtflags fmtflags;
+ fmtflags __fmt = __io.flags();
+ fmtflags __fmtmask = ~(ios_base::showpos | ios_base::basefield
+ | ios_base::uppercase | ios_base::internal);
+ __io.flags(__fmt & __fmtmask | (ios_base::hex | ios_base::showbase));
+ try {
+ _OutIter __s2 = _S_format(__s, __io, __fill, false,
+ reinterpret_cast<unsigned long>(__v));
+ __io.flags(__fmt);
+ return __s2;
+ }
+ catch (...) {
+ __io.flags(__fmt);
+ throw;
+ }
+ }
+
+ template<typename _CharT>
+ locale::id numpunct<_CharT>::id;
+
+ template<typename _CharT>
+ locale::id collate<_CharT>::id;
+
+ // Support for time_get:
+ // Note that these partial specializations could, and maybe should,
+ // be changed to full specializations (by eliminating the _Dummy
+ // argument) and moved to a .cc file.
+ template<typename _CharT, typename _Dummy = int>
+ struct _Weekdaynames;
+
+ template<typename _Dummy>
+ struct _Weekdaynames<char, _Dummy>
+ { static const char* const _S_names[14]; };
+
+ template<typename _Dummy>
+ const char* const
+ _Weekdaynames<char,_Dummy>::_S_names[14] =
+ {
+ "Sun", "Sunday",
+ "Mon", "Monday", "Tue", "Tuesday", "Wed", "Wednesday",
+ "Thu", "Thursday", "Fri", "Friday", "Sat", "Saturday"
+ };
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<typename _Dummy>
+ struct _Weekdaynames<wchar_t,_Dummy>
+ { static const wchar_t* const _S_names[14]; };
+
+ template<typename _Dummy>
+ const wchar_t* const
+ _Weekdaynames<wchar_t,_Dummy>::_S_names[14] =
+ {
+ L"Sun", L"Sunday",
+ L"Mon", L"Monday", L"Tue", L"Tuesday", L"Wed", L"Wednesday",
+ L"Thu", L"Thursday", L"Fri", L"Friday", L"Sat", L"Saturday"
+ };
+#endif
+
+ template<typename _CharT, typename _Dummy = int>
+ struct _Monthnames;
+
+ template<typename _Dummy>
+ struct _Monthnames<char,_Dummy>
+ { static const char* const _S_names[24]; };
+
+ template<typename _Dummy>
+ const char* const
+ _Monthnames<char,_Dummy>::_S_names[24] =
+ {
+ "Jan", "January", "Feb", "February", "Mar", "March",
+ "Apr", "April", "May", "May", "Jun", "June",
+ "Jul", "July", "Aug", "August", "Sep", "September",
+ "Oct", "October", "Nov", "November", "Dec", "December"
+ };
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<typename _Dummy>
+ struct _Monthnames<wchar_t, _Dummy>
+ { static const wchar_t* const _S_names[24]; };
+
+ template<typename _Dummy>
+ const wchar_t* const
+ _Monthnames<wchar_t,_Dummy>::_S_names[24] =
+ {
+ L"Jan", L"January", L"Feb", L"February", L"Mar", L"March",
+ L"Apr", L"April", L"May", L"May", L"Jun", L"June",
+ L"Jul", L"July", L"Aug", L"August", L"Sep", L"September",
+ L"Oct", L"October", L"Nov", L"November", L"Dec", L"December"
+ };
+#endif
+
+ template<typename _CharT, typename _InIter>
+ locale::id time_get<_CharT, _InIter>::id;
+
+ template<typename _CharT, typename _InIter>
+ _InIter
+ time_get<_CharT, _InIter>::
+ do_get_weekday(iter_type __s, iter_type __end,
+ ios_base& __io, ios_base::iostate& __err, tm* __t) const
+ {
+ if (!_M_daynames)
+ {
+ _M_daynames = new basic_string<_CharT>[14];
+ for (int __i = 0; __i < 14; ++__i)
+ _M_daynames[__i] = _Weekdaynames<_CharT>::_S_names[__i];
+ }
+ bool __at_eof = false;
+ int __remain = 0;
+ int __matches[14];
+ iter_type __out = __match_parallel(__s, __end, 14, _M_daynames,
+ __matches, __remain, __at_eof);
+ __err = ios_base::iostate(0);
+ if (__at_eof) __err |= __io.eofbit;
+ if (__remain == 1 ||
+ __remain == 2 && (__matches[0]>>1) == (__matches[1]>>1))
+ __t->tm_wday = (__matches[0]>>1);
+ else
+ __err |= __io.failbit;
+ return __out;
+ }
+
+ template<typename _CharT, typename _InIter>
+ _InIter
+ time_get<_CharT, _InIter>::
+ do_get_monthname(iter_type __s, iter_type __end,
+ ios_base& __io, ios_base::iostate& __err, tm* __t) const
+ {
+ if (!_M_monthnames)
+ {
+ _M_monthnames = new basic_string<_CharT>[24];
+ for (int __i = 0; __i < 24; ++__i)
+ _M_monthnames[__i] = _Monthnames<_CharT>::_S_names[__i];
+ }
+ bool __at_eof = false;
+ int __remain = 0;
+ int __matches[24];
+ iter_type __out = __match_parallel( __s, __end, 24, _M_monthnames,
+ __matches, __remain, __at_eof);
+ __err = ios_base::iostate(0);
+ if (__at_eof) __err |= __io.eofbit;
+ if (__remain == 1 ||
+ __remain == 2 && (__matches[0]>>1) == (__matches[1]>>1))
+ __t->tm_mon = (__matches[0]>>1);
+ else
+ __err |= __io.failbit;
+ return __out;
+ }
+
+ template<typename _CharT, typename _OutIter>
+ locale::id time_put<_CharT, _OutIter>::id;
+
+ template<typename _CharT, typename _InIter>
+ locale::id money_get<_CharT, _InIter>::id;
+
+ template<typename _CharT, typename _OutIter>
+ locale::id money_put<_CharT, _OutIter>::id;
+
+ template<typename _CharT, bool _Intl>
+ locale::id moneypunct<_CharT,_Intl>::id;
+
+ template<typename _CharT>
+ locale::id messages<_CharT>::id;
+
+ template<>
+ const ctype<char>&
+ use_facet<const ctype<char> > (const locale& __loc)
+ {
+ size_t __i = ctype<char>::id._M_index;
+ const locale::_Impl* __tmp = __loc._M_impl;
+ return static_cast<const ctype<char>&>(* (*(__tmp->_M_facets))[__i]);
+ }
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ const ctype<wchar_t>&
+ use_facet< const ctype<wchar_t> > (const locale& __loc)
+ {
+ size_t __i = ctype<wchar_t>::id._M_index;
+ const locale::_Impl* __tmp = __loc._M_impl;
+ return static_cast<const ctype<wchar_t>&>(* (*(__tmp->_M_facets))[__i]);
+ }
+#endif
+
+} // std::
+
+#endif /* _CPP_BITS_LOCFACETS_TCC */
+
+// Local Variables:
+// mode:c++
+// End:
+
+
+
+
+
diff --git a/libstdc++-v3/bits/localefwd.h b/libstdc++-v3/bits/localefwd.h
new file mode 100644
index 0000000..7f12457
--- /dev/null
+++ b/libstdc++-v3/bits/localefwd.h
@@ -0,0 +1,497 @@
+// Locale support -*- C++ -*-
+
+// Copyright (C) 1997-2000 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 22.1 Locales
+//
+
+#ifndef _CPP_BITS_LOCCORE_H
+#define _CPP_BITS_LOCCORE_H 1
+
+#include <bits/c++config.h>
+#include <bits/std_climits.h> // For CHAR_BIT
+#include <bits/std_string.h> // For string
+#include <bits/std_cctype.h> // For isspace, etc.
+
+namespace std
+{
+
+ // _Count_ones: compile-time computation of number of 1-bits in a value N
+ // This takes only 5 (or 6) instantiations, doing recursive descent
+ // in parallel -- ncm
+ template<unsigned _Num, int _Shift = (sizeof(unsigned) * CHAR_BIT)/2,
+ unsigned _Mask = (~0u >> _Shift) >
+ struct _Count_ones;
+
+ template<unsigned _Num, unsigned _Mask>
+ struct _Count_ones<_Num,0,_Mask>
+ { static const unsigned _S_count = _Num; };
+
+ template<unsigned _Num, int _Shift, unsigned _Mask>
+ struct _Count_ones
+ {
+ static const unsigned _S_halfcount =
+ _Count_ones<_Num, _Shift/2, (_Mask^((~_Mask)>>(_Shift/2))) >::_S_count;
+ static const unsigned _S_count
+ = (_S_halfcount&_Mask) + ((_S_halfcount>>_Shift)&_Mask);
+ };
+
+ // 22.1.1 Locale
+ template<typename _Tp> class allocator;
+ template<typename _Tp, typename _Alloc> class vector;
+ class locale;
+
+ template<typename _Facet>
+ const _Facet&
+ use_facet(const locale&);
+
+ template<typename _Facet>
+ bool
+ has_facet(const locale&) throw();
+
+ // 22.1.3 Convenience interfaces
+ template<typename _CharT>
+ inline bool
+ isspace(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline bool
+ isprint(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline bool
+ iscntrl(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline bool
+ isupper(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline bool
+ islower(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline bool
+ isalpha(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline bool
+ isdigit(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline bool
+ ispunct(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline bool
+ isxdigit(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline bool
+ isalnum(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline bool
+ isgraph(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline _CharT
+ toupper(_CharT, const locale&);
+
+ template<typename _CharT>
+ inline _CharT
+ tolower(_CharT, const locale&);
+
+
+ // 22.2.1 and 22.2.1.3 ctype
+ class ctype_base;
+ template<typename _CharT>
+ class ctype;
+ template<> class ctype<char>;
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<> class ctype<wchar_t>;
+#endif
+
+ template<typename _CharT>
+ class ctype_byname;
+ // NB: Specialized for char and wchar_t in locfacets.h.
+
+ class codecvt_base;
+ template<typename _InternT, typename _ExternT, typename _StateT>
+ class codecvt;
+ template<> class codecvt<char, char, mbstate_t>;
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<> class codecvt<wchar_t, char, mbstate_t>;
+#endif
+
+ template<typename _InternT, typename _ExternT, typename _StateT>
+ class codecvt_byname;
+ template<> class codecvt_byname<char, char, mbstate_t>;
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<> class codecvt_byname<wchar_t, char, mbstate_t>;
+#endif
+
+ // 22.2.2 and 22.2.3 numeric
+ template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
+ class num_get;
+ template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
+ class num_put;
+ template<typename _CharT> class numpunct;
+ template<typename _CharT> class numpunct_byname;
+
+ // 22.2.4 collation
+ template<typename _CharT>
+ class collate;
+ template<> class collate<char>;
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<> class collate<wchar_t>;
+#endif
+ template<typename _CharT> class
+ collate_byname;
+
+ // 22.2.5 date and time
+ class time_base;
+ template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
+ class time_get;
+ template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
+ class time_get_byname;
+ template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
+ class time_put;
+ template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
+ class time_put_byname;
+
+ // 22.2.6 money
+ class money_base;
+ template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> >
+ class money_get;
+ template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> >
+ class money_put;
+ template<typename _CharT, bool _Intl = false>
+ class moneypunct;
+ template<typename _CharT, bool _Intl = false>
+ class moneypunct_byname;
+
+ // 22.2.7 message retrieval
+ class messages_base;
+ template<typename _CharT>
+ class messages;
+ template<typename _CharT>
+ class messages_byname;
+
+
+ // 22.1.1 Class locale
+ class locale
+ {
+ // Forwrd decls and friends:
+ class _Impl;
+ friend _Impl;
+
+ template<typename _Facet>
+ friend const _Facet&
+ use_facet(const locale&);
+
+ template<typename _Facet>
+ friend bool
+ has_facet(const locale&) throw();
+
+ public:
+ // Types:
+ class facet;
+ class id;
+ typedef int category;
+
+ // Category values:
+ // NB much depends on the order in which these appear:
+ static const category none = 0;
+ static const category collate = 0x0100;
+ static const category ctype = 0x0200;
+ static const category monetary = 0x0400;
+ static const category numeric = 0x0800;
+ static const category time = 0x1000;
+ static const category messages = 0x2000;
+ static const category all = (collate | ctype | monetary |
+ numeric | time | messages);
+
+ // Construct/copy/destroy:
+ inline
+ locale() throw();
+
+ inline
+ locale(const locale& __other) throw();
+
+ explicit
+ locale(const char* __std_name);
+
+ locale(const locale& __other, const char* __std_name, category __cats);
+
+ locale(const locale& __other, const locale& __one, category __cats);
+
+ template<typename _Facet>
+ locale(const locale& __other, _Facet* __f);
+
+ inline
+ ~locale() throw();
+
+ const locale&
+ operator=(const locale& __other) throw();
+
+ template<typename _Facet>
+ locale
+ combine(const locale& __other);
+
+ // Locale operations:
+ string
+ name() const;
+
+ bool
+ operator==(const locale& __other) const throw ();
+
+ inline bool
+ operator!=(const locale& __other) const throw ()
+ { return !(operator==(__other)); }
+
+ template<typename _Char, typename _Traits, typename _Alloc>
+ bool
+ operator()(const basic_string<_Char,_Traits,_Alloc>& __s1,
+ const basic_string<_Char,_Traits,_Alloc>& __s2) const;
+
+ // Global locale objects:
+ static locale
+ global(const locale&);
+
+ static const locale&
+ classic();
+
+ private:
+ _Impl* _M_impl; // The (shared) implementation
+
+ static _Impl* _S_classic; // The one true C reference locale
+ static _Impl* _S_global; // Current global reference locale
+
+ explicit
+ locale(_Impl*) throw();
+
+ static inline void
+ _S_initialize()
+ { if (!_S_classic) classic(); }
+
+ static int
+ _S_normalize_category(int);
+
+ static const int
+ _S_num_categories = _Count_ones<all>::_S_count;
+ };
+
+
+ // locale implementation object
+ class locale::_Impl
+ {
+ typedef vector<facet*, allocator<facet*> > __vec_facet;
+ typedef vector<string, allocator<string> > __vec_string;
+
+ // Friends:
+ friend class locale;
+ friend class facet;
+
+ template<typename _Facet>
+ friend const _Facet&
+ use_facet(const locale&);
+
+ template<typename _Facet>
+ friend bool
+ has_facet(const locale&) throw();
+
+ size_t _M_num_references;
+ __vec_facet* _M_facets;
+ __vec_string* _M_category_names;
+ bool _M_has_name;
+ bool _M_cached_name_ok;
+ string _M_cached_name;
+
+ inline void
+ _M_add_reference() throw()
+ { ++_M_num_references; } // XXX MT
+
+ inline void
+ _M_remove_reference() throw()
+ {
+ if (_M_num_references-- == 0) // XXX MT
+ {
+ try {
+ delete this;
+ }
+ catch(...) {
+ }
+ }
+ }
+
+ _Impl(const _Impl&, size_t __refs);
+ _Impl(const _Impl&, const string&, category, size_t __refs);
+ _Impl(size_t __facets, size_t __refs);
+ ~_Impl() throw();
+
+ void
+ _M_replace_categories(const _Impl*, category);
+
+ void
+ _M_replace_category(const _Impl*, const locale::id* const*);
+
+ void
+ _M_replace_facet(const _Impl*, const locale::id*);
+
+ void
+ _M_install_facet(const locale::id*, facet*);
+
+ template<typename _Facet>
+ inline void
+ _M_init_facet(_Facet* __facet)
+ { _M_install_facet(&_Facet::id, __facet); }
+
+ void
+ _M_construct_collate(const char*);
+
+ void
+ _M_construct_ctype(const char*);
+
+ void
+ _M_construct_monetary(const char*);
+
+ void
+ _M_construct_numeric(const char*);
+
+ void
+ _M_construct_time(const char*);
+
+ void
+ _M_construct_messages(const char*);
+
+ category
+ _M_normalize_category_names(const string&, category __cats);
+
+ static const locale::id* const _S_id_collate[];
+ static const locale::id* const _S_id_ctype[];
+ static const locale::id* const _S_id_monetary[];
+ static const locale::id* const _S_id_numeric[];
+ static const locale::id* const _S_id_time[];
+ static const locale::id* const _S_id_messages[];
+ static const locale::id* const* const _S_facet_categories[];
+ };
+
+ // class locale inlines, that need declaration of locale::_Imp
+ locale::locale() throw()
+ {
+ _S_initialize();
+ (_M_impl = _S_global)->_M_add_reference();
+ } // XXX MT
+
+ locale::locale(const locale& __other) throw()
+ { (_M_impl = __other._M_impl)->_M_add_reference(); }
+
+ template<typename _Facet>
+ locale::locale(const locale& __other, _Facet* __f)
+ {
+ _M_impl = new _Impl(*__other._M_impl, 0);
+ _M_impl->_M_install_facet(&_Facet::id, __f);
+ _M_impl->_M_has_name = false;
+ }
+
+ locale::~locale() throw()
+ { _M_impl->_M_remove_reference(); }
+
+ // 22.1.1.1.2 Class locale::facet
+ class locale::facet
+ {
+ friend class locale;
+ friend class locale::_Impl;
+
+ protected:
+ explicit
+ facet(size_t __refs = 0) throw();
+
+ virtual
+ ~facet() {};
+
+ private:
+ size_t _M_num_references;
+
+ void
+ _M_add_reference() throw();
+
+ void
+ _M_remove_reference() throw();
+
+ facet(const facet&); // not defined
+
+ void
+ operator=(const facet&); // not defined
+ };
+
+
+ // 22.1.1.1.3 Class locale::id
+ class locale::id
+ {
+ friend class locale;
+ friend class locale::_Impl;
+ template<typename _Facet>
+ friend const _Facet&
+ use_facet(const locale&);
+ template<typename _Facet>
+ friend bool
+ has_facet(const locale&) throw ();
+ public:
+ id() {};
+ private:
+ // NB: there is no accessor for _M_index because it may be used
+ // before the constructor is run; the effect of calling a member
+ // function (even an inline) would be undefined.
+ mutable size_t _M_index;
+ static size_t _S_highwater; // last id number assigned
+
+ void
+ operator=(const id&); // not defined
+
+ id(const id&); // not defined
+ };
+
+ template<typename _Facet>
+ const _Facet&
+ use_facet(const locale& __loc);
+
+ template<typename _Facet>
+ bool
+ has_facet(const locale& __loc) throw();
+
+} // namespace std
+
+#endif /* _CPP_BITS_LOCCORE_H */
+
+// Local Variables:
+// mode:c++
+// End:
+
diff --git a/libstdc++-v3/bits/mask_array.h b/libstdc++-v3/bits/mask_array.h
new file mode 100644
index 0000000..5654a2f
--- /dev/null
+++ b/libstdc++-v3/bits/mask_array.h
@@ -0,0 +1,160 @@
+// The template and inlines for the -*- C++ -*- mask_array class.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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 Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
+
+#ifndef _CPP_BITS_MASK_ARRAY_H
+#define _CPP_BITS_MASK_ARRAY_H 1
+
+namespace std {
+
+ template <class _Tp> class mask_array
+ {
+ public:
+ typedef _Tp value_type;
+
+ void operator= (const valarray<_Tp>&) const;
+ void operator*= (const valarray<_Tp>&) const;
+ void operator/= (const valarray<_Tp>&) const;
+ void operator%= (const valarray<_Tp>&) const;
+ void operator+= (const valarray<_Tp>&) const;
+ void operator-= (const valarray<_Tp>&) const;
+ void operator^= (const valarray<_Tp>&) const;
+ void operator&= (const valarray<_Tp>&) const;
+ void operator|= (const valarray<_Tp>&) const;
+ void operator<<=(const valarray<_Tp>&) const;
+ void operator>>=(const valarray<_Tp>&) const;
+ void operator= (const _Tp&);
+
+ // ~mask_array ();
+
+ template<class _Dom>
+ void operator= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator*= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator/= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator%= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator+= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator-= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator^= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator&= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator|= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator<<=(const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator>>=(const _Expr<_Dom,_Tp>&) const;
+
+ private:
+ mask_array (_Array<_Tp>, size_t, _Array<bool>);
+ friend class valarray<_Tp>;
+
+ const size_t _M_sz;
+ const _Array<bool> _M_mask;
+ const _Array<_Tp> _M_array;
+
+ mask_array (const mask_array&);
+
+ // not implemented
+ mask_array ();
+ mask_array& operator= (const mask_array&);
+ };
+
+
+ template<typename _Tp>
+ inline mask_array<_Tp>::mask_array (const mask_array<_Tp>& a)
+ : _M_sz (a._M_sz), _M_mask (a._M_mask), _M_array (a._M_array) {}
+
+ template<typename _Tp>
+ inline
+ mask_array<_Tp>::mask_array (_Array<_Tp> __a, size_t __s, _Array<bool> __m)
+ : _M_sz (__s), _M_mask (__m), _M_array (__a) {}
+
+ // template<typename _Tp>
+ // inline mask_array<_Tp>::~mask_array () {}
+
+ template<typename _Tp>
+ inline void
+ mask_array<_Tp>::operator= (const _Tp& __t)
+ { __valarray_fill (_M_array, _M_sz, _M_mask, __t); }
+
+ template<typename _Tp>
+ inline void
+ mask_array<_Tp>::operator= (const valarray<_Tp>& __v) const
+ { __valarray_copy (_Array<_Tp> (__v), __v.size (), _M_array, _M_mask); }
+
+ template<typename _Tp>
+ template<class E>
+ inline void
+ mask_array<_Tp>::operator= (const _Expr<E, _Tp>& __e) const
+ { __valarray_copy (__e, __e.size (), _M_array, _M_mask); }
+
+#undef _DEFINE_VALARRAY_OPERATOR
+#define _DEFINE_VALARRAY_OPERATOR(op, name) \
+template<typename _Tp> \
+inline void \
+mask_array<_Tp>::operator##op##= (const valarray<_Tp>& __v) const \
+{ \
+ _Array_augmented_##name (_M_array, _M_mask, \
+ _Array<_Tp> (__v), __v.size ()); \
+} \
+ \
+template<typename _Tp> template<class E> \
+inline void \
+mask_array<_Tp>::operator##op##= (const _Expr<E, _Tp>& __e) const \
+{ \
+ _Array_augmented_##name (_M_array, _M_mask, __e, __e.size ()); \
+}
+
+_DEFINE_VALARRAY_OPERATOR(*, multiplies)
+_DEFINE_VALARRAY_OPERATOR(/, divides)
+_DEFINE_VALARRAY_OPERATOR(%, modulus)
+_DEFINE_VALARRAY_OPERATOR(+, plus)
+_DEFINE_VALARRAY_OPERATOR(-, minus)
+_DEFINE_VALARRAY_OPERATOR(^, xor)
+_DEFINE_VALARRAY_OPERATOR(&, and)
+_DEFINE_VALARRAY_OPERATOR(|, or)
+_DEFINE_VALARRAY_OPERATOR(<<, shift_left)
+_DEFINE_VALARRAY_OPERATOR(>>, shift_right)
+
+#undef _DEFINE_VALARRAY_OPERATOR
+
+} // std::
+
+#endif /* _CPP_BITS_MASK_ARRAY_H */
+
+// Local Variables:
+// mode:c++
+// End:
diff --git a/libstdc++-v3/bits/ostream.tcc b/libstdc++-v3/bits/ostream.tcc
new file mode 100644
index 0000000..2ac7753
--- /dev/null
+++ b/libstdc++-v3/bits/ostream.tcc
@@ -0,0 +1,673 @@
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.6.2 Output streams
+//
+
+#include <bits/std_locale.h>
+
+namespace std {
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>::sentry::
+ sentry(basic_ostream<_CharT,_Traits>& __os)
+ : _M_ok(__os.good()), _M_os(__os)
+ {
+ // XXX MT
+ if (_M_ok && __os.tie())
+ __os.tie()->flush();
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::
+ operator<<(__ostream_type& (*__pf)(__ostream_type&))
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ try {
+ __pf(*this);
+ }
+ catch(exception& __fail){
+ // 27.6.2.5.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::
+ operator<<(__ios_type& (*__pf)(__ios_type&))
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ try {
+ __pf(*this);
+ }
+ catch(exception& __fail){
+ // 27.6.2.5.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::
+ operator<<(ios_base& (*__pf)(ios_base&))
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ try {
+ __pf(*this);
+ }
+ catch(exception& __fail){
+ // 27.6.2.5.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::operator<<(bool __n)
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ try {
+ if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
+ this->setstate(ios_base::badbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::operator<<(long __n)
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ try {
+ bool __f;
+ ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
+ if (__fmt & ios_base::oct || __fmt & ios_base::hex)
+ __f = _M_fnumput->put(*this, *this, this->fill(),
+ static_cast<unsigned long>(__n)).failed();
+ else
+ __f = _M_fnumput->put(*this, *this, this->fill(), __n).failed();
+
+ if (__f)
+ this->setstate(ios_base::badbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ try {
+ if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
+ this->setstate(ios_base::badbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::operator<<(long long __n)
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ try {
+ bool __f;
+ ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
+ if (__fmt & ios_base::oct || __fmt & ios_base::hex)
+ __f = _M_fnumput->put(*this, *this, this->fill(),
+ static_cast<unsigned long long>(__n)).failed();
+ else
+ __f = _M_fnumput->put(*this, *this, this->fill(), __n).failed();
+
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ try {
+ if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
+ this->setstate(ios_base::badbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+#endif
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::operator<<(double __n)
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ try {
+ if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
+ this->setstate(ios_base::badbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::operator<<(long double __n)
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ try {
+ if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
+ this->setstate(ios_base::badbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ try {
+ if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
+ this->setstate(ios_base::badbit);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ this->setstate(ios_base::badbit);
+ if ((this->exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin)
+ {
+ streamsize __xtrct = 0;
+ __streambuf_type* __sbout = this->rdbuf();
+ sentry __cerb(*this);
+ if (__sbin && __cerb)
+ __xtrct = _S_copy_streambufs(*this, __sbin, __sbout);
+ if (!__sbin || !__xtrct)
+ this->setstate(ios_base::failbit);
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::put(char_type __c)
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ int_type __put = rdbuf()->sputc(__c);
+ if (__put != traits_type::to_int_type(__c))
+ this->setstate(ios_base::badbit);
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::write(const _CharT* __s, streamsize __n)
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ streamsize __put = this->rdbuf()->sputn(__s, __n);
+ if ( __put != __n)
+ this->setstate(ios_base::badbit);
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::flush()
+ {
+ sentry __cerb(*this);
+ if (__cerb)
+ {
+ if (this->rdbuf() && this->rdbuf()->pubsync() == -1)
+ this->setstate(ios_base::badbit);
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ typename basic_ostream<_CharT, _Traits>::pos_type
+ basic_ostream<_CharT, _Traits>::tellp()
+ {
+ pos_type __retval = pos_type(-1);
+ bool __testok = this->fail() != true;
+
+ if (__testok)
+ __retval = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
+ return __retval;
+ }
+
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
+ {
+ bool __testok = this->fail() != true;
+
+ if (__testok)
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+// 136. seekp, seekg setting wrong streams?
+ this->rdbuf()->pubseekpos(__pos, ios_base::out);
+#endif
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ basic_ostream<_CharT, _Traits>::
+ seekp(off_type __off, ios_base::seekdir __d)
+ {
+ bool __testok = this->fail() != true;
+
+ if (__testok)
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+// 136. seekp, seekg setting wrong streams?
+ rdbuf()->pubseekoff(__off, __d, ios_base::out);
+#endif
+ return *this;
+ }
+
+ // 27.6.2.5.4 Character inserters
+
+ // Construct correctly padded string, as per 22.2.2.2.2
+ // Similar in theory to _S_pad_numeric, from num_put, but it doesn't
+ // use _S_fill: perhaps it should.
+ // Assumes
+ // __newlen > __oldlen
+ // __news is allocated for __newlen size
+ template<typename _CharT, typename _Traits>
+ static void
+ _S_pad_char(basic_ios<_CharT, _Traits>& __ios,
+ _CharT* __news, const _CharT* __olds,
+ const streamsize __newlen, const streamsize __oldlen)
+ {
+ typedef _CharT char_type;
+ typedef _Traits traits_type;
+ typedef typename traits_type::int_type int_type;
+
+ int_type __plen = static_cast<size_t>(__newlen - __oldlen);
+ char_type __pads[__plen];
+ traits_type::assign(__pads, __plen, __ios.fill());
+
+ char_type* __beg;
+ char_type* __end;
+ size_t __mod = 0;
+ size_t __beglen; //either __plen or __oldlen
+ ios_base::fmtflags __fmt = __ios.flags() & ios_base::adjustfield;
+
+ if (__fmt == ios_base::left)
+ {
+ // Padding last.
+ __beg = const_cast<char_type*>(__olds);
+ __beglen = __oldlen;
+ __end = __pads;
+ }
+ else if (__fmt == ios_base::internal)
+ {
+ // Pad after the sign, if there is one.
+ // Pad after 0[xX], if there is one.
+ // Who came up with these rules, anyway? Jeeze.
+ typedef _Format_cache<_CharT> __cache_type;
+ __cache_type const* __fmt = __cache_type::_S_get(__ios);
+ const char_type* __minus = traits_type::find(__olds, __oldlen,
+ __fmt->_S_minus);
+ const char_type* __plus = traits_type::find(__olds, __oldlen,
+ __fmt->_S_plus);
+ bool __testsign = __minus || __plus;
+ bool __testhex = __olds[0] == '0'
+ && (__olds[1] == 'x' || __olds[1] == 'X');
+
+ if (__testhex)
+ {
+ __news[0] = __olds[0];
+ __news[1] = __olds[1];
+ __mod += 2;
+ __beg = const_cast<char_type*>(__olds + __mod);
+ __beglen = __oldlen - __mod;
+ __end = __pads;
+ }
+ else if (__testsign)
+ {
+ __mod += __plen;
+ const char_type* __sign = __minus ? __minus + 1: __plus + 1;
+ __beg = const_cast<char_type*>(__olds);
+ __beglen = __sign - __olds;
+ __end = const_cast<char_type*>(__sign + __plen);
+ traits_type::copy(__news + __beglen, __pads, __plen);
+ }
+ else
+ {
+ // Padding first.
+ __beg = __pads;
+ __beglen = __plen;
+ __end = const_cast<char_type*>(__olds);
+ }
+ }
+ else
+ {
+ // Padding first.
+ __beg = __pads;
+ __beglen = __plen;
+ __end = const_cast<char_type*>(__olds);
+ }
+
+ traits_type::copy(__news, __beg, __beglen);
+ traits_type::copy(__news + __beglen, __end, __newlen - __beglen - __mod);
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
+ {
+ typedef basic_ostream<_CharT, _Traits> __ostream_type;
+ __ostream_type::sentry __cerb(__out);
+ if (__cerb)
+ {
+ try {
+ streamsize __w = __out.width();
+ _CharT __pads[__w];
+ __pads[0] = __c;
+ streamsize __len = 1;
+ if (__w > __len)
+ {
+ _S_pad_char(__out, __pads, &__c, __w, __len);
+ __len = __w;
+ }
+ __out.write(__pads, __len);
+ __out.width(0);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ __out.setstate(ios_base::badbit);
+ if ((__out.exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return __out;
+ }
+
+ // Specialization
+ template <class _Traits>
+ basic_ostream<char, _Traits>&
+ operator<<(basic_ostream<char, _Traits>& __out, char __c)
+ {
+ typedef basic_ostream<char, _Traits> __ostream_type;
+ __ostream_type::sentry __cerb(__out);
+ if (__cerb)
+ {
+ try {
+ streamsize __w = __out.width();
+ char __pads[__w + 1];
+ __pads[0] = __c;
+ streamsize __len = 1;
+ if (__w > __len)
+ {
+ _S_pad_char(__out, __pads, &__c, __w, __len);
+ __len = __w;
+ }
+ __out.write(__pads, __len);
+ __out.width(0);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ __out.setstate(ios_base::badbit);
+ if ((__out.exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return __out;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
+ {
+ typedef basic_ostream<_CharT, _Traits> __ostream_type;
+ __ostream_type::sentry __cerb(__out);
+ if (__cerb)
+ {
+ try {
+ streamsize __w = __out.width();
+ _CharT __pads[__w];
+ streamsize __len = static_cast<streamsize>(_Traits::length(__s));
+ if (__w > __len)
+ {
+ _S_pad_char(__out, __pads, __s, __w, __len);
+ __s = __pads;
+ __len = __w;
+ }
+ __out.write(__s, __len);
+ __out.width(0);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ __out.setstate(ios_base::badbit);
+ if ((__out.exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return __out;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __out, const char* /*__s*/)
+ {
+#if 0
+ typedef basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef typename _Traits::state_type __state_type;
+ typedef codecvt<char, _CharT, __state_type> __codecvt_type;
+ typedef typename __ostream_type::char_type __char_type;
+
+ __ostream_type::sentry __cerb(__out);
+ if (__cerb)
+ {
+ const __codecvt_type* __fcvt = &use_facet<__codecvt_type>(__out.getloc());
+ try {
+ streamsize __n = char_traits<char>::length(__s);
+ __char_type __conv[__n];
+ __state_type __state_cur;
+ __char_type __pbuf[__n];
+ __char_type* __pend;
+ char* __send;
+ __fcvt->out(__state_cur,
+ __pbuf, __pbuf + __n,
+ const_cast<const __char_type*&>(__pend),
+ const_cast<char*>(__s),
+ const_cast<char*>(__s + __n),
+ __send);
+ __out.write(__pbuf, __n);
+ }
+#endif
+ return __out;
+ }
+
+ // Partial specializationss
+ template<class _Traits>
+ basic_ostream<char, _Traits>&
+ operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
+ {
+ typedef basic_ostream<char, _Traits> __ostream_type;
+ __ostream_type::sentry __cerb(__out);
+ if (__cerb)
+ {
+ try {
+ streamsize __w = __out.width();
+ char __pads[__w];
+ streamsize __len = static_cast<streamsize>(_Traits::length(__s));
+ if (__w > __len)
+ {
+ _S_pad_char(__out, __pads, __s, __w, __len);
+ __s = __pads;
+ __len = __w;
+ }
+ __out.write(__s, __len);
+ __out.width(0);
+ }
+ catch(exception& __fail){
+ // 27.6.1.2.1 Common requirements.
+ // Turn this on without causing an ios::failure to be thrown.
+ __out.setstate(ios_base::badbit);
+ if ((__out.exceptions() & ios_base::badbit) != 0)
+ throw;
+ }
+ }
+ return __out;
+ }
+
+ // 21.3.7.8 basic_string::operator<<
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __out,
+ const basic_string<_CharT, _Traits, _Alloc>& __s)
+ { return (__out << __s.c_str()); }
+
+} // namespace std
+
+// Local Variables:
+// mode:C++
+// End:
+
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/pthread_allocimpl.h b/libstdc++-v3/bits/pthread_allocimpl.h
new file mode 100644
index 0000000..3b63127
--- /dev/null
+++ b/libstdc++-v3/bits/pthread_allocimpl.h
@@ -0,0 +1,495 @@
+/*
+ * Copyright (c) 1996
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_BITS_PTHREAD_ALLOCIMPL_H
+#define _CPP_BITS_PTHREAD_ALLOCIMPL_H 1
+
+// Pthread-specific node allocator.
+// This is similar to the default allocator, except that free-list
+// information is kept separately for each thread, avoiding locking.
+// This should be reasonably fast even in the presence of threads.
+// The down side is that storage may not be well-utilized.
+// It is not an error to allocate memory in thread A and deallocate
+// it in thread B. But this effectively transfers ownership of the memory,
+// so that it can only be reallocated by thread B. Thus this can effectively
+// result in a storage leak if it's done on a regular basis.
+// It can also result in frequent sharing of
+// cache lines among processors, with potentially serious performance
+// consequences.
+
+#include <bits/std_cerrno.h>
+#include <bits/stl_config.h>
+#include <bits/stl_alloc.h>
+#ifndef __RESTRICT
+# define __RESTRICT
+#endif
+
+#ifndef __STL_NO_BAD_ALLOC
+# include <bits/std_new.h>
+#endif
+
+__STL_BEGIN_NAMESPACE
+
+#define __STL_DATA_ALIGNMENT 8
+
+union _Pthread_alloc_obj {
+ union _Pthread_alloc_obj * __free_list_link;
+ char __client_data[__STL_DATA_ALIGNMENT]; /* The client sees this. */
+};
+
+// Pthread allocators don't appear to the client to have meaningful
+// instances. We do in fact need to associate some state with each
+// thread. That state is represented by
+// _Pthread_alloc_per_thread_state<_Max_size>.
+
+template<size_t _Max_size>
+struct _Pthread_alloc_per_thread_state {
+ typedef _Pthread_alloc_obj __obj;
+ enum { _S_NFREELISTS = _Max_size/__STL_DATA_ALIGNMENT };
+ _Pthread_alloc_obj* volatile __free_list[_S_NFREELISTS];
+ _Pthread_alloc_per_thread_state<_Max_size> * __next;
+ // Free list link for list of available per thread structures.
+ // When one of these becomes available for reuse due to thread
+ // termination, any objects in its free list remain associated
+ // with it. The whole structure may then be used by a newly
+ // created thread.
+ _Pthread_alloc_per_thread_state() : __next(0)
+ {
+ memset((void *)__free_list, 0, (size_t) _S_NFREELISTS * sizeof(__obj *));
+ }
+ // Returns an object of size __n, and possibly adds to size n free list.
+ void *_M_refill(size_t __n);
+};
+
+// Pthread-specific allocator.
+// The argument specifies the largest object size allocated from per-thread
+// free lists. Larger objects are allocated using malloc_alloc.
+// Max_size must be a power of 2.
+template <size_t _Max_size = 128>
+class _Pthread_alloc_template {
+
+public: // but only for internal use:
+
+ typedef _Pthread_alloc_obj __obj;
+
+ // Allocates a chunk for nobjs of size size. nobjs may be reduced
+ // if it is inconvenient to allocate the requested number.
+ static char *_S_chunk_alloc(size_t __size, int &__nobjs);
+
+ enum {_S_ALIGN = __STL_DATA_ALIGNMENT};
+
+ static size_t _S_round_up(size_t __bytes) {
+ return (((__bytes) + (int) _S_ALIGN-1) & ~((int) _S_ALIGN - 1));
+ }
+ static size_t _S_freelist_index(size_t __bytes) {
+ return (((__bytes) + (int) _S_ALIGN-1)/(int)_S_ALIGN - 1);
+ }
+
+private:
+ // Chunk allocation state. And other shared state.
+ // Protected by _S_chunk_allocator_lock.
+ static pthread_mutex_t _S_chunk_allocator_lock;
+ static char *_S_start_free;
+ static char *_S_end_free;
+ static size_t _S_heap_size;
+ static _Pthread_alloc_per_thread_state<_Max_size>* _S_free_per_thread_states;
+ static pthread_key_t _S_key;
+ static bool _S_key_initialized;
+ // Pthread key under which per thread state is stored.
+ // Allocator instances that are currently unclaimed by any thread.
+ static void _S_destructor(void *instance);
+ // Function to be called on thread exit to reclaim per thread
+ // state.
+ static _Pthread_alloc_per_thread_state<_Max_size> *_S_new_per_thread_state();
+ // Return a recycled or new per thread state.
+ static _Pthread_alloc_per_thread_state<_Max_size> *_S_get_per_thread_state();
+ // ensure that the current thread has an associated
+ // per thread state.
+ class _M_lock;
+ friend class _M_lock;
+ class _M_lock {
+ public:
+ _M_lock () { pthread_mutex_lock(&_S_chunk_allocator_lock); }
+ ~_M_lock () { pthread_mutex_unlock(&_S_chunk_allocator_lock); }
+ };
+
+public:
+
+ /* n must be > 0 */
+ static void * allocate(size_t __n)
+ {
+ __obj * volatile * __my_free_list;
+ __obj * __RESTRICT __result;
+ _Pthread_alloc_per_thread_state<_Max_size>* __a;
+
+ if (__n > _Max_size) {
+ return(malloc_alloc::allocate(__n));
+ }
+ if (!_S_key_initialized ||
+ !(__a = (_Pthread_alloc_per_thread_state<_Max_size>*)
+ pthread_getspecific(_S_key))) {
+ __a = _S_get_per_thread_state();
+ }
+ __my_free_list = __a -> __free_list + _S_freelist_index(__n);
+ __result = *__my_free_list;
+ if (__result == 0) {
+ void *__r = __a -> _M_refill(_S_round_up(__n));
+ return __r;
+ }
+ *__my_free_list = __result -> __free_list_link;
+ return (__result);
+ };
+
+ /* p may not be 0 */
+ static void deallocate(void *__p, size_t __n)
+ {
+ __obj *__q = (__obj *)__p;
+ __obj * volatile * __my_free_list;
+ _Pthread_alloc_per_thread_state<_Max_size>* __a;
+
+ if (__n > _Max_size) {
+ malloc_alloc::deallocate(__p, __n);
+ return;
+ }
+ if (!_S_key_initialized ||
+ !(__a = (_Pthread_alloc_per_thread_state<_Max_size> *)
+ pthread_getspecific(_S_key))) {
+ __a = _S_get_per_thread_state();
+ }
+ __my_free_list = __a->__free_list + _S_freelist_index(__n);
+ __q -> __free_list_link = *__my_free_list;
+ *__my_free_list = __q;
+ }
+
+ static void * reallocate(void *__p, size_t __old_sz, size_t __new_sz);
+
+} ;
+
+typedef _Pthread_alloc_template<> pthread_alloc;
+
+
+template <size_t _Max_size>
+void _Pthread_alloc_template<_Max_size>::_S_destructor(void * __instance)
+{
+ _M_lock __lock_instance; // Need to acquire lock here.
+ _Pthread_alloc_per_thread_state<_Max_size>* __s =
+ (_Pthread_alloc_per_thread_state<_Max_size> *)__instance;
+ __s -> __next = _S_free_per_thread_states;
+ _S_free_per_thread_states = __s;
+}
+
+template <size_t _Max_size>
+_Pthread_alloc_per_thread_state<_Max_size> *
+_Pthread_alloc_template<_Max_size>::_S_new_per_thread_state()
+{
+ /* lock already held here. */
+ if (0 != _S_free_per_thread_states) {
+ _Pthread_alloc_per_thread_state<_Max_size> *__result =
+ _S_free_per_thread_states;
+ _S_free_per_thread_states = _S_free_per_thread_states -> __next;
+ return __result;
+ } else {
+ return new _Pthread_alloc_per_thread_state<_Max_size>;
+ }
+}
+
+template <size_t _Max_size>
+_Pthread_alloc_per_thread_state<_Max_size> *
+_Pthread_alloc_template<_Max_size>::_S_get_per_thread_state()
+{
+ /*REFERENCED*/
+ _M_lock __lock_instance; // Need to acquire lock here.
+ int __ret_code;
+ _Pthread_alloc_per_thread_state<_Max_size> * __result;
+ if (!_S_key_initialized) {
+ if (pthread_key_create(&_S_key, _S_destructor)) {
+ __THROW_BAD_ALLOC; // defined in stl_alloc.h
+ }
+ _S_key_initialized = true;
+ }
+ __result = _S_new_per_thread_state();
+ __ret_code = pthread_setspecific(_S_key, __result);
+ if (__ret_code) {
+ if (__ret_code == ENOMEM) {
+ __THROW_BAD_ALLOC;
+ } else {
+ // EINVAL
+ abort();
+ }
+ }
+ return __result;
+}
+
+/* We allocate memory in large chunks in order to avoid fragmenting */
+/* the malloc heap too much. */
+/* We assume that size is properly aligned. */
+template <size_t _Max_size>
+char *_Pthread_alloc_template<_Max_size>
+::_S_chunk_alloc(size_t __size, int &__nobjs)
+{
+ {
+ char * __result;
+ size_t __total_bytes;
+ size_t __bytes_left;
+ /*REFERENCED*/
+ _M_lock __lock_instance; // Acquire lock for this routine
+
+ __total_bytes = __size * __nobjs;
+ __bytes_left = _S_end_free - _S_start_free;
+ if (__bytes_left >= __total_bytes) {
+ __result = _S_start_free;
+ _S_start_free += __total_bytes;
+ return(__result);
+ } else if (__bytes_left >= __size) {
+ __nobjs = __bytes_left/__size;
+ __total_bytes = __size * __nobjs;
+ __result = _S_start_free;
+ _S_start_free += __total_bytes;
+ return(__result);
+ } else {
+ size_t __bytes_to_get =
+ 2 * __total_bytes + _S_round_up(_S_heap_size >> 4);
+ // Try to make use of the left-over piece.
+ if (__bytes_left > 0) {
+ _Pthread_alloc_per_thread_state<_Max_size>* __a =
+ (_Pthread_alloc_per_thread_state<_Max_size>*)
+ pthread_getspecific(_S_key);
+ __obj * volatile * __my_free_list =
+ __a->__free_list + _S_freelist_index(__bytes_left);
+
+ ((__obj *)_S_start_free) -> __free_list_link = *__my_free_list;
+ *__my_free_list = (__obj *)_S_start_free;
+ }
+# ifdef _SGI_SOURCE
+ // Try to get memory that's aligned on something like a
+ // cache line boundary, so as to avoid parceling out
+ // parts of the same line to different threads and thus
+ // possibly different processors.
+ {
+ const int __cache_line_size = 128; // probable upper bound
+ __bytes_to_get &= ~(__cache_line_size-1);
+ _S_start_free = (char *)memalign(__cache_line_size, __bytes_to_get);
+ if (0 == _S_start_free) {
+ _S_start_free = (char *)malloc_alloc::allocate(__bytes_to_get);
+ }
+ }
+# else /* !SGI_SOURCE */
+ _S_start_free = (char *)malloc_alloc::allocate(__bytes_to_get);
+# endif
+ _S_heap_size += __bytes_to_get;
+ _S_end_free = _S_start_free + __bytes_to_get;
+ }
+ }
+ // lock is released here
+ return(_S_chunk_alloc(__size, __nobjs));
+}
+
+
+/* Returns an object of size n, and optionally adds to size n free list.*/
+/* We assume that n is properly aligned. */
+/* We hold the allocation lock. */
+template <size_t _Max_size>
+void *_Pthread_alloc_per_thread_state<_Max_size>
+::_M_refill(size_t __n)
+{
+ int __nobjs = 128;
+ char * __chunk =
+ _Pthread_alloc_template<_Max_size>::_S_chunk_alloc(__n, __nobjs);
+ __obj * volatile * __my_free_list;
+ __obj * __result;
+ __obj * __current_obj, * __next_obj;
+ int __i;
+
+ if (1 == __nobjs) {
+ return(__chunk);
+ }
+ __my_free_list = __free_list
+ + _Pthread_alloc_template<_Max_size>::_S_freelist_index(__n);
+
+ /* Build free list in chunk */
+ __result = (__obj *)__chunk;
+ *__my_free_list = __next_obj = (__obj *)(__chunk + __n);
+ for (__i = 1; ; __i++) {
+ __current_obj = __next_obj;
+ __next_obj = (__obj *)((char *)__next_obj + __n);
+ if (__nobjs - 1 == __i) {
+ __current_obj -> __free_list_link = 0;
+ break;
+ } else {
+ __current_obj -> __free_list_link = __next_obj;
+ }
+ }
+ return(__result);
+}
+
+template <size_t _Max_size>
+void *_Pthread_alloc_template<_Max_size>
+::reallocate(void *__p, size_t __old_sz, size_t __new_sz)
+{
+ void * __result;
+ size_t __copy_sz;
+
+ if (__old_sz > _Max_size
+ && __new_sz > _Max_size) {
+ return(realloc(__p, __new_sz));
+ }
+ if (_S_round_up(__old_sz) == _S_round_up(__new_sz)) return(__p);
+ __result = allocate(__new_sz);
+ __copy_sz = __new_sz > __old_sz? __old_sz : __new_sz;
+ memcpy(__result, __p, __copy_sz);
+ deallocate(__p, __old_sz);
+ return(__result);
+}
+
+template <size_t _Max_size>
+_Pthread_alloc_per_thread_state<_Max_size> *
+_Pthread_alloc_template<_Max_size>::_S_free_per_thread_states = 0;
+
+template <size_t _Max_size>
+pthread_key_t _Pthread_alloc_template<_Max_size>::_S_key;
+
+template <size_t _Max_size>
+bool _Pthread_alloc_template<_Max_size>::_S_key_initialized = false;
+
+template <size_t _Max_size>
+pthread_mutex_t _Pthread_alloc_template<_Max_size>::_S_chunk_allocator_lock
+= PTHREAD_MUTEX_INITIALIZER;
+
+template <size_t _Max_size>
+char *_Pthread_alloc_template<_Max_size>
+::_S_start_free = 0;
+
+template <size_t _Max_size>
+char *_Pthread_alloc_template<_Max_size>
+::_S_end_free = 0;
+
+template <size_t _Max_size>
+size_t _Pthread_alloc_template<_Max_size>
+::_S_heap_size = 0;
+
+#ifdef __STL_USE_STD_ALLOCATORS
+
+template <class _Tp>
+class pthread_allocator {
+ typedef pthread_alloc _S_Alloc; // The underlying allocator.
+public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef _Tp* pointer;
+ typedef const _Tp* const_pointer;
+ typedef _Tp& reference;
+ typedef const _Tp& const_reference;
+ typedef _Tp value_type;
+
+ template <class _NewType> struct rebind {
+ typedef pthread_allocator<_NewType> other;
+ };
+
+ pthread_allocator() __STL_NOTHROW {}
+ pthread_allocator(const pthread_allocator& a) __STL_NOTHROW {}
+ template <class _OtherType>
+ pthread_allocator(const pthread_allocator<_OtherType>&)
+ __STL_NOTHROW {}
+ ~pthread_allocator() __STL_NOTHROW {}
+
+ pointer address(reference __x) const { return &__x; }
+ const_pointer address(const_reference __x) const { return &__x; }
+
+ // __n is permitted to be 0. The C++ standard says nothing about what
+ // the return value is when __n == 0.
+ _Tp* allocate(size_type __n, const void* = 0) {
+ return __n != 0 ? static_cast<_Tp*>(_S_Alloc::allocate(__n * sizeof(_Tp)))
+ : 0;
+ }
+
+ // p is not permitted to be a null pointer.
+ void deallocate(pointer __p, size_type __n)
+ { _S_Alloc::deallocate(__p, __n * sizeof(_Tp)); }
+
+ size_type max_size() const __STL_NOTHROW
+ { return size_t(-1) / sizeof(_Tp); }
+
+ void construct(pointer __p, const _Tp& __val) { new(__p) _Tp(__val); }
+ void destroy(pointer _p) { _p->~_Tp(); }
+};
+
+template<>
+class pthread_allocator<void> {
+public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef void* pointer;
+ typedef const void* const_pointer;
+ typedef void value_type;
+
+ template <class _NewType> struct rebind {
+ typedef pthread_allocator<_NewType> other;
+ };
+};
+
+template <size_t _Max_size>
+inline bool operator==(const _Pthread_alloc_template<_Max_size>&,
+ const _Pthread_alloc_template<_Max_size>&)
+{
+ return true;
+}
+
+template <class _T1, class _T2>
+inline bool operator==(const pthread_allocator<_T1>&,
+ const pthread_allocator<_T2>& a2)
+{
+ return true;
+}
+
+template <class _T1, class _T2>
+inline bool operator!=(const pthread_allocator<_T1>&,
+ const pthread_allocator<_T2>&)
+{
+ return false;
+}
+
+template <class _Tp, size_t _Max_size>
+struct _Alloc_traits<_Tp, _Pthread_alloc_template<_Max_size> >
+{
+ static const bool _S_instanceless = true;
+ typedef simple_alloc<_Tp, _Pthread_alloc_template<_Max_size> > _Alloc_type;
+ typedef __allocator<_Tp, _Pthread_alloc_template<_Max_size> >
+ allocator_type;
+};
+
+template <class _Tp, class _Atype, size_t _Max>
+struct _Alloc_traits<_Tp, __allocator<_Atype, _Pthread_alloc_template<_Max> > >
+{
+ static const bool _S_instanceless = true;
+ typedef simple_alloc<_Tp, _Pthread_alloc_template<_Max> > _Alloc_type;
+ typedef __allocator<_Tp, _Pthread_alloc_template<_Max> > allocator_type;
+};
+
+template <class _Tp, class _Atype>
+struct _Alloc_traits<_Tp, pthread_allocator<_Atype> >
+{
+ static const bool _S_instanceless = true;
+ typedef simple_alloc<_Tp, _Pthread_alloc_template<> > _Alloc_type;
+ typedef pthread_allocator<_Tp> allocator_type;
+};
+
+
+#endif /* __STL_USE_STD_ALLOCATORS */
+
+__STL_END_NAMESPACE
+
+#endif /* _CPP_BITS_PTHREAD_ALLOCIMPL_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/sbuf_iter.h b/libstdc++-v3/bits/sbuf_iter.h
new file mode 100644
index 0000000..a028f23
--- /dev/null
+++ b/libstdc++-v3/bits/sbuf_iter.h
@@ -0,0 +1,264 @@
+// Streambuf iterators
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+// XXX Should specialize copy, find algorithms for streambuf iterators.
+
+#ifndef _CPP_BITS_SBUF_ITER_H
+#define _CPP_BITS_SBUF_ITER_H 1
+
+namespace std
+{
+
+ template<typename _CharT, typename _Traits>
+ class ostreambuf_iterator
+#if 0 // XXX this is standard:
+ : public iterator<output_iterator_tag,_CharT,void,void,void>
+#else
+ : public output_iterator
+#endif
+ {
+ public:
+
+ // Types:
+ typedef _CharT char_type;
+ typedef _Traits traits_type;
+ typedef basic_streambuf<_CharT, _Traits> streambuf_type;
+ typedef basic_ostream<_CharT, _Traits> ostream_type;
+
+ inline
+ ostreambuf_iterator(ostream_type& __s) throw ()
+ : _M_sbuf(__s.rdbuf()), _M_failed(false) { }
+
+ ostreambuf_iterator(streambuf_type* __s) throw ()
+ : _M_sbuf(__s), _M_failed(false) { }
+
+ ostreambuf_iterator&
+ operator=(_CharT __c);
+
+ ostreambuf_iterator&
+ operator*() throw()
+ { return *this; }
+
+ ostreambuf_iterator&
+ operator++(int) throw()
+ { return *this; }
+
+ ostreambuf_iterator&
+ operator++() throw()
+ { return *this; }
+
+ bool
+ failed() const throw()
+ { return _M_failed; }
+
+ private:
+ streambuf_type* _M_sbuf;
+ bool _M_failed;
+
+#if 0
+ template<>
+ friend char const*
+ copy(char const* __first, char const* __last,
+ ostreambuf_iterator<char,char_traits<char> > __to);
+ template<>
+ friend wchar_t const*
+ copy(wchar_t const* __first, wchar_t const* __last,
+ ostreambuf_iterator<wchar_t,char_traits<wchar_t> > __to);
+#endif
+ };
+
+ template<typename _CharT, typename _Traits>
+ inline ostreambuf_iterator<_CharT, _Traits>&
+ ostreambuf_iterator<_CharT, _Traits>::operator=(_CharT __c)
+ {
+ if (!_M_failed &&
+ _Traits::eq_int_type(_M_sbuf->sputc(__c),_Traits::eof()))
+ _M_failed = true;
+ return *this;
+ }
+
+
+#if 0
+ // Optimized specializations of standard algorithms
+ // These are specialized only for standard types
+ // (with no unbound arguments) to avoid creating
+ // overload problems with user specializations.
+
+ template<>
+ char const*
+ copy(char const* __first, char const* __last,
+ ostreambuf_iterator<char,char_traits<char> > __to)
+ {
+ if (!__to._M_failed)
+ __to._M_sbuf->sputn(__first, __last-__first);
+ return __last;
+ }
+
+ template<>
+ wchar_t const*
+ copy(wchar_t const* __first, wchar_t const* __last,
+ ostreambuf_iterator<whar_t,char_traits<wchar_t> > __to)
+ {
+ if (!__to._M_failed)
+ __to._M_sbuf->sputn(__first, __last-__first);
+ return __last;
+ }
+#endif
+
+ // 24.5.3 Template class istreambuf_iterator
+ template<class _CharT, class _Traits>
+ class istreambuf_iterator
+ : public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
+ _CharT*, _CharT&>
+ {
+ public:
+
+ // Types:
+ typedef _CharT char_type;
+ typedef _Traits traits_type;
+ typedef typename _Traits::int_type int_type;
+ typedef basic_streambuf<_CharT, _Traits> streambuf_type;
+ typedef basic_istream<_CharT, _Traits> istream_type;
+ // Non-standard Types:
+ typedef istreambuf_iterator<_CharT, _Traits> __istreambufiter_type;
+
+ istreambuf_iterator() throw()
+ : _M_istreambuf(NULL), _M_c(-2) { }
+
+ istreambuf_iterator(istream_type& __s) throw()
+ : _M_istreambuf(__s.rdbuf()), _M_c(-2) { }
+
+ istreambuf_iterator(streambuf_type* __s) throw()
+ : _M_istreambuf(__s), _M_c(-2) { }
+
+ // NB: This should really have an int_type return
+ // value, so "end of stream" postion can be checked without
+ // hacking.
+ char_type
+ operator*() const
+ {
+ // The result of operator*() on an end of stream is undefined.
+ char_type __retval;
+ if (_M_istreambuf && _M_c != static_cast<int_type>(-2))
+ __retval = _M_c;
+ else if (_M_istreambuf)
+ __retval = traits_type::to_char_type(_M_istreambuf->sgetc());
+ else
+ __retval = static_cast<char_type>(traits_type::eof());
+ return __retval;
+ }
+
+ __istreambufiter_type&
+ operator++()
+ {
+ if (_M_istreambuf)
+ _M_istreambuf->sbumpc();
+ _M_c = -2;
+ return *this;
+ }
+
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ // 14882 says return a proxy object. It should be a const
+ // proxy object, but since this class is not mandated, it
+ // should allow this signature:
+ const __istreambufiter_type
+ operator++(int)
+ {
+ if (_M_istreambuf)
+ _M_c = _M_istreambuf->sbumpc();
+ return *this;
+ }
+#endif
+
+ bool
+ equal(const __istreambufiter_type& __b)
+ {
+ int_type __eof = traits_type::eof();
+ bool __thiseof = !_M_istreambuf || _M_istreambuf->sgetc() == __eof;
+ bool __beof = !__b._M_istreambuf
+ || __b._M_istreambuf->sgetc() == __eof;
+ return (__thiseof && __beof || (!__thiseof && !__beof));
+ }
+
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ // 110 istreambuf_iterator::equal not const
+ // NB: there is also number 111 pending on this function.
+ bool
+ equal(const __istreambufiter_type& __b) const
+ {
+ int_type __eof = traits_type::eof();
+ bool __thiseof = !_M_istreambuf || _M_istreambuf->sgetc() == __eof;
+ bool __beof = !__b._M_istreambuf
+ || __b._M_istreambuf->sgetc() == __eof;
+ return (__thiseof && __beof || (!__thiseof && !__beof));
+ }
+#endif
+
+ private:
+ // 24.5.3 istreambuf_iterator
+ // p 1
+ // If the end of stream is reached (streambuf_type::sgetc()
+ // returns traits_type::eof()), the iterator becomes equal to
+ // the "end of stream" iterator value.
+ // NB: This implementation assumes the "end of stream" value
+ // is EOF, or -1.
+ streambuf_type* _M_istreambuf;
+ int_type _M_c;
+ };
+
+ template<typename _CharT, typename _Traits>
+ inline bool
+ operator==(const istreambuf_iterator<_CharT, _Traits>& __a,
+ const istreambuf_iterator<_CharT, _Traits>& __b)
+ { return __a.equal(__b); }
+
+ template<typename _CharT, typename _Traits>
+ inline bool
+ operator!=(const istreambuf_iterator<_CharT, _Traits>& __a,
+ const istreambuf_iterator<_CharT, _Traits>& __b)
+ { return !__a.equal(__b); }
+
+} // std::
+
+#endif /* _CPP_BITS_SBUF_ITER_H */
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/slice.h b/libstdc++-v3/bits/slice.h
new file mode 100644
index 0000000..3e4f7a7
--- /dev/null
+++ b/libstdc++-v3/bits/slice.h
@@ -0,0 +1,77 @@
+// The template and inlines for the -*- C++ -*- slice class.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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 Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
+
+#ifndef _CPP_BITS_SLICE_H
+#define _CPP_BITS_SLICE_H
+
+namespace std {
+
+class slice
+{
+public:
+ slice ();
+ slice (size_t, size_t, size_t);
+
+ size_t start () const;
+ size_t size () const;
+ size_t stride () const;
+
+private:
+ size_t _M_off; // offset
+ size_t _M_sz; // size
+ size_t _M_st; // stride unit
+};
+
+inline slice::slice () {}
+
+inline slice::slice (size_t __o, size_t __d, size_t __s)
+ : _M_off (__o), _M_sz (__d), _M_st (__s) {}
+
+inline size_t
+slice::start () const
+ { return _M_off; }
+
+inline size_t
+slice::size () const
+ { return _M_sz; }
+
+inline size_t
+slice::stride () const
+ { return _M_st; }
+
+} // std::
+
+
+#endif /* _CPP_BITS_SLICE_H */
+
+// Local Variables:
+// mode:c++
+// End:
diff --git a/libstdc++-v3/bits/slice_array.h b/libstdc++-v3/bits/slice_array.h
new file mode 100644
index 0000000..04efd5f
--- /dev/null
+++ b/libstdc++-v3/bits/slice_array.h
@@ -0,0 +1,161 @@
+// The template and inlines for the -*- C++ -*- slice_array class.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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 Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
+
+#ifndef _CPP_BITS_SLICE_ARRAY_H
+#define _CPP_BITS_SLICE_ARRAY_H 1
+
+namespace std {
+
+ template<typename _Tp>
+ class slice_array
+ {
+ public:
+ typedef _Tp value_type;
+
+ void operator= (const valarray<_Tp>&) const;
+ void operator*= (const valarray<_Tp>&) const;
+ void operator/= (const valarray<_Tp>&) const;
+ void operator%= (const valarray<_Tp>&) const;
+ void operator+= (const valarray<_Tp>&) const;
+ void operator-= (const valarray<_Tp>&) const;
+ void operator^= (const valarray<_Tp>&) const;
+ void operator&= (const valarray<_Tp>&) const;
+ void operator|= (const valarray<_Tp>&) const;
+ void operator<<= (const valarray<_Tp>&) const;
+ void operator>>= (const valarray<_Tp>&) const;
+ void operator= (const _Tp &);
+ // ~slice_array ();
+
+ template<class _Dom>
+ void operator= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator*= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator/= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator%= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator+= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator-= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator^= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator&= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator|= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator<<= (const _Expr<_Dom,_Tp>&) const;
+ template<class _Dom>
+ void operator>>= (const _Expr<_Dom,_Tp>&) const;
+
+ private:
+ friend class valarray<_Tp>;
+ slice_array(_Array<_Tp>, const slice&);
+
+ const size_t _M_sz;
+ const size_t _M_stride;
+ const _Array<_Tp> _M_array;
+
+ // this constructor is implemented since we need to return a value.
+ slice_array (const slice_array&);
+
+ // not implemented
+ slice_array ();
+ slice_array& operator= (const slice_array&);
+ };
+
+ template<typename _Tp>
+ inline slice_array<_Tp>::slice_array (_Array<_Tp> __a, const slice& __s)
+ : _M_sz (__s.size ()), _M_stride (__s.stride ()),
+ _M_array (__a.begin () + __s.start ()) {}
+
+
+ template<typename _Tp>
+ inline slice_array<_Tp>::slice_array(const slice_array<_Tp>& a)
+ : _M_sz(a._M_sz), _M_stride(a._M_stride), _M_array(a._M_array) {}
+
+ // template<typename _Tp>
+ // inline slice_array<_Tp>::~slice_array () {}
+
+ template<typename _Tp>
+ inline void
+ slice_array<_Tp>::operator= (const _Tp& __t)
+ { __valarray_fill (_M_array, _M_sz, _M_stride, __t); }
+
+ template<typename _Tp>
+ inline void
+ slice_array<_Tp>::operator= (const valarray<_Tp>& __v) const
+ { __valarray_copy (_Array<_Tp> (__v), _M_array, _M_sz, _M_stride); }
+
+ template<typename _Tp>
+ template<class _Dom>
+ inline void
+ slice_array<_Tp>::operator= (const _Expr<_Dom,_Tp>& __e) const
+ { __valarray_copy (__e, _M_sz, _M_array, _M_stride); }
+
+#undef _DEFINE_VALARRAY_OPERATOR
+#define _DEFINE_VALARRAY_OPERATOR(op, name) \
+template<typename _Tp> \
+inline void \
+slice_array<_Tp>::operator##op##= (const valarray<_Tp>& __v) const \
+{ \
+ _Array_augmented_##name (_M_array, _M_sz, _M_stride, _Array<_Tp> (__v));\
+} \
+ \
+template<typename _Tp> template<class _Dom> \
+inline void \
+slice_array<_Tp>::operator##op##= (const _Expr<_Dom,_Tp>& __e) const \
+{ \
+ _Array_augmented_##name (_M_array, _M_stride, __e, _M_sz); \
+}
+
+
+_DEFINE_VALARRAY_OPERATOR(*, multiplies)
+_DEFINE_VALARRAY_OPERATOR(/, divides)
+_DEFINE_VALARRAY_OPERATOR(%, modulus)
+_DEFINE_VALARRAY_OPERATOR(+, plus)
+_DEFINE_VALARRAY_OPERATOR(-, minus)
+_DEFINE_VALARRAY_OPERATOR(^, xor)
+_DEFINE_VALARRAY_OPERATOR(&, and)
+_DEFINE_VALARRAY_OPERATOR(|, or)
+_DEFINE_VALARRAY_OPERATOR(<<, shift_left)
+_DEFINE_VALARRAY_OPERATOR(>>, shift_right)
+
+#undef _DEFINE_VALARRAY_OPERATOR
+
+} // std::
+
+#endif /* _CPP_BITS_SLICE_ARRAY_H */
+
+// Local Variables:
+// mode:c++
+// End:
diff --git a/libstdc++-v3/bits/sstream.tcc b/libstdc++-v3/bits/sstream.tcc
new file mode 100644
index 0000000..6596c4b
--- /dev/null
+++ b/libstdc++-v3/bits/sstream.tcc
@@ -0,0 +1,221 @@
+// String based streams -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.7 String-based streams
+//
+
+#ifndef _CPP_BITS_SSTREAM_TCC
+#define _CPP_BITS_SSTREAM_TCC 1
+
+#include <bits/std_sstream.h>
+
+namespace std {
+
+ template <class _CharT, class _Traits, class _Alloc>
+ basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
+ basic_stringbuf<_CharT, _Traits, _Alloc>::
+ pbackfail(int_type __c)
+ {
+ int_type __retval = traits_type::eof();
+ bool __testeof = traits_type::eq_int_type(__c, traits_type::eof());
+ bool __testpos = _M_in_cur && _M_in_beg < _M_in_cur;
+
+ // Try to put back __c into input sequence in one of three ways.
+ // Order these tests done in is unspecified by the standard.
+ if (!__testeof && __testpos
+ && traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1]))
+ {
+ --_M_in_cur;
+ __retval = __c;
+ }
+ else if (!__testeof && __testpos)
+ {
+ --_M_in_cur;
+ *_M_in_cur = traits_type::to_char_type(__c);
+ __retval = __c;
+ }
+ else if (__testeof && __testpos)
+ {
+ --_M_in_cur;
+ __retval = traits_type::not_eof(__c);
+ }
+ return __retval;
+ }
+
+ template <class _CharT, class _Traits, class _Alloc>
+ basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
+ basic_stringbuf<_CharT, _Traits, _Alloc>::
+ overflow(int_type __c)
+ {
+ int_type __retval = traits_type::eof();
+ bool __testeof = traits_type::eq_int_type(__c, __retval);
+ bool __testwrite = _M_out_cur < _M_buf + _M_buf_size;
+ bool __testout = _M_mode & ios_base::out;
+
+ // Try to append __c into output sequence in one of two ways.
+ // Order these tests done in is unspecified by the standard.
+ if (__testout)
+ {
+ if (!__testeof)
+ {
+ // NB: Start ostringstream buffers at 1024 bytes. This
+ // is an experimental value (pronounced "arbitrary" in
+ // some of the hipper english-speaking countries), and
+ // can be changed to suite particular needs.
+ __size_type __len = max(_M_buf_size, static_cast<int_type>(512));
+ __len *= 2;
+
+ if (__testwrite)
+ __retval = this->sputc(__c);
+ else if (__len <= _M_string.max_size())
+ {
+ // Force-allocate, re-sync.
+ _M_string = this->str();
+ _M_string.reserve(__len);
+ _M_buf_size = static_cast<int_type>(__len);
+ _M_really_sync(_M_in_cur - _M_in_beg,
+ _M_out_cur - _M_out_beg);
+ *_M_out_cur = traits_type::to_char_type(__c);
+ _M_buf_bump(1);
+ __retval = __c;
+ }
+ }
+ else
+ __retval = traits_type::not_eof(__c);
+ }
+ return __retval;
+ }
+
+ template <class _CharT, class _Traits, class _Alloc>
+ basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
+ basic_stringbuf<_CharT, _Traits, _Alloc>::
+ seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode)
+ {
+ pos_type __retval = pos_type(off_type(-1));
+ bool __testin = __mode & ios_base::in && _M_mode & ios_base::in;
+ bool __testout = __mode & ios_base::out && _M_mode & ios_base::out;
+ bool __testboth = __testin && __testout && __way != ios_base::cur;
+
+ if (_M_buf_size && ((__testin != __testout) || __testboth))
+ {
+ char_type* __beg = _M_buf;
+ char_type* __curi = NULL;
+ char_type* __curo = NULL;
+ char_type* __endi = NULL;
+ char_type* __endo = NULL;
+
+ if (__testin)
+ {
+ __curi = this->gptr();
+ __endi = this->egptr();
+ }
+ if (__testout)
+ {
+ __curo = this->pptr();
+ __endo = this->epptr();
+ }
+
+ off_type __newoffi = 0;
+ off_type __newoffo = 0;
+ if (__way == ios_base::cur)
+ {
+ __newoffi = __curi - __beg;
+ __newoffo = __curo - __beg;
+ }
+ else if (__way == ios_base::end)
+ {
+ __newoffi = __endi - __beg;
+ __newoffo = __endo - __beg;
+ }
+
+ if (__testin
+ && __newoffi + __off >= 0 && __endi - __beg >= __newoffi + __off)
+ {
+ _M_in_cur = __beg + __newoffi + __off;
+ __retval = pos_type(__newoffi);
+ }
+ if (__testout
+ && __newoffo + __off >= 0 && __endo - __beg >= __newoffo + __off)
+ {
+ _M_buf_bump(__newoffo + __off - (_M_out_cur - __beg));
+ __retval = pos_type(__newoffo);
+ }
+ }
+ return __retval;
+ }
+
+ template <class _CharT, class _Traits, class _Alloc>
+ basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
+ basic_stringbuf<_CharT, _Traits, _Alloc>::
+ seekpos(pos_type __sp, ios_base::openmode __mode)
+ {
+ pos_type __retval = pos_type(off_type(-1));
+ off_type __pos = __sp._M_position();
+ char_type* __beg = NULL;
+ char_type* __end = NULL;
+ bool __testin = __mode & ios_base::in && _M_mode & ios_base::in;
+ bool __testout = __mode & ios_base::out && _M_mode & ios_base::out;
+
+ if (__testin)
+ {
+ __beg = this->eback();
+ __end = this->egptr();
+ }
+ if (__testout)
+ {
+ __beg = this->pbase();
+ __end = _M_buf + _M_buf_size;
+ }
+
+ if (0 <= __pos && __pos <= __end - __beg)
+ {
+ // Need to set both of these if applicable
+ if (__testin)
+ _M_in_cur = _M_in_beg + __pos;
+ if (__testout)
+ _M_buf_bump((__pos) - (_M_out_cur - __beg));
+ __retval = pos_type(off_type(__pos));
+ }
+
+ return __retval;
+ }
+
+} // namespace std
+
+#endif /* _CPP_BITS_SSTREAM_TCC */
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_algorithm.h b/libstdc++-v3/bits/std_algorithm.h
new file mode 100644
index 0000000..3f08426
--- /dev/null
+++ b/libstdc++-v3/bits/std_algorithm.h
@@ -0,0 +1,40 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_ALGORITHM
+#define _CPP_ALGORITHM 1
+
+#include <bits/stl_algobase.h>
+#include <bits/stl_construct.h>
+#include <bits/stl_uninitialized.h>
+#include <bits/stl_tempbuf.h>
+#include <bits/stl_algo.h>
+
+#endif /* _CPP_ALGORITHM */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_bitset.h b/libstdc++-v3/bits/std_bitset.h
new file mode 100644
index 0000000..ffd147d
--- /dev/null
+++ b/libstdc++-v3/bits/std_bitset.h
@@ -0,0 +1,1216 @@
+/*
+ * Copyright (c) 1998
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_BITSET
+#define _CPP_BITSET 1
+
+// This implementation of bitset<> has a second template parameter,
+// _WordT, which defaults to unsigned long. *YOU SHOULD NOT USE
+// THIS FEATURE*. It is experimental, and it may be removed in
+// future releases.
+
+// A bitset of size N, using words of type _WordT, will have
+// N % (sizeof(_WordT) * CHAR_BIT) unused bits. (They are the high-
+// order bits in the highest word.) It is a class invariant
+// of class bitset<> that those unused bits are always zero.
+
+// Most of the actual code isn't contained in bitset<> itself, but in the
+// base class _Base_bitset. The base class works with whole words, not with
+// individual bits. This allows us to specialize _Base_bitset for the
+// important special case where the bitset is only a single word.
+
+// The C++ standard does not define the precise semantics of operator[].
+// In this implementation the const version of operator[] is equivalent
+// to test(), except that it does no range checking. The non-const version
+// returns a reference to a bit, again without doing any range checking.
+
+
+#include <bits/std_cstddef.h> // for size_t
+#include <bits/std_string.h>
+#include <bits/std_stdexcept.h>
+#include <bits/std_istream.h>
+#include <bits/std_ostream.h>
+#include <bits/std_algorithm.h>
+
+#define __BITS_PER_WORDT(__wt) (CHAR_BIT*sizeof(__wt))
+#define __BITSET_WORDS(__n,__wt) \
+ ((__n) < 1 ? 1 : ((__n) + __BITS_PER_WORDT(__wt) - 1)/__BITS_PER_WORDT(__wt))
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1209
+#endif
+
+// structure to aid in counting bits
+template<bool __dummy>
+struct _Bit_count {
+ static unsigned char _S_bit_count[256];
+};
+
+// Mapping from 8 bit unsigned integers to the index of the first one
+// bit:
+template<bool __dummy>
+struct _First_one {
+ static unsigned char _S_first_one[256];
+};
+
+//
+// Base class: general case.
+//
+
+template<size_t _Nw, class _WordT>
+struct _Base_bitset {
+ _WordT _M_w[_Nw]; // 0 is the least significant word.
+
+ _Base_bitset( void ) { _M_do_reset(); }
+
+ _Base_bitset(unsigned long __val);
+
+ static size_t _S_whichword( size_t __pos ) {
+ return __pos / __BITS_PER_WORDT(_WordT);
+ }
+ static size_t _S_whichbyte( size_t __pos ) {
+ return (__pos % __BITS_PER_WORDT(_WordT)) / CHAR_BIT;
+ }
+ static size_t _S_whichbit( size_t __pos ) {
+ return __pos % __BITS_PER_WORDT(_WordT);
+ }
+ static _WordT _S_maskbit( size_t __pos ) {
+ return (static_cast<_WordT>(1)) << _S_whichbit(__pos);
+ }
+
+ _WordT& _M_getword(size_t __pos) { return _M_w[_S_whichword(__pos)]; }
+ _WordT _M_getword(size_t __pos) const { return _M_w[_S_whichword(__pos)]; }
+
+ _WordT& _M_hiword() { return _M_w[_Nw - 1]; }
+ _WordT _M_hiword() const { return _M_w[_Nw - 1]; }
+
+ void _M_do_and(const _Base_bitset<_Nw,_WordT>& __x) {
+ for ( size_t __i = 0; __i < _Nw; __i++ ) {
+ _M_w[__i] &= __x._M_w[__i];
+ }
+ }
+
+ void _M_do_or(const _Base_bitset<_Nw,_WordT>& __x) {
+ for ( size_t __i = 0; __i < _Nw; __i++ ) {
+ _M_w[__i] |= __x._M_w[__i];
+ }
+ }
+
+ void _M_do_xor(const _Base_bitset<_Nw,_WordT>& __x) {
+ for ( size_t __i = 0; __i < _Nw; __i++ ) {
+ _M_w[__i] ^= __x._M_w[__i];
+ }
+ }
+
+ void _M_do_left_shift(size_t __shift);
+
+ void _M_do_right_shift(size_t __shift);
+
+ void _M_do_flip() {
+ for ( size_t __i = 0; __i < _Nw; __i++ ) {
+ _M_w[__i] = ~_M_w[__i];
+ }
+ }
+
+ void _M_do_set() {
+ for ( size_t __i = 0; __i < _Nw; __i++ ) {
+ _M_w[__i] = ~static_cast<_WordT>(0);
+ }
+ }
+
+ void _M_do_reset() {
+ for ( size_t __i = 0; __i < _Nw; __i++ ) {
+ _M_w[__i] = 0;
+ }
+ }
+
+ bool _M_is_equal(const _Base_bitset<_Nw,_WordT>& __x) const {
+ for (size_t __i = 0; __i < _Nw; ++__i) {
+ if (_M_w[__i] != __x._M_w[__i])
+ return false;
+ }
+ return true;
+ }
+
+ bool _M_is_any() const {
+ for ( size_t __i = 0; __i < __BITSET_WORDS(_Nw,_WordT); __i++ ) {
+ if ( _M_w[__i] != static_cast<_WordT>(0) )
+ return true;
+ }
+ return false;
+ }
+
+ size_t _M_do_count() const {
+ size_t __result = 0;
+ const unsigned char* __byte_ptr = (const unsigned char*)_M_w;
+ const unsigned char* __end_ptr = (const unsigned char*)(_M_w+_Nw);
+
+ while ( __byte_ptr < __end_ptr ) {
+ __result += _Bit_count<true>::_S_bit_count[*__byte_ptr];
+ __byte_ptr++;
+ }
+ return __result;
+ }
+
+ unsigned long _M_do_to_ulong() const;
+
+ // find first "on" bit
+ size_t _M_do_find_first(size_t __not_found) const;
+
+ // find the next "on" bit that follows "prev"
+ size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
+};
+
+//
+// Definitions of non-inline functions from _Base_bitset.
+//
+
+template<size_t _Nw, class _WordT>
+_Base_bitset<_Nw, _WordT>::_Base_bitset(unsigned long __val)
+{
+ _M_do_reset();
+ const size_t __n = min(sizeof(unsigned long)*CHAR_BIT,
+ __BITS_PER_WORDT(_WordT)*_Nw);
+ for(size_t __i = 0; __i < __n; ++__i, __val >>= 1)
+ if ( __val & 0x1 )
+ _M_getword(__i) |= _S_maskbit(__i);
+}
+
+template<size_t _Nw, class _WordT>
+void _Base_bitset<_Nw, _WordT>::_M_do_left_shift(size_t __shift)
+{
+ if (__shift != 0) {
+ const size_t __wshift = __shift / __BITS_PER_WORDT(_WordT);
+ const size_t __offset = __shift % __BITS_PER_WORDT(_WordT);
+ const size_t __sub_offset = __BITS_PER_WORDT(_WordT) - __offset;
+ const _WordT __mask = __offset == static_cast<size_t>(0) ?
+ static_cast<_WordT>(0) :
+ ~static_cast<_WordT>(0);
+ size_t __n = _Nw - 1;
+ for ( ; __n > __wshift; --__n)
+ _M_w[__n] = (_M_w[__n - __wshift] << __offset) |
+ ((_M_w[__n - __wshift - 1] >> __sub_offset) & __mask);
+ if (__n == __wshift)
+ _M_w[__n] = _M_w[0] << __offset;
+ for (size_t __n1 = 0; __n1 < __n; ++__n1)
+ _M_w[__n1] = static_cast<_WordT>(0);
+ }
+}
+
+template<size_t _Nw, class _WordT>
+void _Base_bitset<_Nw, _WordT>::_M_do_right_shift(size_t __shift)
+{
+ if (__shift != 0) {
+ const size_t __wshift = __shift / __BITS_PER_WORDT(_WordT);
+ const size_t __offset = __shift % __BITS_PER_WORDT(_WordT);
+ const size_t __sub_offset = __BITS_PER_WORDT(_WordT) - __offset;
+ const _WordT __mask = __offset == static_cast<size_t>(0) ?
+ static_cast<_WordT>(0) :
+ ~static_cast<_WordT>(0);
+ const size_t __limit = _Nw - __wshift - 1;
+ size_t __n = 0;
+ for ( ; __n < __limit; ++__n)
+ _M_w[__n] = (_M_w[__n + __wshift] >> __offset) |
+ ((_M_w[__n + __wshift + 1] << __sub_offset) & __mask);
+ _M_w[__limit] = _M_w[_Nw-1] >> __offset;
+ for (size_t __n1 = __limit + 1; __n1 < _Nw; ++__n1)
+ _M_w[__n1] = static_cast<_WordT>(0);
+ }
+}
+
+template<size_t _Nw, class _WordT>
+unsigned long _Base_bitset<_Nw, _WordT>::_M_do_to_ulong() const
+{
+ if (sizeof(_WordT) >= sizeof(unsigned long)) {
+ for (size_t __i = 1; __i < _Nw; ++__i)
+ if (_M_w[__i])
+ __STL_THROW(overflow_error("bitset"));
+
+ const _WordT __mask = static_cast<_WordT>(static_cast<unsigned long>(-1));
+ if (_M_w[0] & ~__mask)
+ __STL_THROW(overflow_error("bitset"));
+
+ return static_cast<unsigned long>(_M_w[0] & __mask);
+ }
+ else { // sizeof(_WordT) < sizeof(unsigned long).
+ const size_t __nwords =
+ (sizeof(unsigned long) + sizeof(_WordT) - 1) / sizeof(_WordT);
+
+ size_t __min_nwords = __nwords;
+ if (_Nw > __nwords) {
+ for (size_t __i = __nwords; __i < _Nw; ++__i)
+ if (_M_w[__i])
+ __STL_THROW(overflow_error("bitset"));
+ }
+ else
+ __min_nwords = _Nw;
+
+ // If unsigned long is 8 bytes and _WordT is 6 bytes, then an unsigned
+ // long consists of all of one word plus 2 bytes from another word.
+ const size_t __part = sizeof(unsigned long) % sizeof(_WordT);
+
+ if (__part != 0 && __nwords <= _Nw &&
+ (_M_w[__min_nwords - 1] >> ((sizeof(_WordT) - __part) * CHAR_BIT)) != 0)
+ __STL_THROW(overflow_error("bitset"));
+
+ unsigned long __result = 0;
+ for (size_t __i = 0; __i < __min_nwords; ++__i) {
+ __result |= static_cast<unsigned long>(
+ _M_w[__i]) << (__i * sizeof(_WordT) * CHAR_BIT);
+ }
+ return __result;
+ }
+} // End _M_do_to_ulong
+
+template<size_t _Nw, class _WordT>
+size_t _Base_bitset<_Nw, _WordT>::_M_do_find_first(size_t __not_found) const
+{
+ for ( size_t __i = 0; __i < _Nw; __i++ ) {
+ _WordT __thisword = _M_w[__i];
+ if ( __thisword != static_cast<_WordT>(0) ) {
+ // find byte within word
+ for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
+ unsigned char __this_byte
+ = static_cast<unsigned char>(__thisword & (~(unsigned char)0));
+ if ( __this_byte )
+ return __i*__BITS_PER_WORDT(_WordT) + __j*CHAR_BIT +
+ _First_one<true>::_S_first_one[__this_byte];
+
+ __thisword >>= CHAR_BIT;
+ }
+ }
+ }
+ // not found, so return an indication of failure.
+ return __not_found;
+}
+
+template<size_t _Nw, class _WordT>
+size_t
+_Base_bitset<_Nw, _WordT>::_M_do_find_next(size_t __prev,
+ size_t __not_found) const
+{
+ // make bound inclusive
+ ++__prev;
+
+ // check out of bounds
+ if ( __prev >= _Nw * __BITS_PER_WORDT(_WordT) )
+ return __not_found;
+
+ // search first word
+ size_t __i = _S_whichword(__prev);
+ _WordT __thisword = _M_w[__i];
+
+ // mask off bits below bound
+ __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
+
+ if ( __thisword != static_cast<_WordT>(0) ) {
+ // find byte within word
+ // get first byte into place
+ __thisword >>= _S_whichbyte(__prev) * CHAR_BIT;
+ for ( size_t __j = _S_whichbyte(__prev); __j < sizeof(_WordT); __j++ ) {
+ unsigned char __this_byte
+ = static_cast<unsigned char>(__thisword & (~(unsigned char)0));
+ if ( __this_byte )
+ return __i*__BITS_PER_WORDT(_WordT) + __j*CHAR_BIT +
+ _First_one<true>::_S_first_one[__this_byte];
+
+ __thisword >>= CHAR_BIT;
+ }
+ }
+
+ // check subsequent words
+ __i++;
+ for ( ; __i < _Nw; __i++ ) {
+ _WordT __thisword = _M_w[__i];
+ if ( __thisword != static_cast<_WordT>(0) ) {
+ // find byte within word
+ for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
+ unsigned char __this_byte
+ = static_cast<unsigned char>(__thisword & (~(unsigned char)0));
+ if ( __this_byte )
+ return __i*__BITS_PER_WORDT(_WordT) + __j*CHAR_BIT +
+ _First_one<true>::_S_first_one[__this_byte];
+
+ __thisword >>= CHAR_BIT;
+ }
+ }
+ }
+
+ // not found, so return an indication of failure.
+ return __not_found;
+} // end _M_do_find_next
+
+
+// ------------------------------------------------------------
+
+//
+// Base class: specialization for a single word.
+//
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template<class _WordT>
+struct _Base_bitset<1, _WordT> {
+ _WordT _M_w;
+
+ _Base_bitset( void ) { _M_do_reset(); }
+
+ _Base_bitset(unsigned long __val);
+
+ static size_t _S_whichword( size_t __pos ) {
+ return __pos / __BITS_PER_WORDT(_WordT);
+ }
+ static size_t _S_whichbyte( size_t __pos ) {
+ return (__pos % __BITS_PER_WORDT(_WordT)) / CHAR_BIT;
+ }
+ static size_t _S_whichbit( size_t __pos ) {
+ return __pos % __BITS_PER_WORDT(_WordT);
+ }
+ static _WordT _S_maskbit( size_t __pos ) {
+ return (static_cast<_WordT>(1)) << _S_whichbit(__pos);
+ }
+
+ _WordT& _M_getword(size_t) { return _M_w; }
+ _WordT _M_getword(size_t) const { return _M_w; }
+
+ _WordT& _M_hiword() { return _M_w; }
+ _WordT _M_hiword() const { return _M_w; }
+
+ void _M_do_and(const _Base_bitset<1,_WordT>& __x) { _M_w &= __x._M_w; }
+ void _M_do_or(const _Base_bitset<1,_WordT>& __x) { _M_w |= __x._M_w; }
+ void _M_do_xor(const _Base_bitset<1,_WordT>& __x) { _M_w ^= __x._M_w; }
+ void _M_do_left_shift(size_t __shift) { _M_w <<= __shift; }
+ void _M_do_right_shift(size_t __shift) { _M_w >>= __shift; }
+ void _M_do_flip() { _M_w = ~_M_w; }
+ void _M_do_set() { _M_w = ~static_cast<_WordT>(0); }
+ void _M_do_reset() { _M_w = 0; }
+
+ bool _M_is_equal(const _Base_bitset<1,_WordT>& __x) const {
+ return _M_w == __x._M_w;
+ }
+ bool _M_is_any() const {
+ return _M_w != 0;
+ }
+
+ size_t _M_do_count() const {
+ size_t __result = 0;
+ const unsigned char* __byte_ptr = (const unsigned char*)&_M_w;
+ const unsigned char* __end_ptr = ((const unsigned char*)&_M_w)+sizeof(_M_w);
+ while ( __byte_ptr < __end_ptr ) {
+ __result += _Bit_count<true>::_S_bit_count[*__byte_ptr];
+ __byte_ptr++;
+ }
+ return __result;
+ }
+
+ unsigned long _M_do_to_ulong() const {
+ if (sizeof(_WordT) <= sizeof(unsigned long))
+ return static_cast<unsigned long>(_M_w);
+ else {
+ const _WordT __mask = static_cast<_WordT>(static_cast<unsigned long>(-1));
+ if (_M_w & ~__mask)
+ __STL_THROW(overflow_error("bitset"));
+ return static_cast<unsigned long>(_M_w);
+ }
+ }
+
+ size_t _M_do_find_first(size_t __not_found) const;
+
+ // find the next "on" bit that follows "prev"
+ size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
+
+};
+
+//
+// Definitions of non-inline functions from the single-word version of
+// _Base_bitset.
+//
+
+template <class _WordT>
+_Base_bitset<1, _WordT>::_Base_bitset(unsigned long __val)
+{
+ _M_do_reset();
+ const size_t __n = min(sizeof(unsigned long)*CHAR_BIT,
+ __BITS_PER_WORDT(_WordT)*_Nw);
+ for(size_t __i = 0; __i < __n; ++__i, __val >>= 1)
+ if ( __val & 0x1 )
+ _M_w |= _S_maskbit(__i);
+}
+
+template <class _WordT>
+size_t _Base_bitset<1, _WordT>::_M_do_find_first(size_t __not_found) const
+{
+ _WordT __thisword = _M_w;
+
+ if ( __thisword != static_cast<_WordT>(0) ) {
+ // find byte within word
+ for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
+ unsigned char __this_byte
+ = static_cast<unsigned char>(__thisword & (~(unsigned char)0));
+ if ( __this_byte )
+ return __j*CHAR_BIT + _First_one<true>::_S_first_one[__this_byte];
+
+ __thisword >>= CHAR_BIT;
+ }
+ }
+ // not found, so return a value that indicates failure.
+ return __not_found;
+}
+
+template <class _WordT>
+size_t
+_Base_bitset<1, _WordT>::_M_do_find_next(size_t __prev,
+ size_t __not_found ) const
+{
+ // make bound inclusive
+ ++__prev;
+
+ // check out of bounds
+ if ( __prev >= __BITS_PER_WORDT(_WordT) )
+ return __not_found;
+
+ // search first (and only) word
+ _WordT __thisword = _M_w;
+
+ // mask off bits below bound
+ __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
+
+ if ( __thisword != static_cast<_WordT>(0) ) {
+ // find byte within word
+ // get first byte into place
+ __thisword >>= _S_whichbyte(__prev) * CHAR_BIT;
+ for ( size_t __j = _S_whichbyte(__prev); __j < sizeof(_WordT); __j++ ) {
+ unsigned char __this_byte
+ = static_cast<unsigned char>(__thisword & (~(unsigned char)0));
+ if ( __this_byte )
+ return __j*CHAR_BIT + _First_one<true>::_S_first_one[__this_byte];
+
+ __thisword >>= CHAR_BIT;
+ }
+ }
+
+ // not found, so return a value that indicates failure.
+ return __not_found;
+} // end _M_do_find_next
+
+//
+// One last specialization: _M_do_to_ulong() and the constructor from
+// unsigned long are very simple if the bitset consists of a single
+// word of type unsigned long.
+//
+
+__STL_TEMPLATE_NULL
+inline unsigned long
+_Base_bitset<1, unsigned long>::_M_do_to_ulong() const { return _M_w; }
+
+__STL_TEMPLATE_NULL
+inline _Base_bitset<1, unsigned long>::_Base_bitset(unsigned long __val) {
+ _M_w = __val;
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+// ------------------------------------------------------------
+// Helper class to zero out the unused high-order bits in the highest word.
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _WordT, size_t _Extrabits> struct _Sanitize {
+ static void _M_do_sanitize(_WordT& __val)
+ { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
+};
+
+template <class _WordT> struct _Sanitize<_WordT, 0> {
+ static void _M_do_sanitize(_WordT) {}
+};
+
+#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _WordT, size_t _Extrabits> struct _Sanitize {
+ static void _M_do_sanitize(_WordT& __val) {
+ if (_Extrabits != 0)
+ __val &= ~((~static_cast<_WordT>(0)) << _Extrabits);
+ }
+};
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+// ------------------------------------------------------------
+// Class bitset.
+// _Nb may be any nonzero number of type size_t.
+// Type _WordT may be any unsigned integral type.
+
+template<size_t _Nb, class _WordT = unsigned long>
+class bitset : private _Base_bitset<__BITSET_WORDS(_Nb,_WordT), _WordT>
+{
+private:
+ typedef _Base_bitset<__BITSET_WORDS(_Nb,_WordT), _WordT> _Base;
+
+ // Import base's protected interface. Necessary because of new template
+ // name resolution rules.
+
+#ifdef __STL_HAS_NAMESPACES
+ using _Base::_S_whichword;
+ using _Base::_S_whichbyte;
+ using _Base::_S_whichbit;
+ using _Base::_S_maskbit;
+ using _Base::_M_getword;
+ using _Base::_M_hiword;
+ using _Base::_M_do_and;
+ using _Base::_M_do_or;
+ using _Base::_M_do_xor;
+ using _Base::_M_do_left_shift;
+ using _Base::_M_do_right_shift;
+ using _Base::_M_do_flip;
+ using _Base::_M_do_set;
+ using _Base::_M_do_reset;
+ using _Base::_M_is_equal;
+ using _Base::_M_is_any;
+ using _Base::_M_do_count;
+ using _Base::_M_do_to_ulong;
+ using _Base::_M_do_find_first;
+ using _Base::_M_do_find_next;
+#endif /* __STL_HAS_NAMESPACES */
+
+private:
+ void _M_do_sanitize() {
+ _Sanitize<_WordT,_Nb%__BITS_PER_WORDT(_WordT) >
+ ::_M_do_sanitize(_M_hiword());
+ }
+
+public:
+
+ // bit reference:
+ class reference;
+ friend class reference;
+
+ class reference {
+ friend class bitset;
+
+ _WordT *_M_wp;
+ size_t _M_bpos;
+
+ // left undefined
+ reference();
+
+ public:
+ reference( bitset& __b, size_t __pos ) {
+ _M_wp = &__b._M_getword(__pos);
+ _M_bpos = _S_whichbit(__pos);
+ }
+
+ ~reference() {}
+
+ // for b[i] = __x;
+ reference& operator=(bool __x) {
+ if ( __x )
+ *_M_wp |= _S_maskbit(_M_bpos);
+ else
+ *_M_wp &= ~_S_maskbit(_M_bpos);
+
+ return *this;
+ }
+
+ // for b[i] = b[__j];
+ reference& operator=(const reference& __j) {
+ if ( (*(__j._M_wp) & _S_maskbit(__j._M_bpos)) )
+ *_M_wp |= _S_maskbit(_M_bpos);
+ else
+ *_M_wp &= ~_S_maskbit(_M_bpos);
+
+ return *this;
+ }
+
+ // flips the bit
+ bool operator~() const { return (*(_M_wp) & _S_maskbit(_M_bpos)) == 0; }
+
+ // for __x = b[i];
+ operator bool() const { return (*(_M_wp) & _S_maskbit(_M_bpos)) != 0; }
+
+ // for b[i].flip();
+ reference& flip() {
+ *_M_wp ^= _S_maskbit(_M_bpos);
+ return *this;
+ }
+ };
+
+ // 23.3.5.1 constructors:
+ bitset() {}
+ bitset(unsigned long __val) :
+ _Base_bitset<__BITSET_WORDS(_Nb,_WordT), _WordT>(__val) {}
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template<class _CharT, class _Traits, class _Alloc>
+ explicit bitset(const basic_string<_CharT,_Traits,_Alloc>& __s,
+ size_t __pos = 0)
+ : _Base()
+ {
+ if (__pos > __s.size())
+ __STL_THROW(out_of_range("bitset"));
+ _M_copy_from_string(__s, __pos,
+ basic_string<_CharT,_Traits,_Alloc>::npos);
+ }
+
+ template<class _CharT, class _Traits, class _Alloc>
+ bitset(const basic_string<_CharT, _Traits, _Alloc>& __s,
+ size_t __pos,
+ size_t __n)
+ : _Base()
+ {
+ if (__pos > __s.size())
+ __STL_THROW(out_of_range("bitset"));
+ _M_copy_from_string(__s, __pos, __n);
+ }
+#else
+ explicit bitset(const basic_string<char>& __s,
+ size_t __pos = 0,
+ size_t __n = basic_string<char>::npos)
+ : _Base()
+ {
+ if (__pos > __s.size())
+ __STL_THROW(out_of_range("bitset"));
+ _M_copy_from_string(__s, __pos, __n);
+ }
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ // 23.3.5.2 bitset operations:
+ bitset<_Nb,_WordT>& operator&=(const bitset<_Nb,_WordT>& __rhs) {
+ _M_do_and(__rhs);
+ return *this;
+ }
+
+ bitset<_Nb,_WordT>& operator|=(const bitset<_Nb,_WordT>& __rhs) {
+ _M_do_or(__rhs);
+ return *this;
+ }
+
+ bitset<_Nb,_WordT>& operator^=(const bitset<_Nb,_WordT>& __rhs) {
+ _M_do_xor(__rhs);
+ return *this;
+ }
+
+ bitset<_Nb,_WordT>& operator<<=(size_t __pos) {
+ _M_do_left_shift(__pos);
+ _M_do_sanitize();
+ return *this;
+ }
+
+ bitset<_Nb,_WordT>& operator>>=(size_t __pos) {
+ _M_do_right_shift(__pos);
+ _M_do_sanitize();
+ return *this;
+ }
+
+ //
+ // Extension:
+ // Versions of single-bit set, reset, flip, test with no range checking.
+ //
+
+ bitset<_Nb,_WordT>& _Unchecked_set(size_t __pos) {
+ _M_getword(__pos) |= _S_maskbit(__pos);
+ return *this;
+ }
+
+ bitset<_Nb,_WordT>& _Unchecked_set(size_t __pos, int __val) {
+ if (__val)
+ _M_getword(__pos) |= _S_maskbit(__pos);
+ else
+ _M_getword(__pos) &= ~_S_maskbit(__pos);
+
+ return *this;
+ }
+
+ bitset<_Nb,_WordT>& _Unchecked_reset(size_t __pos) {
+ _M_getword(__pos) &= ~_S_maskbit(__pos);
+ return *this;
+ }
+
+ bitset<_Nb,_WordT>& _Unchecked_flip(size_t __pos) {
+ _M_getword(__pos) ^= _S_maskbit(__pos);
+ return *this;
+ }
+
+ bool _Unchecked_test(size_t __pos) const {
+ return (_M_getword(__pos) & _S_maskbit(__pos)) != static_cast<_WordT>(0);
+ }
+
+ // Set, reset, and flip.
+
+ bitset<_Nb,_WordT>& set() {
+ _M_do_set();
+ _M_do_sanitize();
+ return *this;
+ }
+
+ bitset<_Nb,_WordT>& set(size_t __pos) {
+ if (__pos >= _Nb)
+ __STL_THROW(out_of_range("bitset"));
+
+ return _Unchecked_set(__pos);
+ }
+
+ bitset<_Nb,_WordT>& set(size_t __pos, int __val) {
+ if (__pos >= _Nb)
+ __STL_THROW(out_of_range("bitset"));
+
+ return _Unchecked_set(__pos, __val);
+ }
+
+ bitset<_Nb,_WordT>& reset() {
+ _M_do_reset();
+ return *this;
+ }
+
+ bitset<_Nb,_WordT>& reset(size_t __pos) {
+ if (__pos >= _Nb)
+ __STL_THROW(out_of_range("bitset"));
+
+ return _Unchecked_reset(__pos);
+ }
+
+ bitset<_Nb,_WordT>& flip() {
+ _M_do_flip();
+ _M_do_sanitize();
+ return *this;
+ }
+
+ bitset<_Nb,_WordT>& flip(size_t __pos) {
+ if (__pos >= _Nb)
+ __STL_THROW(out_of_range("bitset"));
+
+ return _Unchecked_flip(__pos);
+ }
+
+ bitset<_Nb,_WordT> operator~() const {
+ return bitset<_Nb,_WordT>(*this).flip();
+ }
+
+ // element access:
+ //for b[i];
+ reference operator[](size_t __pos) { return reference(*this,__pos); }
+ bool operator[](size_t __pos) const { return _Unchecked_test(__pos); }
+
+ unsigned long to_ulong() const { return _M_do_to_ulong(); }
+
+#if defined(__STL_MEMBER_TEMPLATES) && \
+ defined(__STL_EXPLICIT_FUNCTION_TMPL_ARGS)
+
+ template <class _CharT, class _Traits, class _Alloc>
+ basic_string<_CharT, _Traits, _Alloc> to_string() const {
+ basic_string<_CharT, _Traits, _Alloc> __result;
+ _M_copy_to_string(__result);
+ return __result;
+ }
+
+#endif /* member templates and explicit function template args */
+
+ // Helper functions for string operations.
+#ifdef __STL_MEMBER_TEMPLATES
+
+ template<class _CharT, class _Traits, class _Alloc>
+ void _M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s,
+ size_t,
+ size_t);
+
+ template<class _CharT, class _Traits, class _Alloc>
+ void _M_copy_to_string(basic_string<_CharT,_Traits,_Alloc>&) const;
+
+#else /* __STL_MEMBER_TEMPLATES */
+
+ void _M_copy_from_string(const basic_string<char>&, size_t, size_t);
+ void _M_copy_to_string(basic_string<char>&) const;
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ size_t count() const { return _M_do_count(); }
+
+ size_t size() const { return _Nb; }
+
+ bool operator==(const bitset<_Nb,_WordT>& __rhs) const {
+ return _M_is_equal(__rhs);
+ }
+ bool operator!=(const bitset<_Nb,_WordT>& __rhs) const {
+ return !_M_is_equal(__rhs);
+ }
+
+ bool test(size_t __pos) const {
+ if (__pos > _Nb)
+ __STL_THROW(out_of_range("bitset"));
+
+ return _Unchecked_test(__pos);
+ }
+
+ bool any() const { return _M_is_any(); }
+ bool none() const { return !_M_is_any(); }
+
+ bitset<_Nb,_WordT> operator<<(size_t __pos) const
+ { return bitset<_Nb,_WordT>(*this) <<= __pos; }
+ bitset<_Nb,_WordT> operator>>(size_t __pos) const
+ { return bitset<_Nb,_WordT>(*this) >>= __pos; }
+
+ //
+ // EXTENSIONS: bit-find operations. These operations are
+ // experimental, and are subject to change or removal in future
+ // versions.
+ //
+
+ // find the index of the first "on" bit
+ size_t _Find_first() const
+ { return _M_do_find_first(_Nb); }
+
+ // find the index of the next "on" bit after prev
+ size_t _Find_next( size_t __prev ) const
+ { return _M_do_find_next(__prev, _Nb); }
+
+};
+
+//
+// Definitions of non-inline member functions.
+//
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+template <size_t _Nb, class _WordT>
+template<class _CharT, class _Traits, class _Alloc>
+void bitset<_Nb, _WordT>
+ ::_M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s,
+ size_t __pos,
+ size_t __n)
+{
+ reset();
+ const size_t __nbits = min(_Nb, min(__n, __s.size() - __pos));
+ for (size_t __i = 0; __i < __nbits; ++__i) {
+ switch(__s[__pos + __nbits - __i - 1]) {
+ case '0':
+ break;
+ case '1':
+ set(__i);
+ break;
+ default:
+ __STL_THROW(invalid_argument("bitset"));
+ }
+ }
+}
+
+template <size_t _Nb, class _WordT>
+template <class _CharT, class _Traits, class _Alloc>
+void bitset<_Nb, _WordT>
+ ::_M_copy_to_string(basic_string<_CharT, _Traits, _Alloc>& __s) const
+{
+ __s.assign(_Nb, '0');
+
+ for (size_t __i = 0; __i < _Nb; ++__i)
+ if (_Unchecked_test(__i))
+ __s[_Nb - 1 - __i] = '1';
+}
+
+#else /* __STL_MEMBER_TEMPLATES */
+
+template <size_t _Nb, class _WordT>
+void bitset<_Nb, _WordT>::_M_copy_from_string(const basic_string<char>& __s,
+ size_t __pos, size_t __n)
+{
+ reset();
+ size_t __tmp = _Nb;
+ const size_t __nbits = min(__tmp, min(__n, __s.size() - __pos));
+ for (size_t __i = 0; __i < __nbits; ++__i) {
+ switch(__s[__pos + __nbits - __i - 1]) {
+ case '0':
+ break;
+ case '1':
+ set(__i);
+ break;
+ default:
+ __STL_THROW(invalid_argument("bitset"));
+ }
+ }
+}
+
+template <size_t _Nb, class _WordT>
+void bitset<_Nb, _WordT>::_M_copy_to_string(basic_string<char>& __s) const
+{
+ __s.assign(_Nb, '0');
+
+ for (size_t __i = 0; __i < _Nb; ++__i)
+ if (_Unchecked_test(__i))
+ __s[_Nb - 1 - __i] = '1';
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+// ------------------------------------------------------------
+
+//
+// 23.3.5.3 bitset operations:
+//
+
+template <size_t _Nb, class _WordT>
+inline bitset<_Nb,_WordT> operator&(const bitset<_Nb,_WordT>& __x,
+ const bitset<_Nb,_WordT>& __y) {
+ bitset<_Nb,_WordT> __result(__x);
+ __result &= __y;
+ return __result;
+}
+
+
+template <size_t _Nb, class _WordT>
+inline bitset<_Nb,_WordT> operator|(const bitset<_Nb,_WordT>& __x,
+ const bitset<_Nb,_WordT>& __y) {
+ bitset<_Nb,_WordT> __result(__x);
+ __result |= __y;
+ return __result;
+}
+
+template <size_t _Nb, class _WordT>
+inline bitset<_Nb,_WordT> operator^(const bitset<_Nb,_WordT>& __x,
+ const bitset<_Nb,_WordT>& __y) {
+ bitset<_Nb,_WordT> __result(__x);
+ __result ^= __y;
+ return __result;
+}
+
+#ifdef __STL_USE_NEW_IOSTREAMS
+
+template <class _CharT, class _Traits, size_t _Nb, class _WordT>
+basic_istream<_CharT, _Traits>&
+operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb,_WordT>& __x)
+{
+ basic_string<_CharT, _Traits> __tmp;
+ __tmp.reserve(_Nb);
+
+ // Skip whitespace
+ typename basic_istream<_CharT, _Traits>::sentry __sentry(__is);
+ if (__sentry) {
+ basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf();
+ for (size_t __i = 0; __i < _Nb; ++__i) {
+ static _Traits::int_type __eof = _Traits::eof();
+
+ typename _Traits::int_type __c1 = __buf->sbumpc();
+ if (_Traits::eq_int_type(__c1, __eof)) {
+ __is.setstate(ios_base::eofbit);
+ break;
+ }
+ else {
+ char __c2 = _Traits::to_char_type(__c1);
+ char __c = __is.narrow(__c2, '*');
+
+ if (__c == '0' || __c == '1')
+ __tmp.push_back(__c);
+ else if (_Traits::eq_int_type(__buf->sputbackc(__c2), __eof)) {
+ __is.setstate(ios_base::failbit);
+ break;
+ }
+ }
+ }
+
+ if (__tmp.empty())
+ __is.setstate(ios_base::failbit);
+ else
+ __x._M_copy_from_string(__tmp, static_cast<size_t>(0), _Nb);
+ }
+
+ return __is;
+}
+
+template <class _CharT, class _Traits, size_t _Nb, class _WordT>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+ const bitset<_Nb,_WordT>& __x)
+{
+ basic_string<_CharT, _Traits> __tmp;
+ __x._M_copy_to_string(__tmp);
+ return __os << __tmp;
+}
+
+#else /* __STL_USE_NEW_IOSTREAMS */
+
+template <size_t _Nb, class _WordT>
+istream&
+operator>>(istream& __is, bitset<_Nb,_WordT>& __x) {
+ string __tmp;
+ __tmp.reserve(_Nb);
+
+ if (__is.flags() & ios::skipws) {
+ char __c;
+ do
+ __is.get(__c);
+ while (__is && isspace(__c));
+ if (__is)
+ __is.putback(__c);
+ }
+
+ for (size_t __i = 0; __i < _Nb; ++__i) {
+ char __c;
+ __is.get(__c);
+
+ if (!__is)
+ break;
+ else if (__c != '0' && __c != '1') {
+ __is.putback(__c);
+ break;
+ }
+ else
+ __tmp.push_back(__c);
+ }
+
+ if (__tmp.empty())
+ __is.clear(__is.rdstate() | ios::failbit);
+ else
+ __x._M_copy_from_string(__tmp, static_cast<size_t>(0), _Nb);
+
+ return __is;
+}
+
+template <size_t _Nb, class _WordT>
+ostream& operator<<(ostream& __os, const bitset<_Nb,_WordT>& __x) {
+ string __tmp;
+ __x._M_copy_to_string(__tmp);
+ return __os << __tmp;
+}
+
+#endif /* __STL_USE_NEW_IOSTREAMS */
+
+// ------------------------------------------------------------
+// Lookup tables for find and count operations.
+
+template<bool __dummy>
+unsigned char _Bit_count<__dummy>::_S_bit_count[] = {
+ 0, /* 0 */ 1, /* 1 */ 1, /* 2 */ 2, /* 3 */ 1, /* 4 */
+ 2, /* 5 */ 2, /* 6 */ 3, /* 7 */ 1, /* 8 */ 2, /* 9 */
+ 2, /* 10 */ 3, /* 11 */ 2, /* 12 */ 3, /* 13 */ 3, /* 14 */
+ 4, /* 15 */ 1, /* 16 */ 2, /* 17 */ 2, /* 18 */ 3, /* 19 */
+ 2, /* 20 */ 3, /* 21 */ 3, /* 22 */ 4, /* 23 */ 2, /* 24 */
+ 3, /* 25 */ 3, /* 26 */ 4, /* 27 */ 3, /* 28 */ 4, /* 29 */
+ 4, /* 30 */ 5, /* 31 */ 1, /* 32 */ 2, /* 33 */ 2, /* 34 */
+ 3, /* 35 */ 2, /* 36 */ 3, /* 37 */ 3, /* 38 */ 4, /* 39 */
+ 2, /* 40 */ 3, /* 41 */ 3, /* 42 */ 4, /* 43 */ 3, /* 44 */
+ 4, /* 45 */ 4, /* 46 */ 5, /* 47 */ 2, /* 48 */ 3, /* 49 */
+ 3, /* 50 */ 4, /* 51 */ 3, /* 52 */ 4, /* 53 */ 4, /* 54 */
+ 5, /* 55 */ 3, /* 56 */ 4, /* 57 */ 4, /* 58 */ 5, /* 59 */
+ 4, /* 60 */ 5, /* 61 */ 5, /* 62 */ 6, /* 63 */ 1, /* 64 */
+ 2, /* 65 */ 2, /* 66 */ 3, /* 67 */ 2, /* 68 */ 3, /* 69 */
+ 3, /* 70 */ 4, /* 71 */ 2, /* 72 */ 3, /* 73 */ 3, /* 74 */
+ 4, /* 75 */ 3, /* 76 */ 4, /* 77 */ 4, /* 78 */ 5, /* 79 */
+ 2, /* 80 */ 3, /* 81 */ 3, /* 82 */ 4, /* 83 */ 3, /* 84 */
+ 4, /* 85 */ 4, /* 86 */ 5, /* 87 */ 3, /* 88 */ 4, /* 89 */
+ 4, /* 90 */ 5, /* 91 */ 4, /* 92 */ 5, /* 93 */ 5, /* 94 */
+ 6, /* 95 */ 2, /* 96 */ 3, /* 97 */ 3, /* 98 */ 4, /* 99 */
+ 3, /* 100 */ 4, /* 101 */ 4, /* 102 */ 5, /* 103 */ 3, /* 104 */
+ 4, /* 105 */ 4, /* 106 */ 5, /* 107 */ 4, /* 108 */ 5, /* 109 */
+ 5, /* 110 */ 6, /* 111 */ 3, /* 112 */ 4, /* 113 */ 4, /* 114 */
+ 5, /* 115 */ 4, /* 116 */ 5, /* 117 */ 5, /* 118 */ 6, /* 119 */
+ 4, /* 120 */ 5, /* 121 */ 5, /* 122 */ 6, /* 123 */ 5, /* 124 */
+ 6, /* 125 */ 6, /* 126 */ 7, /* 127 */ 1, /* 128 */ 2, /* 129 */
+ 2, /* 130 */ 3, /* 131 */ 2, /* 132 */ 3, /* 133 */ 3, /* 134 */
+ 4, /* 135 */ 2, /* 136 */ 3, /* 137 */ 3, /* 138 */ 4, /* 139 */
+ 3, /* 140 */ 4, /* 141 */ 4, /* 142 */ 5, /* 143 */ 2, /* 144 */
+ 3, /* 145 */ 3, /* 146 */ 4, /* 147 */ 3, /* 148 */ 4, /* 149 */
+ 4, /* 150 */ 5, /* 151 */ 3, /* 152 */ 4, /* 153 */ 4, /* 154 */
+ 5, /* 155 */ 4, /* 156 */ 5, /* 157 */ 5, /* 158 */ 6, /* 159 */
+ 2, /* 160 */ 3, /* 161 */ 3, /* 162 */ 4, /* 163 */ 3, /* 164 */
+ 4, /* 165 */ 4, /* 166 */ 5, /* 167 */ 3, /* 168 */ 4, /* 169 */
+ 4, /* 170 */ 5, /* 171 */ 4, /* 172 */ 5, /* 173 */ 5, /* 174 */
+ 6, /* 175 */ 3, /* 176 */ 4, /* 177 */ 4, /* 178 */ 5, /* 179 */
+ 4, /* 180 */ 5, /* 181 */ 5, /* 182 */ 6, /* 183 */ 4, /* 184 */
+ 5, /* 185 */ 5, /* 186 */ 6, /* 187 */ 5, /* 188 */ 6, /* 189 */
+ 6, /* 190 */ 7, /* 191 */ 2, /* 192 */ 3, /* 193 */ 3, /* 194 */
+ 4, /* 195 */ 3, /* 196 */ 4, /* 197 */ 4, /* 198 */ 5, /* 199 */
+ 3, /* 200 */ 4, /* 201 */ 4, /* 202 */ 5, /* 203 */ 4, /* 204 */
+ 5, /* 205 */ 5, /* 206 */ 6, /* 207 */ 3, /* 208 */ 4, /* 209 */
+ 4, /* 210 */ 5, /* 211 */ 4, /* 212 */ 5, /* 213 */ 5, /* 214 */
+ 6, /* 215 */ 4, /* 216 */ 5, /* 217 */ 5, /* 218 */ 6, /* 219 */
+ 5, /* 220 */ 6, /* 221 */ 6, /* 222 */ 7, /* 223 */ 3, /* 224 */
+ 4, /* 225 */ 4, /* 226 */ 5, /* 227 */ 4, /* 228 */ 5, /* 229 */
+ 5, /* 230 */ 6, /* 231 */ 4, /* 232 */ 5, /* 233 */ 5, /* 234 */
+ 6, /* 235 */ 5, /* 236 */ 6, /* 237 */ 6, /* 238 */ 7, /* 239 */
+ 4, /* 240 */ 5, /* 241 */ 5, /* 242 */ 6, /* 243 */ 5, /* 244 */
+ 6, /* 245 */ 6, /* 246 */ 7, /* 247 */ 5, /* 248 */ 6, /* 249 */
+ 6, /* 250 */ 7, /* 251 */ 6, /* 252 */ 7, /* 253 */ 7, /* 254 */
+ 8 /* 255 */
+}; // end _S_bit_count
+
+template<bool __dummy>
+unsigned char _First_one<__dummy>::_S_first_one[] = {
+ 0, /* 0 */ 0, /* 1 */ 1, /* 2 */ 0, /* 3 */ 2, /* 4 */
+ 0, /* 5 */ 1, /* 6 */ 0, /* 7 */ 3, /* 8 */ 0, /* 9 */
+ 1, /* 10 */ 0, /* 11 */ 2, /* 12 */ 0, /* 13 */ 1, /* 14 */
+ 0, /* 15 */ 4, /* 16 */ 0, /* 17 */ 1, /* 18 */ 0, /* 19 */
+ 2, /* 20 */ 0, /* 21 */ 1, /* 22 */ 0, /* 23 */ 3, /* 24 */
+ 0, /* 25 */ 1, /* 26 */ 0, /* 27 */ 2, /* 28 */ 0, /* 29 */
+ 1, /* 30 */ 0, /* 31 */ 5, /* 32 */ 0, /* 33 */ 1, /* 34 */
+ 0, /* 35 */ 2, /* 36 */ 0, /* 37 */ 1, /* 38 */ 0, /* 39 */
+ 3, /* 40 */ 0, /* 41 */ 1, /* 42 */ 0, /* 43 */ 2, /* 44 */
+ 0, /* 45 */ 1, /* 46 */ 0, /* 47 */ 4, /* 48 */ 0, /* 49 */
+ 1, /* 50 */ 0, /* 51 */ 2, /* 52 */ 0, /* 53 */ 1, /* 54 */
+ 0, /* 55 */ 3, /* 56 */ 0, /* 57 */ 1, /* 58 */ 0, /* 59 */
+ 2, /* 60 */ 0, /* 61 */ 1, /* 62 */ 0, /* 63 */ 6, /* 64 */
+ 0, /* 65 */ 1, /* 66 */ 0, /* 67 */ 2, /* 68 */ 0, /* 69 */
+ 1, /* 70 */ 0, /* 71 */ 3, /* 72 */ 0, /* 73 */ 1, /* 74 */
+ 0, /* 75 */ 2, /* 76 */ 0, /* 77 */ 1, /* 78 */ 0, /* 79 */
+ 4, /* 80 */ 0, /* 81 */ 1, /* 82 */ 0, /* 83 */ 2, /* 84 */
+ 0, /* 85 */ 1, /* 86 */ 0, /* 87 */ 3, /* 88 */ 0, /* 89 */
+ 1, /* 90 */ 0, /* 91 */ 2, /* 92 */ 0, /* 93 */ 1, /* 94 */
+ 0, /* 95 */ 5, /* 96 */ 0, /* 97 */ 1, /* 98 */ 0, /* 99 */
+ 2, /* 100 */ 0, /* 101 */ 1, /* 102 */ 0, /* 103 */ 3, /* 104 */
+ 0, /* 105 */ 1, /* 106 */ 0, /* 107 */ 2, /* 108 */ 0, /* 109 */
+ 1, /* 110 */ 0, /* 111 */ 4, /* 112 */ 0, /* 113 */ 1, /* 114 */
+ 0, /* 115 */ 2, /* 116 */ 0, /* 117 */ 1, /* 118 */ 0, /* 119 */
+ 3, /* 120 */ 0, /* 121 */ 1, /* 122 */ 0, /* 123 */ 2, /* 124 */
+ 0, /* 125 */ 1, /* 126 */ 0, /* 127 */ 7, /* 128 */ 0, /* 129 */
+ 1, /* 130 */ 0, /* 131 */ 2, /* 132 */ 0, /* 133 */ 1, /* 134 */
+ 0, /* 135 */ 3, /* 136 */ 0, /* 137 */ 1, /* 138 */ 0, /* 139 */
+ 2, /* 140 */ 0, /* 141 */ 1, /* 142 */ 0, /* 143 */ 4, /* 144 */
+ 0, /* 145 */ 1, /* 146 */ 0, /* 147 */ 2, /* 148 */ 0, /* 149 */
+ 1, /* 150 */ 0, /* 151 */ 3, /* 152 */ 0, /* 153 */ 1, /* 154 */
+ 0, /* 155 */ 2, /* 156 */ 0, /* 157 */ 1, /* 158 */ 0, /* 159 */
+ 5, /* 160 */ 0, /* 161 */ 1, /* 162 */ 0, /* 163 */ 2, /* 164 */
+ 0, /* 165 */ 1, /* 166 */ 0, /* 167 */ 3, /* 168 */ 0, /* 169 */
+ 1, /* 170 */ 0, /* 171 */ 2, /* 172 */ 0, /* 173 */ 1, /* 174 */
+ 0, /* 175 */ 4, /* 176 */ 0, /* 177 */ 1, /* 178 */ 0, /* 179 */
+ 2, /* 180 */ 0, /* 181 */ 1, /* 182 */ 0, /* 183 */ 3, /* 184 */
+ 0, /* 185 */ 1, /* 186 */ 0, /* 187 */ 2, /* 188 */ 0, /* 189 */
+ 1, /* 190 */ 0, /* 191 */ 6, /* 192 */ 0, /* 193 */ 1, /* 194 */
+ 0, /* 195 */ 2, /* 196 */ 0, /* 197 */ 1, /* 198 */ 0, /* 199 */
+ 3, /* 200 */ 0, /* 201 */ 1, /* 202 */ 0, /* 203 */ 2, /* 204 */
+ 0, /* 205 */ 1, /* 206 */ 0, /* 207 */ 4, /* 208 */ 0, /* 209 */
+ 1, /* 210 */ 0, /* 211 */ 2, /* 212 */ 0, /* 213 */ 1, /* 214 */
+ 0, /* 215 */ 3, /* 216 */ 0, /* 217 */ 1, /* 218 */ 0, /* 219 */
+ 2, /* 220 */ 0, /* 221 */ 1, /* 222 */ 0, /* 223 */ 5, /* 224 */
+ 0, /* 225 */ 1, /* 226 */ 0, /* 227 */ 2, /* 228 */ 0, /* 229 */
+ 1, /* 230 */ 0, /* 231 */ 3, /* 232 */ 0, /* 233 */ 1, /* 234 */
+ 0, /* 235 */ 2, /* 236 */ 0, /* 237 */ 1, /* 238 */ 0, /* 239 */
+ 4, /* 240 */ 0, /* 241 */ 1, /* 242 */ 0, /* 243 */ 2, /* 244 */
+ 0, /* 245 */ 1, /* 246 */ 0, /* 247 */ 3, /* 248 */ 0, /* 249 */
+ 1, /* 250 */ 0, /* 251 */ 2, /* 252 */ 0, /* 253 */ 1, /* 254 */
+ 0, /* 255 */
+}; // end _First_one
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1209
+#endif
+
+__STL_END_NAMESPACE
+
+
+#undef __BITS_PER_WORDT
+#undef __BITSET_WORDS
+
+#endif /* _CPP_BITSET */
+
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_cassert.h b/libstdc++-v3/bits/std_cassert.h
new file mode 100644
index 0000000..c1aefa6
--- /dev/null
+++ b/libstdc++-v3/bits/std_cassert.h
@@ -0,0 +1,38 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 19.2 Assertions
+//
+
+// Note: This is not a conforming implementation.
+
+// No include guards on this header...
+
+# include_next <assert.h>
diff --git a/libstdc++-v3/bits/std_cctype.h b/libstdc++-v3/bits/std_cctype.h
new file mode 100644
index 0000000..b3ce7d9
--- /dev/null
+++ b/libstdc++-v3/bits/std_cctype.h
@@ -0,0 +1,210 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: <ccytpe>
+//
+
+#ifndef _CPP_CCTYPE
+#define _CPP_CCTYPE 1
+
+// This keeps isanum, et al from being propagated as macros.
+#if __linux__
+#define __NO_CTYPE 1
+#endif
+
+# include_next <ctype.h>
+
+// Sequester the C non-inline implementations in the _C_Swamp::
+// namespace, and provide C++ inlines for them in the std:: namespace
+// where they belong.
+
+namespace std
+{
+ // NB: If not using namespaces, can't have any of these definitions,
+ // as they will duplicate what's in the global namespace.
+
+#ifdef toupper
+ inline int
+ _S_toupper_helper(int __c) { return toupper(__c); }
+# undef toupper
+ inline int
+ toupper(int __c) { return _S_toupper_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ toupper(int __c) { return ::toupper(__c); }
+#endif
+
+#ifdef tolower
+ inline int
+ _S_tolower_helper(int __c) { return tolower(__c); }
+# undef tolower
+ inline int
+ tolower(int __c) { return _S_tolower_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ tolower(int __c) { return ::tolower(__c); }
+#endif
+
+#ifdef isspace
+ inline int
+ _S_isspace_helper(int __c) { return isspace(__c); }
+# undef isspace
+ inline int
+ isspace(int __c) { return _S_isspace_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ isspace(int __c) { return ::isspace(__c); }
+#endif
+
+#ifdef isprint
+ inline int
+ _S_isprint_helper(int __c) { return isprint(__c); }
+# undef isprint
+ inline int
+ isprint(int __c) { return _S_isprint_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ isprint(int __c) { return ::isprint(__c); }
+#endif
+
+#ifdef iscntrl
+ inline int
+ _S_iscntrl_helper(int __c) { return iscntrl(__c); }
+# undef iscntrl
+ inline int
+ iscntrl(int __c) { return _S_iscntrl_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ iscntrl(int __c) { return ::iscntrl(__c); }
+#endif
+
+#ifdef isupper
+ inline int
+ _S_isupper_helper(int __c) { return isupper(__c); }
+# undef isupper
+ inline int
+ isupper(int __c) { return _S_isupper_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ isupper(int __c) { return ::isupper(__c); }
+#endif
+
+#ifdef islower
+ inline int
+ _S_islower_helper(int __c) { return islower(__c); }
+# undef islower
+ inline int
+ islower(int __c) { return _S_islower_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ islower(int __c) { return ::islower(__c); }
+#endif
+
+#ifdef isalpha
+ inline int
+ _S_isalpha_helper(int __c) { return isalpha(__c); }
+# undef isalpha
+ inline int
+ isalpha(int __c) { return _S_isalpha_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ isalpha(int __c) { return ::isalpha(__c); }
+#endif
+
+#ifdef isdigit
+ inline int
+ _S_isdigit_helper(int __c) { return isdigit(__c); }
+# undef isdigit
+ inline int
+ isdigit(int __c) { return _S_isdigit_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ isdigit(int __c) { return ::isdigit(__c); }
+#endif
+
+#ifdef ispunct
+ inline int
+ _S_ispunct_helper(int __c) { return ispunct(__c); }
+# undef ispunct
+ inline int
+ ispunct(int __c) { return _S_ispunct_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ ispunct(int __c) { return ::ispunct(__c); }
+#endif
+
+#ifdef isxdigit
+ inline int
+ _S_isxdigit_helper(int __c) { return isxdigit(__c); }
+# undef isxdigit
+ inline int
+ isxdigit(int __c) { return _S_isxdigit_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ isxdigit(int __c) { return ::isxdigit(__c); }
+#endif
+
+#ifdef isalnum
+ inline int
+ _S_isalnum_helper(int __c) { return isalnum(__c); }
+# undef isalnum
+ inline int
+ isalnum(int __c) { return _S_isalnum_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ isalnum(int __c) { return ::isalnum(__c); }
+#endif
+
+#ifdef isgraph
+ inline int
+ _S_isgraph_helper(int __c) { return isgraph(__c); }
+# undef isgraph
+ inline int
+ isgraph(int __c) { return _S_isgraph_helper(__c); }
+#elif _GLIBCPP_USE_NAMESPACES
+ inline int
+ isgraph(int __c) { return ::isgraph(__c); }
+#endif
+
+} // namespace std
+
+#endif // _CPP_CCTYPE
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_cerrno.h b/libstdc++-v3/bits/std_cerrno.h
new file mode 100644
index 0000000..fda202d
--- /dev/null
+++ b/libstdc++-v3/bits/std_cerrno.h
@@ -0,0 +1,39 @@
+// The -*- C++ -*- error number header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 19.3 Error numbers
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CERRNO
+#define _CPP_CERRNO 1
+# include_next <errno.h>
+#endif
diff --git a/libstdc++-v3/bits/std_cfloat.h b/libstdc++-v3/bits/std_cfloat.h
new file mode 100644
index 0000000..869c452
--- /dev/null
+++ b/libstdc++-v3/bits/std_cfloat.h
@@ -0,0 +1,46 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 18.2.2 Implementation properties: C library
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CFLOAT
+#define _CPP_CFLOAT 1
+# include_next <float.h>
+
+#if 0
+# ifdef __GLIBC__
+// For GNU libc we must also include this one:
+# include <fenv.h>
+# endif
+#endif
+#endif
diff --git a/libstdc++-v3/bits/std_ciso646.h b/libstdc++-v3/bits/std_ciso646.h
new file mode 100644
index 0000000..4f8935a
--- /dev/null
+++ b/libstdc++-v3/bits/std_ciso646.h
@@ -0,0 +1,71 @@
+// ciso646 -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: <ciso646>
+//
+
+#ifndef _CPP_ISO646
+#define _CPP_ISO646 1
+
+namespace std {
+
+ // 2.11 Keywords
+ // alternative representations
+ // and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq
+
+#ifndef __cplusplus
+#define and &&
+#define and_eq &=
+#define bitand &
+#define bitor |
+#define compl ~
+#define not !
+#define not_eq !=
+#define or ||
+#define or_eq |=
+#define xor ^
+#define xor_eq ^=
+#endif
+
+#if 0
+ template<typename _T1, typename _T2>
+ inline bool
+ operator and(const _T1& __lhs, const _T2& __rhs)
+ { return (static_cast<bool>(__lhs) && static_cast<bool>(__rhs)); }
+
+ template<typename _T1, typename _T2>
+ inline bool
+ operator or(const _T1& __lhs, const _T2& __rhs)
+ { return (static_cast<bool>(__lhs) || static_cast<bool>(__rhs)); }
+#endif
+
+} // namespace std
+
+#endif // _CPP_ISO646
diff --git a/libstdc++-v3/bits/std_climits.h b/libstdc++-v3/bits/std_climits.h
new file mode 100644
index 0000000..0638ec2
--- /dev/null
+++ b/libstdc++-v3/bits/std_climits.h
@@ -0,0 +1,39 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 18.2.2 Implementation properties: C library
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CLIMITS
+#define _CPP_CLIMITS 1
+# include_next <limits.h>
+#endif
diff --git a/libstdc++-v3/bits/std_clocale.h b/libstdc++-v3/bits/std_clocale.h
new file mode 100644
index 0000000..acadfd7
--- /dev/null
+++ b/libstdc++-v3/bits/std_clocale.h
@@ -0,0 +1,40 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 18.2.2 Implementation properties: C library
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CLOCALE
+#define _CPP_CLOCALE 1
+# include_next <locale.h>
+#endif
+
diff --git a/libstdc++-v3/bits/std_cmath.h b/libstdc++-v3/bits/std_cmath.h
new file mode 100644
index 0000000..04b018f
--- /dev/null
+++ b/libstdc++-v3/bits/std_cmath.h
@@ -0,0 +1,247 @@
+// -*- C++ -*- C math library.
+
+// Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 26.5 C library
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CMATH
+#define _CPP_CMATH 1
+# include_next <math.h>
+# include_next <stdlib.h>
+
+#include <bits/c++config.h>
+
+namespace std {
+
+ inline long
+ abs(long __l) { return ::labs(__l); }
+
+ inline ldiv_t
+ div(long __a, long __b) { return ::ldiv(__a, __b); }
+
+ // double
+ inline double
+ abs(double __x) { return ::fabs(__x); }
+
+ double
+ pow(double, int);
+
+ // float
+ inline float
+ ceil(float __x) { return ::ceil(static_cast<double>(__x)); }
+
+ inline float
+ floor(float __x) { return ::floor(static_cast<double>(__x)); }
+
+ inline float
+ fmod(float __x, float __y)
+ { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
+
+ inline float
+ frexp(float __x, int* __p)
+ { return ::frexp(static_cast<double>(__x), __p); }
+
+ inline float
+ ldexp(float __x, int __i)
+ { return ::ldexp(static_cast<double>(__x), __i); }
+
+ inline float
+ pow(float __x, float __y)
+ { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
+
+ float
+ pow(float, int);
+
+#if _GLIBCPP_HAVE_ABSF
+ inline float
+ abs(float __x) { return ::absf(__x); }
+#else
+ inline float
+ abs(float __x) { return ::fabs(static_cast<double>(__x)); }
+#endif
+
+#if _GLIBCPP_HAVE_ACOSF
+ inline float
+ acos(float __x) { return ::acosf(__x); }
+#else
+ inline float
+ acos(float __x) { return ::acos(static_cast<double>(__x)); }
+#endif
+
+#if _GLIBCPP_HAVE_ASINF
+ inline float
+ asin(float __x) { return ::asinf(__x); }
+#else
+ inline float
+ asin(float __x) { return ::asin(static_cast<double>(__x)); }
+#endif
+
+#if _GLIBCPP_HAVE_ATANF
+ inline float
+ atan(float __x) { return ::atanf(__x); }
+#else
+ inline float
+ atan(float __x) { return ::atan(static_cast<double>(__x)); }
+#endif
+
+#if _GLIBCPP_HAVE_ATAN2F
+ inline float
+ atan2(float __x, float __y) { return ::atan2f(__x, __y); }
+#else
+ inline float
+ atan2(float __x, float __y)
+ { return ::atan2(static_cast<double>(__x), static_cast<double>(__y)); }
+#endif
+
+#if _GLIBCPP_HAVE_TANF
+ inline float
+ tan(float __x) { return ::tanf(__x); }
+#else
+ inline float
+ tan(float __x) { return ::tan(static_cast<double>(__x)); }
+#endif
+
+#if _GLIBCPP_HAVE_SINHF
+ inline float
+ sinh(float __x) { return ::sinhf(__x); }
+#else
+ inline float
+ sinh(float __x) { return ::sinh(static_cast<double>(__x)); }
+#endif
+
+#if _GLIBCPP_HAVE_TANHF
+ inline float
+ tanh(float __x) { return ::tanhf(__x); }
+#else
+ inline float
+ tanh(float __x) { return ::tanh(static_cast<double>(__x)); }
+#endif
+
+#if _GLIBCPP_HAVE_COSHF
+ inline float
+ cosh(float __x) { return ::coshf(__x); }
+#else
+ inline float
+ cosh(float __x) { return ::cosh(static_cast<double>(__x)); }
+#endif
+
+#if _GLIBCPP_HAVE_EXPF
+ inline float
+ exp(float __x) { return ::expf(__x); }
+#else
+ inline float
+ exp(float __x) { return ::exp(static_cast<double>(__x)); }
+#endif
+
+#if _GLIBCPP_HAVE_LOGF
+ inline float
+ log(float __x) { return ::logf(__x); }
+#else
+ inline float
+ log(float __x) { return ::log(static_cast<double>(__x)); }
+#endif
+
+#if _GLIBCPP_HAVE_LOG10F
+ inline float
+ log10(float __x) { return ::log10f(__x); }
+#else
+ inline float
+ log10(float __x) { return ::log10(static_cast<double>(__x)); }
+#endif
+
+#if _GLIBCPP_HAVE_MODFF
+ inline float
+ modf(float __x, float* __p) { return ::modff(__x, __p); }
+#else
+ inline float
+ modf(float __x, float* __p)
+ {
+ double __tmp;
+ double __res = ::modf(static_cast<double>(__x), &__tmp);
+ *__p = static_cast<float> (__tmp);
+ return __res;
+ }
+#endif
+
+#if GLIBCPP_HAS_BUILTIN_SINF
+ inline float
+ sin(float __x) { return __builtin_sinf(__x); }
+#elif _GLIBCPP_HAVE_SINF
+ inline float
+ sin(float __x) { return ::sinf(__x); }
+#else
+ inline float
+ sin(float __x) { return ::sin(static_cast<double>(__x)); }
+#endif
+
+#if GLIBCPP_HAS_BUILTIN_COSF
+ inline float
+ cos(float __x) { return __builtin_cosf(__x); }
+#elif _GLIBCPP_HAVE_COSF
+ inline float
+ cos(float __x) { return ::cosf(__x); }
+#else
+ inline float
+ cos(float __x) { return ::cos(static_cast<double>(__x)); }
+#endif
+
+#if GLIBCPP_HAS_BUILTIN_FABSF
+ inline float
+ fabs(float __x) { return __builtin_fabsf(__x); }
+#elif _GLIBCPP_HAVE_FABSF
+ inline float
+ fabs(float __x) { return ::fabsf(__x); }
+#else
+ inline float
+ fabs(float __x) { return ::fabs(static_cast<double>(__x)); }
+#endif
+
+#if GLIBCPP_HAS_BUILTIN_SQRTF
+ inline float
+ sqrt(float __x) { return __builtin_sqrtf(__x); }
+#elif _GLIBCPP_HAVE_SQRTF
+ inline float
+ sqrt(float __x) { return ::sqrtf(__x); }
+#else
+ inline float
+ sqrt(float __x) { return ::fabs(static_cast<double>(__x)); }
+#endif
+
+ // XXX long double
+ long double
+ pow(long double, int);
+
+} // std
+
+#endif // _CPP_CMATH
+
+
diff --git a/libstdc++-v3/bits/std_complex.h b/libstdc++-v3/bits/std_complex.h
new file mode 100644
index 0000000..5064efa
--- /dev/null
+++ b/libstdc++-v3/bits/std_complex.h
@@ -0,0 +1,966 @@
+// The template and inlines for the -*- C++ -*- complex number classes.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO 14882/26.2.1
+// Note: this is not a conforming implementation.
+// Initially implemented by Ulrich Drepper <drepper@cygnus.com>
+// Improved by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
+//
+
+#ifndef _CPP_COMPLEX
+#define _CPP_COMPLEX 1
+
+#include <bits/c++config.h>
+#include <bits/std_iosfwd.h>
+
+
+namespace std
+{
+ // Forward declarations
+ template<typename _Tp> class complex;
+ template<> class complex<float>;
+ template<> class complex<double>;
+ template<> class complex<long double>;
+
+ template<typename _Tp> _Tp abs(const complex<_Tp>&);
+ template<typename _Tp> _Tp arg(const complex<_Tp>&);
+
+ template<typename _Tp> complex<_Tp> conj(const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> polar(const _Tp&, const _Tp&);
+
+ // Transcendentals:
+ template<typename _Tp> complex<_Tp> cos(const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> cosh(const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> exp(const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> log(const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> log10(const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, int);
+ template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, const _Tp&);
+ template<typename _Tp> complex<_Tp> pow (const complex<_Tp>&,
+ const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> pow(const _Tp&, const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> sin(const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> sinh(const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> sqrt(const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> tan(const complex<_Tp>&);
+ template<typename _Tp> complex<_Tp> tanh(const complex<_Tp>&);
+
+
+ //
+ // 26.2.2 Primary template class complex
+ //
+ template <typename _Tp>
+ class complex
+ {
+ public:
+ typedef _Tp value_type;
+
+ complex (const _Tp& = _Tp(), const _Tp & = _Tp());
+
+ // Let's the compiler synthetize the copy constructor
+ // complex (const complex<_Tp>&);
+
+ template <typename _Up>
+ complex (const complex<_Up>&);
+
+ _Tp real () const;
+ _Tp imag () const;
+
+ complex<_Tp>& operator= (const _Tp&);
+ complex<_Tp>& operator+= (const _Tp&);
+ complex<_Tp>& operator-= (const _Tp&);
+ complex<_Tp>& operator*= (const _Tp&);
+ complex<_Tp>& operator/= (const _Tp&);
+
+ // Let's the compiler synthetize the
+ // copy and assignment operator
+ // complex<_Tp>& operator= (const complex<_Tp>&);
+
+ template <typename _Up>
+ complex<_Tp>& operator= (const complex<_Up>&);
+ template <typename _Up>
+ complex<_Tp>& operator+= (const complex<_Up>&);
+ template <typename _Up>
+ complex<_Tp>& operator-= (const complex<_Up>&);
+ template <typename _Up>
+ complex<_Tp>& operator*= (const complex<_Up>&);
+ template <typename _Up>
+ complex<_Tp>& operator/= (const complex<_Up>&);
+
+ private:
+ _Tp _M_real, _M_imag;
+ };
+
+ template<typename _Tp>
+ inline _Tp
+ complex<_Tp>::real() const { return _M_real; }
+
+ template<typename _Tp>
+ inline _Tp
+ complex<_Tp>::imag() const { return _M_imag; }
+
+
+ //
+ // 26.2.3 complex specializations
+ //
+
+ //
+ // complex<float> specialization
+ //
+ template<> class complex<float>
+ {
+ public:
+ typedef float value_type;
+
+ complex(float = 0.0f, float = 0.0f);
+#ifdef _GLIBCPP_BUGGY_COMPLEX
+ complex(const complex& __z) : _M_value(__z._M_value) {}
+#endif
+ explicit complex(const complex<double>&);
+ explicit complex(const complex<long double>&);
+
+ float real() const;
+ float imag() const;
+
+ complex<float>& operator= (float);
+ complex<float>& operator+= (float);
+ complex<float>& operator-= (float);
+ complex<float>& operator*= (float);
+ complex<float>& operator/= (float);
+
+ // Let's the compiler synthetize the copy and assignment
+ // operator. It always does a pretty good job.
+ // complex& operator= (const complex&);
+
+ template <typename _Tp>
+ complex<float>&operator= (const complex<_Tp>&);
+ template <typename _Tp>
+ complex<float>& operator+= (const complex<_Tp>&);
+ template <class _Tp>
+ complex<float>& operator-= (const complex<_Tp>&);
+ template <class _Tp>
+ complex<float>& operator*= (const complex<_Tp>&);
+ template <class _Tp>
+ complex<float>&operator/= (const complex<_Tp>&);
+
+ private:
+ typedef __complex__ float _ComplexT;
+ _ComplexT _M_value;
+
+ complex(_ComplexT __z) : _M_value(__z) {}
+
+ friend class complex<double>;
+ friend class complex<long double>;
+
+ friend float abs<>(const complex<float>&);
+ friend float arg<>(const complex<float>&);
+
+ friend complex<float> conj<>(const complex<float>&);
+
+ friend complex<float> cos<>(const complex<float>&);
+ friend complex<float> cosh<>(const complex<float>&);
+ friend complex<float> exp<>(const complex<float>&);
+ friend complex<float> log<>(const complex<float>&);
+ friend complex<float> log10<>(const complex<float>&);
+ friend complex<float> pow<>(const complex<float>&, int);
+ friend complex<float> pow<>(const complex<float>&, const float&);
+ friend complex<float> pow<>(const complex<float>&,
+ const complex<float>&);
+ friend complex<float> pow<>(const float&, const complex<float>&);
+ friend complex<float> sin<>(const complex<float>&);
+ friend complex<float> sinh<>(const complex<float>&);
+ friend complex<float> sqrt<>(const complex<float>&);
+ friend complex<float> tan<>(const complex<float>&);
+ friend complex<float> tanh<>(const complex<float>&);
+ };
+
+ inline float
+ complex<float>::real() const
+ { return __real__ _M_value; }
+
+ inline float
+ complex<float>::imag() const
+ { return __imag__ _M_value; }
+
+
+ //
+ // complex<double> specialization
+ //
+ template<> class complex<double>
+ {
+ public:
+ typedef double value_type;
+
+ complex(double =0.0, double =0.0);
+#ifdef _GLIBCPP_BUGGY_COMPLEX
+ complex(const complex& __z) : _M_value(__z._M_value) {}
+#endif
+ complex(const complex<float>&);
+ explicit complex(const complex<long double>&);
+
+ double real () const;
+ double imag () const;
+
+ complex<double>& operator= (double);
+ complex<double>& operator+= (double);
+ complex<double>& operator-= (double);
+ complex<double>& operator*= (double);
+ complex<double>& operator/= (double);
+
+ // The compiler will synthetize this, efficiently.
+ // complex& operator= (const complex&);
+
+ template <typename _Tp>
+ complex<double>& operator= (const complex<_Tp>&);
+ template <typename _Tp>
+ complex<double>& operator+= (const complex<_Tp>&);
+ template <typename _Tp>
+ complex<double>& operator-= (const complex<_Tp>&);
+ template <typename _Tp>
+ complex<double>& operator*= (const complex<_Tp>&);
+ template <typename _Tp>
+ complex<double>& operator/= (const complex<_Tp>&);
+
+ private:
+ typedef __complex__ double _ComplexT;
+ _ComplexT _M_value;
+
+ complex(_ComplexT __z) : _M_value(__z) {}
+
+ friend class complex<float>;
+ friend class complex<long double>;
+
+ friend double abs<>(const complex<double>&);
+ friend double arg<>(const complex<double>&);
+
+ friend complex<double> conj<>(const complex<double>&);
+
+ friend complex<double> cos<>(const complex<double>&);
+ friend complex<double> cosh<>(const complex<double>&);
+ friend complex<double> exp<>(const complex<double>&);
+ friend complex<double> log<>(const complex<double>&);
+ friend complex<double> log10<>(const complex<double>&);
+ friend complex<double> pow<>(const complex<double>&, int);
+ friend complex<double> pow<>(const complex<double>&, const double&);
+ friend complex<double> pow<>(const complex<double>&,
+ const complex<double>&);
+ friend complex<double> pow<>(const double&, const complex<double>&);
+ friend complex<double> sin<>(const complex<double>&);
+ friend complex<double> sinh<>(const complex<double>&);
+ friend complex<double> sqrt<>(const complex<double>&);
+ friend complex<double> tan<>(const complex<double>&);
+ friend complex<double> tanh<>(const complex<double>&);
+ };
+
+ inline double
+ complex<double>::real() const
+ { return __real__ _M_value; }
+
+ inline double
+ complex<double>::imag() const
+ { return __imag__ _M_value; }
+
+
+ //
+ // complex<long double> specialization
+ //
+ template<> class complex<long double>
+ {
+ public:
+ typedef long double value_type;
+
+ complex(long double = 0.0L, long double = 0.0L);
+#ifdef _GLIBCPP_BUGGY_COMPLEX
+ complex(const complex& __z) : _M_value(__z._M_value) {}
+#endif
+ complex(const complex<float>&);
+ complex(const complex<double>&);
+
+ long double real() const;
+ long double imag() const;
+
+ complex<long double>& operator= (long double);
+ complex<long double>& operator+= (long double);
+ complex<long double>& operator-= (long double);
+ complex<long double>& operator*= (long double);
+ complex<long double>& operator/= (long double);
+
+ // The compiler knows how to do this efficiently
+ // complex& operator= (const complex&);
+
+ template<typename _Tp>
+ complex<long double>& operator= (const complex<_Tp>&);
+ template<typename _Tp>
+ complex<long double>& operator+= (const complex<_Tp>&);
+ template<typename _Tp>
+ complex<long double>& operator-= (const complex<_Tp>&);
+ template<typename _Tp>
+ complex<long double>& operator*= (const complex<_Tp>&);
+ template<typename _Tp>
+ complex<long double>& operator/= (const complex<_Tp>&);
+
+ private:
+ typedef __complex__ long double _ComplexT;
+ _ComplexT _M_value;
+
+ complex(_ComplexT __z) : _M_value(__z) {}
+
+ friend class complex<float>;
+ friend class complex<double>;
+
+ friend long double abs<>(const complex<long double>&);
+ friend long double arg<>(const complex<long double>&);
+
+ friend complex<long double> conj<>(const complex<long double>&);
+
+ friend complex<long double> cos<>(const complex<long double>&);
+ friend complex<long double> cosh<>(const complex<long double>&);
+ friend complex<long double> exp<>(const complex<long double>&);
+ friend complex<long double> log<>(const complex<long double>&);
+ friend complex<long double> log10<>(const complex<long double>&);
+ friend complex<long double> pow<>(const complex<long double>&, int);
+ friend complex<long double> pow<>(const complex<long double>&,
+ const long double&);
+ friend complex<long double> pow<>(const complex<long double>&,
+ const complex<long double>&);
+ friend complex<long double> pow<>(const long double&,
+ const complex<long double>&);
+ friend complex<long double> sin<>(const complex<long double>&);
+ friend complex<long double> sinh<>(const complex<long double>&);
+ friend complex<long double> sqrt<>(const complex<long double>&);
+ friend complex<long double> tan<>(const complex<long double>&);
+ friend complex<long double> tanh<>(const complex<long double>&);
+ };
+
+ inline
+ complex<long double>::complex(long double __r, long double __i)
+ {
+ __real__ _M_value = __r;
+ __imag__ _M_value = __i;
+ }
+
+ inline
+ complex<long double>::complex(const complex<float>& __z)
+ : _M_value(_ComplexT(__z._M_value)) {}
+
+ inline
+ complex<long double>::complex(const complex<double>& __z)
+ : _M_value(_ComplexT(__z._M_value)) {}
+
+ inline long double
+ complex<long double>::real() const
+ { return __real__ _M_value; }
+
+ inline long double
+ complex<long double>::imag() const
+ { return __imag__ _M_value; }
+
+ inline complex<long double>&
+ complex<long double>::operator= (long double __r)
+ {
+ __real__ _M_value = __r;
+ __imag__ _M_value = 0.0L;
+ return *this;
+ }
+
+ inline complex<long double>&
+ complex<long double>::operator+= (long double __r)
+ {
+ __real__ _M_value += __r;
+ return *this;
+ }
+
+ inline complex<long double>&
+ complex<long double>::operator-= (long double __r)
+ {
+ __real__ _M_value -= __r;
+ return *this;
+ }
+
+ inline complex<long double>&
+ complex<long double>::operator*= (long double __r)
+ {
+ __real__ _M_value *= __r;
+ return *this;
+ }
+
+ inline complex<long double>&
+ complex<long double>::operator/= (long double __r)
+ {
+ __real__ _M_value /= __r;
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<long double>&
+ complex<long double>::operator= (const complex<_Tp>& __z)
+ {
+ __real__ _M_value = __z.real();
+ __imag__ _M_value = __z.imag();
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<long double>&
+ complex<long double>::operator+= (const complex<_Tp>& __z)
+ {
+ __real__ _M_value += __z.real();
+ __imag__ _M_value += __z.imag();
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<long double>&
+ complex<long double>::operator-= (const complex<_Tp>& __z)
+ {
+ __real__ _M_value -= __z.real();
+ __imag__ _M_value -= __z.imag();
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<long double>&
+ complex<long double>::operator*= (const complex<_Tp>& __z)
+ {
+ _ComplexT __t;
+ __real__ __t = __z.real();
+ __imag__ __t = __z.imag();
+ _M_value *= __t;
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<long double>&
+ complex<long double>::operator/= (const complex<_Tp>& __z)
+ {
+ _ComplexT __t;
+ __real__ __t = __z.real();
+ __imag__ __t = __z.imag();
+ _M_value /= __t;
+ return *this;
+ }
+
+ //
+ // complex<float> continued.
+ //
+ inline
+ complex<float>::complex(float r, float i)
+ {
+ __real__ _M_value = r;
+ __imag__ _M_value = i;
+ }
+
+ inline
+ complex<float>::complex(const complex<double>& __z)
+ : _M_value(_ComplexT(__z._M_value)) {}
+
+ inline
+ complex<float>::complex(const complex<long double>& __z)
+ : _M_value(_ComplexT(__z._M_value)) {}
+
+ inline complex<float>&
+ complex<float>::operator= (float __f)
+ {
+ __real__ _M_value = __f;
+ __imag__ _M_value = 0.0f;
+ return *this;
+ }
+
+ inline complex<float>&
+ complex<float>::operator+= (float __f)
+ {
+ __real__ _M_value += __f;
+ return *this;
+ }
+
+ inline complex<float>&
+ complex<float>::operator-= (float __f)
+ {
+ __real__ _M_value -= __f;
+ return *this;
+ }
+
+ inline complex<float>&
+ complex<float>::operator*= (float __f)
+ {
+ _M_value *= __f;
+ return *this;
+ }
+
+ inline complex<float>&
+ complex<float>::operator/= (float __f)
+ {
+ _M_value /= __f;
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<float>&
+ complex<float>::operator= (const complex<_Tp>& __z)
+ {
+ __real__ _M_value = __z.real();
+ __imag__ _M_value = __z.imag();
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<float>&
+ complex<float>::operator+= (const complex<_Tp>& __z)
+ {
+ __real__ _M_value += __z.real();
+ __imag__ _M_value += __z.imag();
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<float>&
+ complex<float>::operator-= (const complex<_Tp>& __z)
+ {
+ __real__ _M_value -= __z.real();
+ __imag__ _M_value -= __z.real();
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<float>&
+ complex<float>::operator*= (const complex<_Tp>& __z)
+ {
+ _ComplexT __t;
+ __real__ __t = __z.real();
+ __imag__ __t = __z.imag();
+ _M_value *= __t;
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<float>&
+ complex<float>::operator/= (const complex<_Tp>& __z)
+ {
+ _ComplexT __t;
+ __real__ __t = __z.real();
+ __imag__ __t = __z.imag();
+ _M_value /= __t;
+ return *this;
+ }
+
+
+ //
+ // complex<double> continued.
+ //
+ inline
+ complex<double>::complex(double __r, double __i)
+ {
+ __real__ _M_value = __r;
+ __imag__ _M_value = __i;
+ }
+
+ inline
+ complex<double>::complex(const complex<float>& __z)
+ : _M_value(_ComplexT(__z._M_value)) {}
+
+ inline
+ complex<double>::complex(const complex<long double>& __z)
+ {
+ __real__ _M_value = __z.real();
+ __imag__ _M_value = __z.imag();
+ }
+
+ inline complex<double>&
+ complex<double>::operator= (double __d)
+ {
+ __real__ _M_value = __d;
+ __imag__ _M_value = 0.0;
+ return *this;
+ }
+
+ inline complex<double>&
+ complex<double>::operator+= (double __d)
+ {
+ __real__ _M_value += __d;
+ return *this;
+ }
+
+ inline complex<double>&
+ complex<double>::operator-= (double __d)
+ {
+ __real__ _M_value -= __d;
+ return *this;
+ }
+
+ inline complex<double>&
+ complex<double>::operator*= (double __d)
+ {
+ _M_value *= __d;
+ return *this;
+ }
+
+ inline complex<double>&
+ complex<double>::operator/= (double __d)
+ {
+ _M_value /= __d;
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<double>&
+ complex<double>::operator= (const complex<_Tp>& __z)
+ {
+ __real__ _M_value = __z.real();
+ __imag__ _M_value = __z.imag();
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<double>&
+ complex<double>::operator+= (const complex<_Tp>& __z)
+ {
+ __real__ _M_value += __z.real();
+ __imag__ _M_value += __z.imag();
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<double>&
+ complex<double>::operator-= (const complex<_Tp>& __z)
+ {
+ __real__ _M_value -= __z.real();
+ __imag__ _M_value -= __z.imag();
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<double>&
+ complex<double>::operator*= (const complex<_Tp>& __z)
+ {
+ _ComplexT __t;
+ __real__ __t = __z.real();
+ __imag__ __t = __z.imag();
+ _M_value *= __t;
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline complex<double>&
+ complex<double>::operator/= (const complex<_Tp>& __z)
+ {
+ _ComplexT __t;
+ __real__ __t = __z.real();
+ __imag__ __t = __z.imag();
+ _M_value /= __t;
+ return *this;
+ }
+
+ //
+ // Primary template class complex continued.
+ //
+ // 26.2.4
+ template<typename _Tp>
+ inline
+ complex<_Tp>::complex(const _Tp& __r, const _Tp& __i)
+ : _M_real(__r), _M_imag(__i) {}
+
+ template<typename _Tp>
+ template<typename _Up>
+ inline
+ complex<_Tp>::complex(const complex<_Up>& __z)
+ : _M_real(__z.real()), _M_imag(__z.imag()) {}
+
+ // 26.2.7/6
+ template<typename _Tp>
+ inline complex<_Tp>
+ conj(const complex<_Tp>& __z)
+ { return complex<_Tp>(__z.real(), -__z.imag()); }
+
+ // 26.2.7/4
+ template<typename _Tp>
+ inline _Tp
+ norm(const complex<_Tp>& __z)
+ {
+ // XXX: Grammar school computation
+ return __z.real() * __z.real() + __z.imag() * __z.imag();
+ }
+
+ template<typename _Tp>
+ complex<_Tp>&
+ complex<_Tp>::operator= (const _Tp& __t)
+ {
+ _M_real = __t;
+ _M_imag = _Tp();
+ return *this;
+ }
+
+ // 26.2.5/1
+ template<typename _Tp>
+ inline complex<_Tp>&
+ complex<_Tp>::operator+= (const _Tp& __t)
+ {
+ _M_real += __t;
+ return *this;
+ }
+
+ // 26.2.5/3
+ template<typename _Tp>
+ inline complex<_Tp>&
+ complex<_Tp>::operator-= (const _Tp& __t)
+ {
+ _M_real -= __t;
+ return *this;
+ }
+
+ // 26.2.5/5
+ template<typename _Tp>
+ complex<_Tp>&
+ complex<_Tp>::operator*= (const _Tp& __t)
+ {
+ _M_real *= __t;
+ _M_imag *= __t;
+ return *this;
+ }
+
+ // 26.2.5/7
+ template<typename _Tp>
+ complex<_Tp>&
+ complex<_Tp>::operator/= (const _Tp& __t)
+ {
+ _M_real /= __t;
+ _M_imag /= __t;
+ return *this;
+ }
+
+ template<typename _Tp>
+ template<typename _Up>
+ complex<_Tp>&
+ complex<_Tp>::operator= (const complex<_Up>& __z)
+ {
+ _M_real = __z.real();
+ _M_imag = __z.imag();
+ return *this;
+ }
+
+ // 26.2.5/9
+ template<typename _Tp>
+ template<typename _Up>
+ complex<_Tp>&
+ complex<_Tp>::operator+= (const complex<_Up>& __z)
+ {
+ _M_real += __z.real();
+ _M_imag += __z.imag();
+ return *this;
+ }
+
+ // 26.2.5/11
+ template<typename _Tp>
+ template<typename _Up>
+ complex<_Tp>&
+ complex<_Tp>::operator-= (const complex<_Up>& __z)
+ {
+ _M_real -= __z.real();
+ _M_imag -= __z.imag();
+ return *this;
+ }
+
+ // 26.2.5/13
+ // XXX: this is a grammar school implementation.
+ template<typename _Tp>
+ template<typename _Up>
+ complex<_Tp>&
+ complex<_Tp>::operator*= (const complex<_Up>& __z)
+ {
+ _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
+ _M_imag = _M_real * __z.imag() + _M_imag * __z.real();
+ _M_real = __r;
+ return *this;
+ }
+
+ // 26.2.5/15
+ // XXX: this is a grammar school implementation.
+ template<typename _Tp>
+ template<typename _Up>
+ complex<_Tp>&
+ complex<_Tp>::operator/= (const complex<_Up>& __z)
+ {
+ _Tp __r = _M_real * __z.real() + _M_imag * __z.imag();
+ _Tp __n = norm(__z);
+ _M_imag = (_M_real * __z.imag() - _M_imag * __z.real()) / __n;
+ _M_real = __r / __n;
+ return *this;
+ }
+
+
+ // Operators:
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
+ { return complex<_Tp> (__x) += __y; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator+(const complex<_Tp>& __x, const _Tp& __y)
+ { return complex<_Tp> (__x) += __y; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator+(const _Tp& __x, const complex<_Tp>& __y)
+ { return complex<_Tp> (__y) += __x; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
+ { return complex<_Tp> (__x) -= __y; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator-(const complex<_Tp>& __x, const _Tp& __y)
+ { return complex<_Tp> (__x) -= __y; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator-(const _Tp& __x, const complex<_Tp>& __y)
+ { return complex<_Tp> (__x) -= __y; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
+ { return complex<_Tp> (__x) *= __y; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator*(const complex<_Tp>& __x, const _Tp& __y)
+ { return complex<_Tp> (__x) *= __y; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator*(const _Tp& __x, const complex<_Tp>& __y)
+ { return complex<_Tp> (__y) *= __x; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
+ { return complex<_Tp> (__x) /= __y; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator/(const complex<_Tp>& __x, const _Tp& __y)
+ { return complex<_Tp> (__x) /= __y; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator/(const _Tp& __x, const complex<_Tp>& __y)
+ { return complex<_Tp> (__x) /= __y; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator+(const complex<_Tp>& __x)
+ { return __x; }
+
+ template<typename _Tp>
+ inline complex<_Tp>
+ operator-(const complex<_Tp>& __x)
+ { return complex<_Tp>(-__x.real(), -__x.imag()); }
+
+ template<typename _Tp>
+ inline bool
+ operator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
+ { return __x.real() == __y.real() && __x.imag == __y.imag(); }
+
+ template<typename _Tp>
+ inline bool
+ operator==(const complex<_Tp>& __x, const _Tp& __y)
+ { return __x.real() == __y && __x.imag() == 0; }
+
+ template<typename _Tp>
+ inline bool
+ operator==(const _Tp& __x, const complex<_Tp>& __y)
+ { return __x == __y.real() && 0 == __y.imag(); }
+
+ template<typename _Tp>
+ inline bool
+ operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y)
+ { return __x.real() != __y.real() || __x.imag() != __y.imag(); }
+
+ template<typename _Tp>
+ inline bool
+ operator!=(const complex<_Tp>& __x, const _Tp& __y)
+ { return __x.real() != __y || __x.imag() != 0; }
+
+ template<typename _Tp>
+ inline bool
+ operator!=(const _Tp& __x, const complex<_Tp>& __y)
+ { return __x != __y.real() || 0 != __y.imag(); }
+
+ template<typename _Tp, typename _CharT, class _Traits>
+ basic_istream<_CharT, _Traits>&
+ operator>>(basic_istream<_CharT, _Traits>&, complex<_Tp>&);
+
+ template<typename _Tp, typename _CharT, class _Traits>
+ basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>&, const complex<_Tp>&);
+
+
+ // Values:
+ template <typename _Tp>
+ inline _Tp
+ real (const complex<_Tp>& __z)
+ { return __z.real(); }
+
+ template <typename _Tp>
+ inline _Tp
+ imag (const complex<_Tp>& __z)
+ { return __z.imag(); }
+
+
+ // We use here a few more specializations.
+ template<>
+ inline complex<float>
+ conj(const complex<float> &__x)
+#ifdef _GLIBCPP_BUGGY_FLOAT_COMPLEX
+ {
+ complex<float> __tmpf(~__x._M_value);
+ return __tmpf;
+ }
+#else
+ { return complex<float>(~__x._M_value); }
+#endif
+
+ template<>
+ inline complex<double>
+ conj(const complex<double> &__x)
+ { return complex<double> (~__x._M_value); }
+
+ template<>
+ inline complex<long double>
+ conj(const complex<long double> &__x)
+ {
+ return complex<long double> (~__x._M_value);
+ }
+
+} // namespace std
+
+#endif /* _CPP_COMPLEX */
diff --git a/libstdc++-v3/bits/std_csetjmp.h b/libstdc++-v3/bits/std_csetjmp.h
new file mode 100644
index 0000000..e94488b
--- /dev/null
+++ b/libstdc++-v3/bits/std_csetjmp.h
@@ -0,0 +1,39 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 20.4.6 C library
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CSETJMP
+#define _CPP_CSETJMP 1
+# include_next <setjmp.h>
+#endif
diff --git a/libstdc++-v3/bits/std_csignal.h b/libstdc++-v3/bits/std_csignal.h
new file mode 100644
index 0000000..b300f5b
--- /dev/null
+++ b/libstdc++-v3/bits/std_csignal.h
@@ -0,0 +1,39 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 20.4.6 C library
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CSIGNAL
+#define _CPP_CSIGNAL 1
+# include_next <signal.h>
+#endif
diff --git a/libstdc++-v3/bits/std_cstdarg.h b/libstdc++-v3/bits/std_cstdarg.h
new file mode 100644
index 0000000..5b0ca7d
--- /dev/null
+++ b/libstdc++-v3/bits/std_cstdarg.h
@@ -0,0 +1,39 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 20.4.6 C library
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CSTDARG
+#define _CPP_CSTDARG 1
+# include_next <stdarg.h>
+#endif
diff --git a/libstdc++-v3/bits/std_cstddef.h b/libstdc++-v3/bits/std_cstddef.h
new file mode 100644
index 0000000..66a1b5d
--- /dev/null
+++ b/libstdc++-v3/bits/std_cstddef.h
@@ -0,0 +1,39 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 18.1 Types
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CSTDDEF
+#define _CPP_CSTDDEF 1
+# include_next <stddef.h>
+#endif
diff --git a/libstdc++-v3/bits/std_cstdio.h b/libstdc++-v3/bits/std_cstdio.h
new file mode 100644
index 0000000..aec526d
--- /dev/null
+++ b/libstdc++-v3/bits/std_cstdio.h
@@ -0,0 +1,60 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.8.2 C Library files
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CSTDIO
+#define _CPP_CSTDIO 1
+# include_next <stdio.h>
+
+#ifndef SEEK_CUR
+#define SEEK_CUR 1
+#endif
+
+#ifndef SEEK_END
+#define SEEK_END 2
+#endif
+
+#ifndef SEEK_SET
+#define SEEK_SET 4
+#endif
+
+#endif
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_cstdlib.h b/libstdc++-v3/bits/std_cstdlib.h
new file mode 100644
index 0000000..adbefa2
--- /dev/null
+++ b/libstdc++-v3/bits/std_cstdlib.h
@@ -0,0 +1,53 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 20.4.6 C library
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CSTDLIB
+#define _CPP_CSTDLIB 1
+
+// This keeps isanum, et al from being propagated as macros.
+#if __linux__
+#define __USE_ISOC9X 1
+#endif
+
+# include_next <stdlib.h>
+
+#endif // _CPP_CSTDLIB
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_cstring.h b/libstdc++-v3/bits/std_cstring.h
new file mode 100644
index 0000000..c076b6a
--- /dev/null
+++ b/libstdc++-v3/bits/std_cstring.h
@@ -0,0 +1,43 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 20.4.6 C library
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CSTRING
+#define _CPP_CSTRING 1
+# if defined __GLIBC__ && __GLIBC__ >= 2
+// We must not see the optimized string functions GNU libc defines.
+# define __NO_STRING_INLINES
+# endif
+# include_next <string.h>
+#endif
diff --git a/libstdc++-v3/bits/std_ctime.h b/libstdc++-v3/bits/std_ctime.h
new file mode 100644
index 0000000..08c07b6
--- /dev/null
+++ b/libstdc++-v3/bits/std_ctime.h
@@ -0,0 +1,39 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 20.5 Date and time
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CTIME
+#define _CPP_CTIME 1
+# include_next <time.h>
+#endif
diff --git a/libstdc++-v3/bits/std_cwchar.h b/libstdc++-v3/bits/std_cwchar.h
new file mode 100644
index 0000000..8c606dc
--- /dev/null
+++ b/libstdc++-v3/bits/std_cwchar.h
@@ -0,0 +1,108 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: ???
+//
+
+// Note: this is not a conforming implementation.
+
+#ifndef _CPP_CWCHAR
+#define _CPP_CWCHAR 1
+
+#include <bits/c++config.h>
+#ifdef _GLIBCPP_USE_WCHAR_T
+ # include_next <wchar.h>
+#endif
+
+extern "C" {
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+
+#ifndef _GLIBCPP_HAVE_WMEMCMP
+ int wmemcmp(const wchar_t* __s1, const wchar_t* __s2, size_t __n);
+#endif
+
+#ifndef _GLIBCPP_HAVE_WCSLEN
+ size_t wcslen(const wchar_t* __s);
+#endif
+
+#ifndef _GLIBCPP_HAVE_WMEMCHR
+ wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n);
+#endif
+
+#ifndef _GLIBCPP_HAVE_WMEMMOVE
+ wchar_t* wmemmove(wchar_t* __s1, const wchar_t* __s2, size_t __n);
+#endif
+
+#ifndef _GLIBCPP_HAVE_WMEMCPY
+ wchar_t* wmemcpy(wchar_t* __s1, const wchar_t* __s2, size_t __n);
+#endif
+
+#ifndef _GLIBCPP_HAVE_WMEMSET
+ wchar_t* wmemset(wchar_t* __s, wchar_t __c, size_t __n);
+#endif
+
+#endif //_GLIBCPP_USE_WCHAR_T
+
+// NB: mbstate_t should be defined in <cwchar>, as per
+// 21.2 p5
+// If not, autoconf will
+// detect this with some configure time magic and define
+// _GLIBCPP_NEED_MBSTATE_T (see config.h in the build directory.)
+#ifdef _GLIBCPP_NEED_MBSTATE_T
+ typedef struct
+ {
+ int __fill[6];
+ } mbstate_t;
+#endif
+}
+
+
+#endif // _CPP_CWCHAR
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_cwctype.h b/libstdc++-v3/bits/std_cwctype.h
new file mode 100644
index 0000000..97db4b8
--- /dev/null
+++ b/libstdc++-v3/bits/std_cwctype.h
@@ -0,0 +1,164 @@
+// -*- C++ -*- forwarding header.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: <cwctype>
+//
+
+#ifndef _CPP_CWCTYPE
+#define _CPP_CWCTYPE 1
+
+// This keeps isanum, et al from being propagated as macros.
+#if __linux__
+#define __NO_WCTYPE 1
+#endif
+
+# include_next <wctype.h>
+
+// Sequester the C non-inline implementations in the _C_Swamp::
+// namespace, and provide C++ inlines for them in the std:: namespace
+// where they belong.
+
+namespace std
+{
+
+#ifdef towupper
+ inline wint_t
+ _S_towupper_helper(wint_t __wc) { return towupper(__wc); }
+# undef towupper
+ inline wint_t
+ towupper(wint_t __wc) { return _S_towupper_helper(__wc); }
+#endif
+
+#ifdef towlower
+ inline wint_t
+ _S_towlower_helper(wint_t __wc) { return towlower(__wc); }
+# undef towlower
+ inline wint_t
+ towlower(wint_t __wc) { return _S_towlower_helper(__wc); }
+#endif
+
+#ifdef iswspace
+ inline int
+ _S_iswspace_helper(wint_t __wc) { return iswspace(__wc); }
+# undef iswspace
+ inline int
+ iswspace(wint_t __wc) { return _S_iswspace_helper(__wc); }
+#endif
+
+#ifdef iswprint
+ inline int
+ _S_iswprint_helper(wint_t __wc) { return iswprint(__wc); }
+# undef iswprint
+ inline int
+ iswprint(wint_t __wc) { return _S_iswprint_helper(__wc); }
+#endif
+
+#ifdef iswcntrl
+ inline int
+ _S_iswcntrl_helper(wint_t __wc) { return iswcntrl(__wc); }
+# undef iswcntrl
+ inline int
+ iswcntrl(wint_t __wc) { return _S_iswcntrl_helper(__wc); }
+#endif
+
+#ifdef iswupper
+ inline int
+ _S_iswupper_helper(wint_t __wc) { return iswupper(__wc); }
+# undef iswupper
+ inline int
+ iswupper(wint_t __wc) { return _S_iswupper_helper(__wc); }
+#endif
+
+#ifdef iswlower
+ inline int
+ _S_iswlower_helper(wint_t __wc) { return iswlower(__wc); }
+# undef iswlower
+ inline int
+ iswlower(wint_t __wc) { return _S_iswlower_helper(__wc); }
+#endif
+
+#ifdef iswalpha
+ inline int
+ _S_iswalpha_helper(wint_t __wc) { return iswalpha(__wc); }
+# undef iswalpha
+ inline int
+ iswalpha(wint_t __wc) { return _S_iswalpha_helper(__wc); }
+#endif
+
+#ifdef iswdigit
+ inline int
+ _S_iswdigit_helper(wint_t __wc) { return iswdigit(__wc); }
+# undef iswdigit
+ inline int
+ iswdigit(wint_t __wc) { return _S_iswdigit_helper(__wc); }
+#endif
+
+#ifdef iswpunct
+ inline int
+ _S_iswpunct_helper(wint_t __wc) { return iswpunct(__wc); }
+# undef iswpunct
+ inline int
+ iswpunct(wint_t __wc) { return _S_iswpunct_helper(__wc); }
+#endif
+
+#ifdef iswxdigit
+ inline int
+ _S_iswxdigit_helper (wint_t __wc) { return iswxdigit(__wc); }
+# undef iswxdigit
+ inline int
+ iswxdigit(wint_t __wc) { return _S_iswxdigit_helper(__wc); }
+#endif
+
+#ifdef iswalnum
+ inline int
+ _S_iswalnum_helper(wint_t __wc) { return iswalnum(__wc); }
+# undef iswalnum
+ inline int
+ iswalnum(wint_t __wc) { return _S_iswalnum_helper(__wc); }
+#endif
+
+#ifdef iswgraph
+ inline int
+ _S_iswgraph_helper(wint_t __wc) { return iswgraph(__wc); }
+# undef iswgraph
+ inline int
+ iswgraph(wint_t __wc) { return _S_iswgraph_helper(__wc); }
+#endif
+
+} // namespace std
+
+#endif // _CPP_CWCTYPE
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_deque.h b/libstdc++-v3/bits/std_deque.h
new file mode 100644
index 0000000..574ab31
--- /dev/null
+++ b/libstdc++-v3/bits/std_deque.h
@@ -0,0 +1,41 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_DEQUE
+#define _CPP_DEQUE 1
+
+#include <bits/stl_range_errors.h>
+#include <bits/stl_algobase.h>
+#include <bits/stl_alloc.h>
+#include <bits/stl_construct.h>
+#include <bits/stl_uninitialized.h>
+#include <bits/stl_deque.h>
+
+#endif /* _CPP_DEQUE */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_exception.h b/libstdc++-v3/bits/std_exception.h
new file mode 100644
index 0000000..66cf46d
--- /dev/null
+++ b/libstdc++-v3/bits/std_exception.h
@@ -0,0 +1,80 @@
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+#ifndef _CPP_EXCEPTION
+#define _CPP_EXCEPTION 1
+
+#ifdef __GNUG__
+#include_next <exception>
+#else
+
+#include <bits/stl_config.h>
+
+__STL_BEGIN_NAMESPACE
+
+ // 18.6 Exception handling
+ class exception;
+ class bad_exception;
+
+ typedef void (*unexpected_handler)();
+ unexpected_handler set_unexpected(unexpected_handler) throw();
+ void unexpected();
+ typedef void (*terminate_handler)();
+ terminate_handler set_terminate(terminate_handler) throw();
+ void terminate();
+ bool uncaught_exception();
+
+ // 18.6.1 Class exception
+ class exception {
+ public:
+ exception() throw();
+ exception(const exception&) throw();
+ exception& operator=(const exception&) throw();
+ virtual ~exception() throw();
+ virtual const char* what() const throw();
+ };
+
+ // 18.6.2.1 Class bad_exception
+ class bad_exception : public exception {
+ public:
+ bad_exception() throw();
+ bad_exception(const bad_exception&) throw();
+ bad_exception& operator=(const bad_exception&) throw();
+ virtual ~bad_exception() throw();
+ virtual const char* what() const throw();
+ };
+
+__STL_END_NAMESPACE
+
+#endif /* __GNUG__ */
+
+#endif /* _CPP_EXCEPTION */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_fstream.h b/libstdc++-v3/bits/std_fstream.h
new file mode 100644
index 0000000..0ebbc76
--- /dev/null
+++ b/libstdc++-v3/bits/std_fstream.h
@@ -0,0 +1,386 @@
+// File based streams -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.8 File-based streams
+//
+
+#ifndef _CPP_FSTREAM
+#define _CPP_FSTREAM 1
+
+#include <bits/std_istream.h>
+#include <bits/std_ostream.h>
+#include <bits/basic_file.h>
+#include <bits/std_locale.h> // For codecvt
+#include <bits/c++threads.h> // For __mutext_type
+
+namespace std {
+
+ template<typename _CharT, typename _Traits>
+ class basic_filebuf : public basic_streambuf<_CharT, _Traits>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+
+ // Non-standard Types:
+ typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
+ typedef basic_filebuf<_CharT, _Traits> __filebuf_type;
+ typedef __basic_file __file_type;
+ typedef typename _Traits::state_type __state_type;
+ typedef codecvt<_CharT, char, __state_type> __codecvt_type;
+ typedef codecvt<_CharT, char, __state_type>::result __res_type;
+
+ friend ios_base; // For sync_with_stdio.
+
+ private:
+ // Data Members:
+ __file_type* _M_file;
+ bool _M_last_overflowed; // XXX Needed?
+ __state_type _M_state_cur;// Current state type for codecvt.
+ __state_type _M_state_beg;
+ const __codecvt_type* _M_fcvt; // Cached value from use_facet.
+ __mutext_type _M_lock;
+
+ public:
+ // Constructors/destructor:
+ basic_filebuf();
+
+ // Non-standard ctor:
+ basic_filebuf(int __fd, const char* __name = "unknown",
+ ios_base::openmode __mode = ios_base::in | ios_base::out);
+
+ virtual
+ ~basic_filebuf()
+ {
+ this->close();
+ _M_fcvt = NULL;
+ delete _M_file;
+ _M_file = NULL;
+ _M_last_overflowed = false;
+ }
+
+ // Members:
+ bool
+ is_open(void) const { return _M_file ? _M_file->is_open() : false; }
+
+ __filebuf_type*
+ open(const char* __s, ios_base::openmode __mode);
+
+ __filebuf_type*
+ close(void);
+
+ protected:
+ // Common initialization code for both ctors goes here.
+ void
+ _M_init_filebuf(void);
+
+ // Overridden virtual functions:
+ virtual streamsize
+ showmanyc(void);
+
+ // Stroustrup, 1998, p. 628
+ // underflow() and uflow() functions are called to get the next
+ // charater from the real input source when the buffer is empty.
+ // Buffered input uses underflow()
+ virtual int_type
+ underflow(void);
+
+ virtual int_type
+ pbackfail(int_type __c = _Traits::eof());
+
+ // NB: For what the standard expects of the overflow function,
+ // see _M_really_overflow(), below. Because basic_streambuf's
+ // sputc/sputn call overflow directly, and the complications of
+ // this implementation's setting of the initial pointers all
+ // equal to _M_buf when initializing, it seems essential to have
+ // this in actuality be a helper function that checks for the
+ // eccentricities of this implementation, and then call
+ // overflow() if indeed the buffer is full.
+ virtual int_type
+ overflow(int_type __c = _Traits::eof());
+
+ // Stroustrup, 1998, p 648
+ // The overflow() function is called to transfer characters to the
+ // real output destination when the buffer is full. A call to
+ // overflow(c) outputs the contents of the buffer plus the
+ // character c.
+ // 27.5.2.4.5
+ // Consume some sequence of the characters in the pending sequence.
+ int_type
+ _M_really_overflow(int_type __c = _Traits::eof());
+
+ virtual __streambuf_type*
+ setbuf(char_type* __s, streamsize __n)
+ {
+ if (!this->is_open() && __s == 0 && __n == 0)
+ _M_buf_size = 0;
+ _M_last_overflowed = false;
+ return this;
+ }
+
+ virtual pos_type
+ seekoff(off_type __off, ios_base::seekdir __way,
+ ios_base::openmode __mode = ios_base::in | ios_base::out);
+
+ virtual pos_type
+ seekpos(pos_type __pos,
+ ios_base::openmode __mode = ios_base::in | ios_base::out);
+
+ virtual int
+ sync(void)
+ {
+ bool __testput = _M_out_cur && _M_out_beg < _M_out_end;
+ if (__testput)
+ {
+ // Make sure that libio resyncs its idea of the file position
+ // with the external file.
+ _M_file->sync();
+
+ // Need to restore current position. This interpreted as
+ // the position of the external byte sequence (_M_file)
+ // plus the offset in the current internal buffer
+ // (_M_out_beg - _M_out_cur)
+ __c_streampos __cur = _M_file->seekoff(0, ios_base::cur);
+ off_type __off = _M_out_cur - _M_out_beg;
+ this->_M_really_overflow();
+ _M_file->seekpos(__cur + __off);
+ }
+ _M_last_overflowed = false;
+ return 0;
+ }
+
+ virtual void
+ imbue(const locale& __loc);
+
+ void
+ _M_output_unshift();
+ };
+
+ typedef basic_filebuf<char> filebuf;
+ typedef basic_filebuf<wchar_t> wfilebuf;
+
+ // 27.8.1.5 Template class basic_ifstream
+ template<typename _CharT, typename _Traits>
+ class basic_ifstream : public basic_istream<_CharT, _Traits>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+
+ // Non-standard types:
+ typedef basic_filebuf<_CharT, _Traits> __filebuf_type;
+ typedef basic_istream<_CharT, _Traits> __istream_type;
+
+ // Constructors/Destructors:
+ basic_ifstream()
+ : __istream_type(new __filebuf_type())
+ { }
+
+ explicit
+ basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
+ : __istream_type(new __filebuf_type())
+ { this->open(__s, __mode); }
+
+ ~basic_ifstream()
+ {
+ delete _M_streambuf;
+ _M_streambuf = NULL;
+ }
+
+ // Members:
+ __filebuf_type*
+ rdbuf() const
+ { return static_cast<__filebuf_type*>(_M_streambuf); }
+
+ bool
+ is_open(void) { return rdbuf()->is_open(); }
+
+ void
+ open(const char* __s, ios_base::openmode __mode = ios_base::in)
+ {
+ if (rdbuf()->open(__s, __mode | ios_base::in) == NULL)
+ this->setstate(ios_base::failbit);
+ }
+
+ void
+ close(void)
+ {
+ if (!rdbuf()->close())
+ this->setstate(ios_base::failbit);
+ }
+ };
+
+ // 27.8.1.8 Template class basic_ofstream
+ template<typename _CharT, typename _Traits>
+ class basic_ofstream : public basic_ostream<_CharT,_Traits>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+
+ // Non-standard types:
+ typedef basic_filebuf<_CharT, _Traits> __filebuf_type;
+ typedef basic_ostream<_CharT, _Traits> __ostream_type;
+
+ // Constructors:
+ basic_ofstream()
+ : __ostream_type(new __filebuf_type())
+ { }
+
+ explicit
+ basic_ofstream(const char* __s,
+ ios_base::openmode __mode = ios_base::out|ios_base::trunc)
+ : __ostream_type(new __filebuf_type())
+ { this->open(__s, __mode); }
+
+ ~basic_ofstream()
+ {
+ delete _M_streambuf;
+ _M_streambuf = NULL;
+ }
+
+ // Members:
+ __filebuf_type*
+ rdbuf(void) const
+ { return static_cast<__filebuf_type*>(_M_streambuf); }
+
+ bool
+ is_open(void) { return rdbuf()->is_open(); }
+
+ void
+ open(const char* __s,
+ ios_base::openmode __mode = ios_base::out | ios_base::trunc)
+ {
+ if (!rdbuf()->open(__s, __mode | ios_base::out))
+ this->setstate (ios_base::failbit);
+ }
+
+ void
+ close(void)
+ {
+ if (!rdbuf()->close())
+ setstate (ios_base::failbit);
+ }
+ };
+
+ typedef basic_ofstream<char> ofstream;
+ typedef basic_ofstream<wchar_t> wofstream;
+
+
+ // 27.8.1.11 Template class basic_fstream
+ template<typename _CharT, typename _Traits>
+ class basic_fstream : public basic_iostream<_CharT, _Traits>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+
+ // Non-standard types:
+ typedef basic_filebuf<_CharT, _Traits> __filebuf_type;
+ typedef basic_ios<_CharT, _Traits> __ios_type;
+ typedef basic_iostream<_CharT, _Traits> __iostream_type;
+
+ // Constructors/destructor:
+ basic_fstream()
+ : __iostream_type(new __filebuf_type())
+ { }
+
+ explicit
+ basic_fstream(const char* __s,
+ ios_base::openmode __mode = ios_base::in | ios_base::out)
+ : __iostream_type(new __filebuf_type())
+ { this->open(__s, __mode); }
+
+ ~basic_fstream()
+ {
+ delete _M_streambuf;
+ _M_streambuf = NULL;
+ }
+
+ // Members:
+ __filebuf_type*
+ rdbuf(void) const
+ { return static_cast<__filebuf_type*>(_M_streambuf); }
+
+ bool
+ is_open(void) { return rdbuf()->is_open(); }
+
+ void
+ open(const char* __s,
+ ios_base::openmode __mode = ios_base::in | ios_base::out)
+ {
+ if (!rdbuf()->open(__s, __mode))
+ setstate (ios_base::failbit);
+ }
+
+ void
+ close(void)
+ {
+ if (!rdbuf()->close())
+ setstate (ios_base::failbit);
+ }
+ };
+
+ typedef basic_fstream<char> fstream;
+ typedef basic_fstream<wchar_t> wfstream;
+
+} // namespace std
+
+
+#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
+# define export
+#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
+# include <bits/fstream.tcc>
+#endif
+#endif
+
+#endif /* _CPP_FSTREAM */
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_functional.h b/libstdc++-v3/bits/std_functional.h
new file mode 100644
index 0000000..0336c2a
--- /dev/null
+++ b/libstdc++-v3/bits/std_functional.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ */
+
+#ifndef _CPP_FUNCTIONAL
+#define _CPP_FUNCTIONAL
+
+#include <bits/stl_config.h>
+#include <bits/std_cstddef.h>
+#include <bits/stl_function.h>
+
+#endif /* _CPP_FUNCTIONAL */
+
+// Local Variables:
+// mode:C++
+// End:
+
diff --git a/libstdc++-v3/bits/std_iomanip.h b/libstdc++-v3/bits/std_iomanip.h
new file mode 100644
index 0000000..6fa4938
--- /dev/null
+++ b/libstdc++-v3/bits/std_iomanip.h
@@ -0,0 +1,219 @@
+// Standard stream manipulators -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.6.3 Standard manipulators
+//
+
+#ifndef _CPP_IOMANIP
+#define _CPP_IOMANIP 1
+
+#include <bits/c++config.h>
+#include <bits/std_istream.h>
+#include <bits/std_functional.h>
+
+namespace std {
+
+ struct _Resetiosflags { ios_base::fmtflags _M_mask; };
+
+ inline _Resetiosflags
+ resetiosflags(ios_base::fmtflags __mask)
+ {
+ _Resetiosflags __x;
+ __x._M_mask = __mask;
+ return __x;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_istream<_CharT,_Traits>&
+ operator>>(basic_istream<_CharT,_Traits>& __is, _Resetiosflags __f)
+ {
+ __is.setf(ios_base::fmtflags(0), __f._M_mask);
+ return __is;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_ostream<_CharT,_Traits>&
+ operator<<(basic_ostream<_CharT,_Traits>& __os, _Resetiosflags __f)
+ {
+ __os.setf(ios_base::fmtflags(0), __f._M_mask);
+ return __os;
+ }
+
+
+ struct _Setiosflags { ios_base::fmtflags _M_mask; };
+
+ inline _Setiosflags
+ setiosflags (ios_base::fmtflags __mask)
+ {
+ _Setiosflags __x;
+ __x._M_mask = __mask;
+ return __x;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_istream<_CharT,_Traits>&
+ operator>>(basic_istream<_CharT,_Traits>& __is, _Setiosflags __f)
+ {
+ __is.setf(__f._M_mask);
+ return __is;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_ostream<_CharT,_Traits>&
+ operator<<(basic_ostream<_CharT,_Traits>& __os, _Setiosflags __f)
+ {
+ __os.setf(__f._M_mask);
+ return __os;
+ }
+
+
+ struct _Setbase { int _M_base; };
+
+ inline _Setbase
+ setbase (int __base)
+ {
+ _Setbase __x;
+ __x._M_base = __base;
+ return __x;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_istream<_CharT,_Traits>&
+ operator>>(basic_istream<_CharT,_Traits>& __is, _Setbase __f)
+ {
+ __is.setf(__f._M_base == 8 ? ios_base::oct :
+ __f._M_base == 10 ? ios_base::dec :
+ __f._M_base == 16 ? ios_base::hex :
+ ios_base::fmtflags(0), ios_base::basefield);
+ return __is;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_ostream<_CharT,_Traits>&
+ operator<<(basic_ostream<_CharT,_Traits>& __os, _Setbase __f)
+ {
+ __os.setf(__f._M_base == 8 ? ios_base::oct :
+ __f._M_base == 10 ? ios_base::dec :
+ __f._M_base == 16 ? ios_base::hex :
+ ios_base::fmtflags(0), ios_base::basefield);
+ return __os;
+ }
+
+
+ template<class _CharT>
+ struct _Setfill { _CharT _M_c; };
+
+ template<class _CharT>
+ _Setfill<_CharT>
+ setfill(_CharT __c)
+ {
+ _Setfill<_CharT> __x;
+ __x._M_c = __c;
+ return __x;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_istream<_CharT,_Traits>&
+ operator>>(basic_istream<_CharT,_Traits>& __is, _Setfill<_CharT> __f)
+ {
+ __is.fill(__f._M_c);
+ return __is;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_ostream<_CharT,_Traits>&
+ operator<<(basic_ostream<_CharT,_Traits>& __os, _Setfill<_CharT> __f)
+ {
+ __os.fill(__f._M_c);
+ return __os;
+ }
+
+
+ struct _Setprecision { int _M_n; };
+
+ inline _Setprecision
+ setprecision(int __n)
+ {
+ _Setprecision __x;
+ __x._M_n = __n;
+ return __x;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_istream<_CharT,_Traits>&
+ operator>>(basic_istream<_CharT,_Traits>& __is, _Setprecision __f)
+ {
+ __is.precision(__f._M_n);
+ return __is;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_ostream<_CharT,_Traits>&
+ operator<<(basic_ostream<_CharT,_Traits>& __os, _Setprecision __f)
+ {
+ __os.precision(__f._M_n);
+ return __os;
+ }
+
+
+ struct _Setw { int _M_n; };
+
+ inline _Setw
+ setw(int __n)
+ {
+ _Setw __x;
+ __x._M_n = __n;
+ return __x;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_istream<_CharT,_Traits>&
+ operator>>(basic_istream<_CharT,_Traits>& __is, _Setw __f)
+ {
+ __is.width(__f._M_n);
+ return __is;
+ }
+
+ template <class _CharT, class _Traits>
+ basic_ostream<_CharT,_Traits>&
+ operator<<(basic_ostream<_CharT,_Traits>& __os, _Setw __f)
+ {
+ __os.width(__f._M_n);
+ return __os;
+ }
+
+} // namespace std
+
+#endif /* __IOMANIP */
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_ios.h b/libstdc++-v3/bits/std_ios.h
new file mode 100644
index 0000000..7c54547
--- /dev/null
+++ b/libstdc++-v3/bits/std_ios.h
@@ -0,0 +1,52 @@
+// Iostreams base classes -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.4 Iostreams base classes
+//
+
+#ifndef _CPP_IOS
+#define _CPP_IOS 1
+
+#include <bits/std_iosfwd.h>
+#include <bits/std_exception.h> // For ios_base::failure
+#include <bits/char_traits.h> // For char_traits, streamoff, streamsize, fpos
+#include <bits/stl_string_fwd.h>// For string.
+#include <bits/std_cstdio.h> // For SEEK_SET, SEEK_CUR, SEEK_END
+# include <bits/localefwd.h> // For class locale
+#include <bits/ios_base.h> // For ios_base declarations.
+#include <bits/std_streambuf.h>
+#include <bits/basic_ios.h>
+
+#endif /* _CPP_IOS */
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_iosfwd.h b/libstdc++-v3/bits/std_iosfwd.h
new file mode 100644
index 0000000..3a8eb05
--- /dev/null
+++ b/libstdc++-v3/bits/std_iosfwd.h
@@ -0,0 +1,157 @@
+// Forwarding declarations -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.2 Forward declarations
+//
+
+#ifndef _CPP_IOSFWD
+#define _CPP_IOSFWD 1
+
+#include <bits/c++config.h>
+#include <bits/std_cwchar.h> //For mbstate_t
+
+namespace std {
+
+ // Generic declarations.
+ template<typename _CharT> struct char_traits;
+ template<typename _Alloc> class allocator;
+
+ // Forward declarations
+ template<> class char_traits<char>;
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<> class char_traits<wchar_t>;
+#endif
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT> >
+ class basic_ios;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT> >
+ class basic_streambuf;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT> >
+ class basic_istream;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT> >
+ class basic_ostream;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT> >
+ class basic_iostream;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT>,
+ typename _Alloc = allocator<_CharT> >
+ class basic_stringbuf;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT>,
+ typename _Alloc = allocator<_CharT> >
+ class basic_istringstream;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT>,
+ typename _Alloc = allocator<_CharT> >
+ class basic_ostringstream;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT>,
+ typename _Alloc = allocator<_CharT> >
+ class basic_stringstream;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT> >
+ class basic_filebuf;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT> >
+ class basic_ifstream;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT> >
+ class basic_ofstream;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT> >
+ class basic_fstream;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT> >
+ class istreambuf_iterator;
+
+ template<typename _CharT, typename _Traits = char_traits<_CharT> >
+ class ostreambuf_iterator;
+
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ // Not included.
+ class ios_base;
+#endif
+
+ template<class _State> struct fpos;
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ // Can't have self-recursive types for streampos.
+ // 21.1.3.1 char_traits sets size_type to streampos
+ // 27.4.1
+ // And here, where streampos is typedefed to fpos<traits::state_type>
+ typedef fpos<mbstate_t> streampos;
+# ifdef _GLIBCPP_USE_WCHAR_T
+ typedef fpos<mbstate_t> wstreampos;
+# endif
+#endif
+
+ typedef basic_ios<char> ios;
+ typedef basic_streambuf<char> streambuf;
+ typedef basic_istream<char> istream;
+ typedef basic_ostream<char> ostream;
+ typedef basic_iostream<char> iostream;
+ typedef basic_stringbuf<char> stringbuf;
+ typedef basic_istringstream<char> istringstream;
+ typedef basic_ostringstream<char> ostringstream;
+ typedef basic_stringstream<char> stringstream;
+ typedef basic_filebuf<char> filebuf;
+ typedef basic_ifstream<char> ifstream;
+ typedef basic_ofstream<char> ofstream;
+ typedef basic_fstream<char> fstream;
+
+#ifdef _GLIBCPP_USE_WCHAR_T
+ typedef basic_ios<wchar_t> wios;
+ typedef basic_streambuf<wchar_t> wstreambuf;
+ typedef basic_istream<wchar_t> wistream;
+ typedef basic_ostream<wchar_t> wostream;
+ typedef basic_iostream<wchar_t> wiostream;
+ typedef basic_stringbuf<wchar_t> wstringbuf;
+ typedef basic_istringstream<wchar_t> wistringstream;
+ typedef basic_ostringstream<wchar_t> wostringstream;
+ typedef basic_stringstream<wchar_t> wstringstream;
+ typedef basic_filebuf<wchar_t> wfilebuf;
+ typedef basic_ifstream<wchar_t> wifstream;
+ typedef basic_ofstream<wchar_t> wofstream;
+ typedef basic_fstream<wchar_t> wfstream;
+#endif
+
+} // namespace std
+
+#endif // _CPP_IOSFWD
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_iostream.h b/libstdc++-v3/bits/std_iostream.h
new file mode 100644
index 0000000..b08d038
--- /dev/null
+++ b/libstdc++-v3/bits/std_iostream.h
@@ -0,0 +1,58 @@
+// Standard iostream objects -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.3 Standard iostream objects
+//
+
+#ifndef _CPP_IOSTREAM
+#define _CPP_IOSTREAM 1
+
+#include <bits/c++config.h>
+#include <bits/std_ostream.h>
+#include <bits/std_istream.h>
+
+namespace std {
+
+ extern istream cin;
+ extern ostream cout;
+ extern ostream cerr;
+ extern ostream clog;
+#ifdef _GLIBCPP_USE_WCHAR_T
+ extern wistream wcin;
+ extern wostream wcout;
+ extern wostream wcerr;
+ extern wostream wclog;
+#endif
+
+ // For construction of filebuffers for cout, cin, cerr, clog et. al.
+ static ios_base::Init __ioinit;
+} // namespace std
+
+#endif /* _CPP_IOSTREAM */
diff --git a/libstdc++-v3/bits/std_istream.h b/libstdc++-v3/bits/std_istream.h
new file mode 100644
index 0000000..baddea4
--- /dev/null
+++ b/libstdc++-v3/bits/std_istream.h
@@ -0,0 +1,307 @@
+// Input streams -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.6.1 Input streams
+//
+
+#ifndef _CPP_ISTREAM
+#define _CPP_ISTREAM 1
+
+#include <bits/std_ios.h>
+#include <bits/std_limits.h> // For numeric_limits
+
+namespace std {
+
+ // 27.6.1.1 Template class basic_istream
+ template<typename _CharT, typename _Traits>
+ class basic_istream : virtual public basic_ios<_CharT, _Traits>
+ {
+ public:
+
+ // Types (inherited from basic_ios (27.4.4)):
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+
+ // Non-standard Types:
+ typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
+ typedef basic_ios<_CharT, _Traits> __ios_type;
+ typedef basic_istream<_CharT, _Traits> __istream_type;
+ typedef istreambuf_iterator<_CharT> __istreambuf_iter;
+ typedef num_get<_CharT, __istreambuf_iter> __numget_type;
+ typedef ctype<_CharT> __ctype_type;
+
+ protected:
+ // Data Members:
+ streamsize _M_gcount;
+
+ public:
+ // 27.6.1.1.1 Constructor/destructor:
+ explicit
+ basic_istream(__streambuf_type* __sb)
+ {
+ this->init(__sb);
+ _M_gcount = streamsize(0);
+ }
+
+ virtual
+ ~basic_istream()
+ {
+ _M_gcount = streamsize(0);
+ _M_fnumget = NULL;
+ }
+
+ // 27.6.1.1.2 Prefix/suffix:
+ class sentry;
+ friend class sentry;
+
+ // 27.6.1.2 Formatted input:
+ // 27.6.1.2.3 basic_istream::operator>>
+ __istream_type&
+ operator>>(__istream_type& (*__pf)(__istream_type&));
+
+ __istream_type&
+ operator>>(__ios_type& (*__pf)(__ios_type&));
+
+ __istream_type&
+ operator>>(ios_base& (*__pf)(ios_base&));
+
+ // 27.6.1.2.2 Arithmetic Extractors
+ __istream_type&
+ operator>>(bool& __n);
+
+ __istream_type&
+ operator>>(short& __n);
+
+ __istream_type&
+ operator>>(unsigned short& __n);
+
+ __istream_type&
+ operator>>(int& __n);
+
+ __istream_type&
+ operator>>(unsigned int& __n);
+
+ __istream_type&
+ operator>>(long& __n);
+
+ __istream_type&
+ operator>>(unsigned long& __n);
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ __istream_type&
+ operator>>(long long& __n);
+
+ __istream_type&
+ operator>>(unsigned long long& __n);
+#endif
+
+ __istream_type&
+ operator>>(float& __f);
+
+ __istream_type&
+ operator>>(double& __f);
+
+ __istream_type&
+ operator>>(long double& __f);
+
+ __istream_type&
+ operator>>(void*& __p);
+
+ __istream_type&
+ operator>>(__streambuf_type* __sb);
+
+ // 27.6.1.3 Unformatted input:
+ inline streamsize
+ gcount(void) const
+ { return _M_gcount; }
+
+ int_type
+ get(void);
+
+ __istream_type&
+ get(char_type& __c);
+
+ __istream_type&
+ get(char_type* __s, streamsize __n, char_type __delim);
+
+ inline __istream_type&
+ get(char_type* __s, streamsize __n)
+ { return get(__s, __n, this->widen('\n')); }
+
+ __istream_type&
+ get(__streambuf_type& __sb, char_type __delim);
+
+ inline __istream_type&
+ get(__streambuf_type& __sb)
+ { return get(__sb, this->widen('\n')); }
+
+ __istream_type&
+ getline(char_type* __s, streamsize __n, char_type __delim);
+
+ inline __istream_type&
+ getline(char_type* __s, streamsize __n)
+ { return getline(__s, __n, this->widen('\n')); }
+
+ __istream_type&
+ ignore(streamsize __n = 1, int_type __delim = traits_type::eof());
+
+ int_type
+ peek(void);
+
+ __istream_type&
+ read(char_type* __s, streamsize __n);
+
+ streamsize
+ readsome(char_type* __s, streamsize __n);
+
+ __istream_type&
+ putback(char_type __c);
+
+ __istream_type&
+ unget(void);
+
+ int
+ sync(void);
+
+ pos_type
+ tellg(void);
+
+ __istream_type&
+ seekg(pos_type);
+
+ __istream_type&
+ seekg(off_type, ios_base::seekdir);
+
+ private:
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ // Not defined.
+ __istream_type&
+ operator=(const __istream_type&);
+
+ basic_istream(const __istream_type&);
+#endif
+ };
+
+ template<typename _CharT, typename _Traits>
+ class basic_istream<_CharT, _Traits>::sentry
+ {
+ public:
+
+ typedef _Traits traits_type;
+ typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
+ typedef basic_istream<_CharT, _Traits> __istream_type;
+ typedef __istream_type::__ctype_type __ctype_type;
+ typedef typename _Traits::int_type __int_type;
+
+ explicit
+ sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
+
+ operator bool() { return _M_ok; }
+
+ private:
+ bool _M_ok;
+ };
+
+ // 27.6.1.2.3 Character extraction templates
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
+
+ template<class _Traits>
+ basic_istream<char, _Traits>&
+ operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
+ { return (__in >> static_cast<char>(__c)); }
+
+ template<class _Traits>
+ basic_istream<char, _Traits>&
+ operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
+ { return (__in >> static_cast<char>(__c)); }
+
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
+
+ template<class _Traits>
+ basic_istream<char,_Traits>&
+ operator>>(basic_istream<char,_Traits>& __in, unsigned char* __s)
+ { return (__in >> reinterpret_cast<char*>(__s)); }
+
+ template<class _Traits>
+ basic_istream<char,_Traits>&
+ operator>>(basic_istream<char,_Traits>& __in, signed char* __s)
+ { return (__in >> reinterpret_cast<char*>(__s)); }
+
+ // 27.6.1.5 Template class basic_iostream
+ template<typename _CharT, typename _Traits>
+ class basic_iostream
+ : public basic_istream<_CharT, _Traits>,
+ public basic_ostream<_CharT, _Traits>
+ {
+ public:
+
+ // Non-standard Types:
+ typedef basic_istream<_CharT, _Traits> __istream_type;
+ typedef basic_ostream<_CharT, _Traits> __ostream_type;
+
+ explicit
+ basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
+ : __istream_type(__sb), __ostream_type(__sb)
+ { }
+
+ virtual
+ ~basic_iostream() { }
+ };
+
+ // 27.6.1.4 Standard basic_istream manipulators
+ template<typename _CharT, typename _Traits>
+ basic_istream<_CharT, _Traits>&
+ ws(basic_istream<_CharT, _Traits>& __is);
+
+} // namespace std
+
+#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
+# define export
+#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
+# include <bits/istream.tcc>
+#endif
+#endif
+
+#endif /* _CPP_ISTREAM */
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_iterator.h b/libstdc++-v3/bits/std_iterator.h
new file mode 100644
index 0000000..643cff9
--- /dev/null
+++ b/libstdc++-v3/bits/std_iterator.h
@@ -0,0 +1,46 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_ITERATOR
+#define _CPP_ITERATOR 1
+
+#include <bits/stl_config.h>
+#include <bits/stl_relops.h>
+#include <bits/std_cstddef.h>
+#include <bits/std_iosfwd.h>
+#include <bits/stl_iterator_base.h>
+#include <bits/stl_iterator.h>
+
+#endif /* _CPP_ITERATOR */
+
+// Local Variables:
+// mode:C++
+// End:
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_list.h b/libstdc++-v3/bits/std_list.h
new file mode 100644
index 0000000..eaf1258
--- /dev/null
+++ b/libstdc++-v3/bits/std_list.h
@@ -0,0 +1,40 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_LIST
+#define _CPP_LIST 1
+
+#include <bits/stl_algobase.h>
+#include <bits/stl_alloc.h>
+#include <bits/stl_construct.h>
+#include <bits/stl_uninitialized.h>
+#include <bits/stl_list.h>
+
+#endif /* _CPP_LIST */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_locale.h b/libstdc++-v3/bits/std_locale.h
new file mode 100644
index 0000000..8510044
--- /dev/null
+++ b/libstdc++-v3/bits/std_locale.h
@@ -0,0 +1,44 @@
+// Locale support -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 22.1 Locales
+//
+
+#ifndef _CPP_LOCALE
+#define _CPP_LOCALE 1
+
+#include <bits/localefwd.h>
+#include <bits/locale_facets.h>
+
+#endif
+
+// Local Variables:
+// mode:c++
+// End:
diff --git a/libstdc++-v3/bits/std_map.h b/libstdc++-v3/bits/std_map.h
new file mode 100644
index 0000000..9390ab8
--- /dev/null
+++ b/libstdc++-v3/bits/std_map.h
@@ -0,0 +1,40 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_MAP
+#define _CPP_MAP 1
+
+#ifndef _CPP_BITS_STL_TREE_H /* XXX is this guard necessary? */
+#include <bits/stl_tree.h>
+#endif
+#include <bits/stl_map.h>
+#include <bits/stl_multimap.h>
+
+#endif /* _CPP_MAP */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_memory.h b/libstdc++-v3/bits/std_memory.h
new file mode 100644
index 0000000..005c7d3
--- /dev/null
+++ b/libstdc++-v3/bits/std_memory.h
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 1997-1999
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ */
+
+#ifndef _CPP_MEMORY
+#define _CPP_MEMORY 1
+
+#include <bits/stl_algobase.h>
+#include <bits/stl_alloc.h>
+#include <bits/stl_construct.h>
+#include <bits/stl_iterator_base.h> //for iterator_traits
+#include <bits/stl_tempbuf.h>
+#include <bits/stl_uninitialized.h>
+#include <bits/stl_raw_storage_iter.h>
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__SGI_STL_USE_AUTO_PTR_CONVERSIONS) && \
+ defined(__STL_MEMBER_TEMPLATES)
+
+ template<class _Tp1> struct auto_ptr_ref {
+ _Tp1* _M_ptr;
+ auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
+};
+
+#endif
+
+template <class _Tp> class auto_ptr {
+private:
+ _Tp* _M_ptr;
+
+public:
+ typedef _Tp element_type;
+
+ explicit auto_ptr(_Tp* __p = 0) __STL_NOTHROW : _M_ptr(__p) {}
+ auto_ptr(auto_ptr& __a) __STL_NOTHROW : _M_ptr(__a.release()) {}
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _Tp1> auto_ptr(auto_ptr<_Tp1>& __a) __STL_NOTHROW
+ : _M_ptr(__a.release()) {}
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ auto_ptr& operator=(auto_ptr& __a) __STL_NOTHROW {
+ reset(__a.release());
+ return *this;
+ }
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _Tp1>
+ auto_ptr& operator=(auto_ptr<_Tp1>& __a) __STL_NOTHROW {
+ reset(__a.release());
+ return *this;
+ }
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ ~auto_ptr() __STL_NOTHROW { delete _M_ptr; }
+
+ _Tp& operator*() const __STL_NOTHROW {
+ return *_M_ptr;
+ }
+ _Tp* operator->() const __STL_NOTHROW {
+ return _M_ptr;
+ }
+ _Tp* get() const __STL_NOTHROW {
+ return _M_ptr;
+ }
+ _Tp* release() __STL_NOTHROW {
+ _Tp* __tmp = _M_ptr;
+ _M_ptr = 0;
+ return __tmp;
+ }
+ void reset(_Tp* __p = 0) __STL_NOTHROW {
+ if (__p != _M_ptr) {
+ delete _M_ptr;
+ _M_ptr = __p;
+ }
+ }
+
+ // According to the C++ standard, these conversions are required. Most
+ // present-day compilers, however, do not enforce that requirement---and,
+ // in fact, most present-day compilers do not support the language
+ // features that these conversions rely on.
+
+#if defined(__SGI_STL_USE_AUTO_PTR_CONVERSIONS) && \
+ defined(__STL_MEMBER_TEMPLATES)
+
+public:
+ auto_ptr(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW
+ : _M_ptr(__ref._M_ptr) {}
+
+ auto_ptr& operator=(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW {
+ if (__ref._M_ptr != this->get()) {
+ delete _M_ptr;
+ _M_ptr = __ref._M_ptr;
+ }
+ return *this;
+ }
+
+ template <class _Tp1> operator auto_ptr_ref<_Tp1>() __STL_NOTHROW
+ { return auto_ptr_ref<_Tp>(this->release()); }
+ template <class _Tp1> operator auto_ptr<_Tp1>() __STL_NOTHROW
+ { return auto_ptr<_Tp1>(this->release()); }
+
+#endif /* auto ptr conversions && member templates */
+};
+
+__STL_END_NAMESPACE
+
+#endif /* _CPP_MEMORY */
+
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_new.h b/libstdc++-v3/bits/std_new.h
new file mode 100644
index 0000000..1ac2dd0
--- /dev/null
+++ b/libstdc++-v3/bits/std_new.h
@@ -0,0 +1,81 @@
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+#ifndef _CPP_NEW
+#define _CPP_NEW 1
+
+#include <bits/c++config.h>
+
+#ifdef __GNUG__
+# include_next <new>
+#else
+
+#include <bits/std_exception.h>
+
+
+// 18.4 Dynamic memory management
+
+__STL_BEGIN_NAMESPACE
+
+ class bad_alloc;
+ struct nothrow_t {};
+ extern const nothrow_t nothrow;
+ typedef void (*new_handler)();
+ new_handler set_new_handler(new_handler) throw();
+
+ class bad_alloc : public exception {
+ public:
+ bad_alloc() throw();
+ bad_alloc(const bad_alloc&) throw();
+ bad_alloc& operator=(const bad_alloc&) throw();
+ virtual ~bad_alloc() throw();
+ virtual const char* what() const throw();
+ };
+
+__STL_END_NAMESPACE
+
+ void* operator new(__STD::size_t) throw(__STD::bad_alloc);
+ void* operator new(__STD::size_t, const __STD::nothrow_t&) throw();
+ void operator delete(void*) throw();
+ void operator delete(void*, const __STD::nothrow_t&) throw();
+ void* operator new[](__STD::size_t) throw(__STD::bad_alloc);
+ void* operator new[](__STD::size_t, const __STD::nothrow_t&) throw();
+ void operator delete[](void*) throw();
+ void operator delete[](void*, const __STD::nothrow_t&) throw();
+ void* operator new (__STD::size_t, void*) throw();
+ void* operator new[](__STD::size_t, void*) throw();
+ void operator delete (void*, void*) throw();
+ void operator delete[](void*, void*) throw();
+
+#endif
+
+#endif /* _CPP_NEW */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_numeric.h b/libstdc++-v3/bits/std_numeric.h
new file mode 100644
index 0000000..8b7c6fd
--- /dev/null
+++ b/libstdc++-v3/bits/std_numeric.h
@@ -0,0 +1,41 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_NUMERIC
+#define _CPP_NUMERIC 1
+
+#include <bits/stl_config.h>
+#include <bits/stl_relops.h>
+#include <bits/std_cstddef.h>
+#include <bits/std_iterator.h>
+#include <bits/stl_function.h>
+#include <bits/stl_numeric.h>
+
+#endif /* _CPP_NUMERIC */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_ostream.h b/libstdc++-v3/bits/std_ostream.h
new file mode 100644
index 0000000..eff25b9
--- /dev/null
+++ b/libstdc++-v3/bits/std_ostream.h
@@ -0,0 +1,288 @@
+// Output streams -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.6.2 Output streams
+//
+
+#ifndef _CPP_OSTREAM
+#define _CPP_OSTREAM 1
+
+#include <bits/std_ios.h>
+
+namespace std {
+
+ // 27.6.2.1 Template class basic_ostream
+ template<typename _CharT, typename _Traits>
+ class basic_ostream : virtual public basic_ios<_CharT, _Traits>
+ {
+ public:
+
+ // Types (inherited from basic_ios (27.4.4)):
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+
+ // Non-standard Types:
+ typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
+ typedef basic_ios<_CharT, _Traits> __ios_type;
+ typedef basic_ostream<_CharT, _Traits> __ostream_type;
+ typedef ostreambuf_iterator<_CharT> __ostreambuf_iter;
+ typedef num_put<_CharT, __ostreambuf_iter> __numput_type;
+ typedef ctype<_CharT> __ctype_type;
+
+ // 27.6.2.2 Constructor/destructor:
+ explicit
+ basic_ostream(__streambuf_type* __sb)
+ { this->init(__sb); }
+
+ virtual
+ ~basic_ostream()
+ { _M_fnumput = NULL; }
+
+ // 27.6.2.3 Prefix/suffix:
+ class sentry;
+ friend class sentry;
+
+ // 27.6.2.5 Formatted output:
+ // 27.6.2.5.3 basic_ostream::operator<<
+ __ostream_type&
+ operator<<(__ostream_type& (*__pf)(__ostream_type&));
+
+ __ostream_type&
+ operator<<(__ios_type& (*__pf)(__ios_type&));
+
+ __ostream_type&
+ operator<<(ios_base& (*__pf) (ios_base&));
+
+ // 27.6.2.5.2 Arithmetic Inserters
+ __ostream_type&
+ operator<<(long __n);
+
+ __ostream_type&
+ operator<<(unsigned long __n);
+
+ __ostream_type&
+ operator<<(bool __n);
+
+ __ostream_type&
+ operator<<(short __n)
+ {
+ ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
+ if (__fmt & ios_base::oct || __fmt & ios_base::hex)
+ return this->operator<<(static_cast<unsigned long>
+ (static_cast<unsigned short>(__n)));
+ else
+ return this->operator<<(static_cast<long>(__n));
+ }
+
+ __ostream_type&
+ operator<<(unsigned short __n)
+ { return this->operator<<(static_cast<unsigned long>(__n)); }
+
+ __ostream_type&
+ operator<<(int __n)
+ {
+ ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
+ if (__fmt & ios_base::oct || __fmt & ios_base::hex)
+ return this->operator<<(static_cast<unsigned long>
+ (static_cast<unsigned int>(__n)));
+ else
+ return this->operator<<(static_cast<long>(__n));
+ }
+
+ __ostream_type&
+ operator<<(unsigned int __n)
+ { return this->operator<<(static_cast<unsigned long>(__n)); }
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+ __ostream_type&
+ operator<<(long long __n);
+
+ __ostream_type&
+ operator<<(unsigned long long __n);
+#endif
+
+ __ostream_type&
+ operator<<(double __f);
+
+ __ostream_type&
+ operator<<(float __f)
+ { return this->operator<<(static_cast<double>(__f)); }
+
+ __ostream_type&
+ operator<<(long double __f);
+
+ __ostream_type&
+ operator<<(const void* __p);
+
+ __ostream_type&
+ operator<<(__streambuf_type* __sb);
+
+ // Unformatted output:
+ __ostream_type&
+ put(char_type __c);
+
+ __ostream_type&
+ write(const char_type* __s, streamsize __n);
+
+ __ostream_type&
+ flush();
+
+ // Seeks:
+ pos_type
+ tellp();
+
+ __ostream_type&
+ seekp(pos_type);
+
+ __ostream_type&
+ seekp(off_type, ios_base::seekdir);
+
+ private:
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ // Not defined.
+ __ostream_type&
+ operator=(const __ostream_type&);
+
+ basic_ostream(const __ostream_type&);
+#endif
+ };
+
+ // 27.6.2.3 Class basic_ostream::sentry
+ template <typename _CharT, typename _Traits>
+ class basic_ostream<_CharT, _Traits>::sentry
+ {
+ // Data Members:
+ bool _M_ok;
+ basic_ostream<_CharT,_Traits>& _M_os;
+
+ public:
+ explicit
+ sentry(basic_ostream<_CharT,_Traits>& __os);
+
+ ~sentry()
+ {
+ // XXX MT
+ if (_M_os.flags() & ios_base::unitbuf && !uncaught_exception())
+ {
+ // Can't call flush directly or else will get into recursive lock.
+ if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
+ _M_os.setstate(ios_base::badbit);
+ }
+ }
+
+ operator bool()
+ { return _M_ok; }
+ };
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c);
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
+ { return (__out << __out.widen(__c)); }
+
+ // Specialization
+ template <class _Traits>
+ basic_ostream<char, _Traits>&
+ operator<<(basic_ostream<char, _Traits>& __out, char __c);
+
+ // Signed and unsigned
+ template<class _Traits>
+ basic_ostream<char, _Traits>&
+ operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
+ { return (__out << static_cast<char>(__c)); }
+
+ template<class _Traits>
+ basic_ostream<char, _Traits>&
+ operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
+ { return (__out << static_cast<char>(__c)); }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s);
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits> &
+ operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s);
+
+ // Partial specializationss
+ template<class _Traits>
+ basic_ostream<char, _Traits>&
+ operator<<(basic_ostream<char, _Traits>& __out, const char* __s);
+
+ // Signed and unsigned
+ template<class _Traits>
+ basic_ostream<char, _Traits>&
+ operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
+ { return (__out << reinterpret_cast<const char*>(__s)); }
+
+ template<class _Traits>
+ basic_ostream<char, _Traits> &
+ operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
+ { return (__out << reinterpret_cast<const char*>(__s)); }
+
+ // 27.6.2.7 Standard basic_ostream manipulators
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ endl(basic_ostream<_CharT, _Traits>& __os)
+ { return flush(__os.put(__os.widen('\n'))); }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ ends(basic_ostream<_CharT, _Traits>& __os)
+ { return __os.put(_Traits::eos()); }
+
+ template<typename _CharT, typename _Traits>
+ basic_ostream<_CharT, _Traits>&
+ flush(basic_ostream<_CharT, _Traits>& __os)
+ { return __os.flush(); }
+
+} // namespace std
+
+#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
+# define export
+#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
+# include <bits/ostream.tcc>
+#endif
+#endif
+
+#endif /* _CPP_OSTREAM */
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_queue.h b/libstdc++-v3/bits/std_queue.h
new file mode 100644
index 0000000..198b2c0
--- /dev/null
+++ b/libstdc++-v3/bits/std_queue.h
@@ -0,0 +1,45 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_QUEUE
+#define _CPP_QUEUE 1
+
+#include <bits/stl_algobase.h>
+#include <bits/stl_alloc.h>
+#include <bits/stl_construct.h>
+#include <bits/stl_uninitialized.h>
+#include <bits/stl_vector.h>
+#include <ext/stl_bvector.h>
+#include <bits/stl_heap.h>
+#include <bits/stl_deque.h>
+#include <bits/stl_function.h>
+#include <bits/stl_queue.h>
+
+#endif /* _CPP_QUEUE */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_set.h b/libstdc++-v3/bits/std_set.h
new file mode 100644
index 0000000..7a5f5c5
--- /dev/null
+++ b/libstdc++-v3/bits/std_set.h
@@ -0,0 +1,40 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_SET
+#define _CPP_SET 1
+
+#ifndef _CPP_BITS_STL_TREE_H /* XXX is this guard needed? */
+#include <bits/stl_tree.h>
+#endif
+#include <bits/stl_set.h>
+#include <bits/stl_multiset.h>
+
+#endif /* _CPP_SET */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_sstream.h b/libstdc++-v3/bits/std_sstream.h
new file mode 100644
index 0000000..68a36c2
--- /dev/null
+++ b/libstdc++-v3/bits/std_sstream.h
@@ -0,0 +1,367 @@
+// String based streams -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.7 String-based streams
+//
+
+#ifndef _CPP_SSTREAM
+#define _CPP_SSTREAM 1
+
+#include <bits/std_istream.h>
+#include <bits/std_ostream.h>
+
+namespace std {
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ class basic_stringbuf : public basic_streambuf<_CharT, _Traits>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+ // Non-standard types:
+ typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
+ typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
+ typedef __string_type::size_type __size_type;
+
+ private:
+ // Data Members:
+ __string_type _M_string;
+
+ public:
+ // Constructors:
+ explicit
+ basic_stringbuf(ios_base::openmode __mode = ios_base::in | ios_base::out)
+ : __streambuf_type(), _M_string()
+ { _M_init_stringbuf(__mode); }
+
+ explicit
+ basic_stringbuf(const __string_type& __str,
+ ios_base::openmode __mode = ios_base::in | ios_base::out)
+ : __streambuf_type(), _M_string(__str)
+ { _M_init_stringbuf(__mode); }
+
+ // Get and set:
+ __string_type
+ str() const
+ {
+ if (_M_mode & ios_base::in && !(_M_mode & ios_base::out))
+ return _M_string;
+ else
+ {
+ // This is the deal: _M_string.size() is value that
+ // represents the size of the intial string that makes
+ // _M_string, and may not be the correct size of the
+ // current stringbuf internal buffer.
+ __size_type __len = _M_string.size();
+ if (_M_out_cur > _M_out_beg)
+ __len = max(__size_type(_M_out_end - _M_out_beg), __len);
+ return __string_type(_M_out_beg, _M_out_beg + __len);
+ }
+ }
+
+ void
+ str(const __string_type& __s)
+ {
+ _M_string = __s;
+ _M_init_stringbuf(_M_mode);
+ }
+
+ protected:
+ // Common initialization code for both ctors goes here.
+ void
+ _M_init_stringbuf(ios_base::openmode __mode)
+ {
+ // _M_buf_size is a convenient alias for "what the streambuf
+ // thinks the allocated size of the string really is." This is
+ // necessary as ostringstreams are implemented with the
+ // streambufs having control of the allocation and
+ // re-allocation of the internal string object, _M_string.
+ _M_buf_size = _M_string.size();
+ _M_mode = __mode;
+ if (_M_mode & ios_base::ate)
+ _M_really_sync(0, _M_buf_size);
+ else
+ _M_really_sync(0, 0);
+ }
+
+ // Overridden virtual functions:
+ virtual int_type
+ underflow()
+ {
+ if (_M_in_cur && _M_in_cur < _M_in_end)
+ return traits_type::to_int_type(*gptr());
+ else
+ return traits_type::eof();
+ }
+
+ virtual int_type
+ pbackfail(int_type __c = traits_type::eof());
+
+ virtual int_type
+ overflow(int_type __c = traits_type::eof());
+
+ virtual __streambuf_type*
+ setbuf(char_type* __s, streamsize __n)
+ {
+ if (__n)
+ {
+ _M_string = __string_type(__s, __n);
+ _M_really_sync(0, 0);
+ }
+ return this;
+ }
+
+ virtual pos_type
+ seekoff(off_type __off, ios_base::seekdir __way,
+ ios_base::openmode __mode = ios_base::in | ios_base::out);
+
+ virtual pos_type
+ seekpos(pos_type __sp,
+ ios_base::openmode __mode = ios_base::in | ios_base::out);
+
+ // Internal function for correctly updating the internal buffer
+ // for a particular _M_string, due to initialization or
+ // re-sizing of an existing _M_string.
+ // Assumes: contents of _M_string and internal buffer match exactly.
+ // __i == _M_in_cur - _M_in_beg
+ // __o == _M_out_cur - _M_out_beg
+ virtual int
+ _M_really_sync(__size_type __i, __size_type __o)
+ {
+ char_type* __base = const_cast<char_type*>(_M_string.data());
+ bool __testin = _M_mode & ios_base::in;
+ bool __testout = _M_mode & ios_base::out;
+ __size_type __len = _M_string.size();
+
+ _M_buf = __base;
+ if (__testin)
+ this->setg(__base, __base + __i, __base + __len);
+ if (__testout)
+ {
+ this->setp(__base, __base + __len);
+ _M_out_cur += __o;
+ }
+ return 0;
+ }
+ };
+
+ typedef basic_stringbuf<char> stringbuf;
+ typedef basic_stringbuf<wchar_t> wstringbuf;
+
+
+ // 27.7.2 Template class basic_istringstream
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ class basic_istringstream : public basic_istream<_CharT, _Traits>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+
+ // Non-standard types:
+ typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
+ typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
+ typedef basic_istream<_CharT, _Traits> __istream_type;
+
+ // Constructors:
+ explicit
+ basic_istringstream(ios_base::openmode __mode = ios_base::in)
+ : __istream_type(new __stringbuf_type(__mode | ios_base::in))
+ { }
+
+ explicit
+ basic_istringstream(const __string_type& __str,
+ ios_base::openmode __mode = ios_base::in)
+ : __istream_type(new __stringbuf_type(__str, __mode | ios_base::in))
+ { }
+
+ ~basic_istringstream()
+ {
+ delete _M_streambuf;
+ _M_streambuf = NULL;
+ }
+
+ // Members:
+ __stringbuf_type*
+ rdbuf() const
+ { return static_cast<__stringbuf_type*>(_M_streambuf); }
+
+ __string_type
+ str() const
+ { return this->rdbuf()->str(); }
+
+ void
+ str(const __string_type& __s)
+ { rdbuf()->str(__s); }
+
+ };
+
+ typedef basic_istringstream<char> istringstream;
+ typedef basic_istringstream<wchar_t> wistringstream;
+
+ // 27.7.3 Template class basic_ostringstream
+ template <typename _CharT, typename _Traits, typename _Alloc>
+ class basic_ostringstream : public basic_ostream<_CharT, _Traits>
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+ // Non-standard types:
+ typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
+ typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
+ typedef basic_ostream<_CharT, _Traits> __ostream_type;
+
+ // Constructors/destructor:
+ explicit
+ basic_ostringstream(ios_base::openmode __mode = ios_base::out)
+ : __ostream_type(new __stringbuf_type(__mode | ios_base::out))
+ { }
+
+ explicit
+ basic_ostringstream(const __string_type __str,
+ ios_base::openmode __mode = ios_base::out)
+ : __ostream_type(new __stringbuf_type(__str, __mode | ios_base::out))
+ { }
+
+ ~basic_ostringstream()
+ {
+ delete _M_streambuf;
+ _M_streambuf = NULL;
+ }
+
+ // Members:
+ __stringbuf_type*
+ rdbuf() const
+ { return static_cast<__stringbuf_type*>(_M_streambuf); }
+
+ __string_type
+ str() const
+ { return this->rdbuf()->str(); }
+
+ void
+ str(const __string_type& __s)
+ { rdbuf()->str(__s); }
+
+ };
+
+ typedef basic_ostringstream<char> ostringstream;
+ typedef basic_ostringstream<wchar_t> wostringstream;
+
+ // 27.7.4 Template class basic_stringstream
+ template <typename _CharT, typename _Traits, typename _Alloc>
+ class basic_stringstream : public basic_iostream<_CharT, _Traits>
+ {
+ public:
+ // Types
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+ // Non-standard types:
+ typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
+ typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
+ typedef basic_iostream<_CharT, _Traits> __iostream_type;
+
+ // Constructors/destructors
+ explicit
+ basic_stringstream(ios_base::openmode __mode =
+ ios_base::out | ios_base::in)
+ : __iostream_type(new __stringbuf_type(__mode))
+ { }
+
+ explicit
+ basic_stringstream(const __string_type& __str,
+ ios_base::openmode __mode =
+ ios_base::out | ios_base::in)
+ : __iostream_type(new __stringbuf_type(__str, __mode))
+ { }
+
+ ~basic_stringstream()
+ {
+ delete _M_streambuf;
+ _M_streambuf = NULL;
+ }
+
+ // Members:
+ __stringbuf_type*
+ rdbuf() const
+ { return static_cast<__stringbuf_type*>(_M_streambuf); }
+
+ __string_type
+ str() const
+ { return rdbuf()->str(); }
+
+ void
+ str(const __string_type& __s)
+ { rdbuf()->str(__s); }
+ };
+
+ typedef basic_stringstream<char> stringstream;
+ typedef basic_stringstream<wchar_t> wstringstream;
+
+} // namespace std
+
+
+
+#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
+# define export
+#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
+# include <bits/sstream.tcc>
+#endif
+#endif
+
+
+#endif /* _CPP_SSTREAM */
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_stack.h b/libstdc++-v3/bits/std_stack.h
new file mode 100644
index 0000000..53e7e21
--- /dev/null
+++ b/libstdc++-v3/bits/std_stack.h
@@ -0,0 +1,41 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_STACK
+#define _CPP_STACK 1
+
+#include <bits/stl_algobase.h>
+#include <bits/stl_alloc.h>
+#include <bits/stl_construct.h>
+#include <bits/stl_uninitialized.h>
+#include <bits/stl_deque.h>
+#include <bits/stl_stack.h>
+
+#endif /* _CPP_STACK */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_stdexcept.h b/libstdc++-v3/bits/std_stdexcept.h
new file mode 100644
index 0000000..691b9b5
--- /dev/null
+++ b/libstdc++-v3/bits/std_stdexcept.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_STDEXCEPT
+#define _CPP_STDEXCEPT 1
+
+#include <bits/std_exception.h>
+
+#if defined(__STL_USE_EXCEPTIONS) || \
+ !(defined(_MIPS_SIM) && defined(_ABIO32) && _MIPS_SIM == _ABIO32)
+
+#include <bits/stl_string_fwd.h>
+
+__STL_BEGIN_NAMESPACE
+
+class __Named_exception : public exception {
+public:
+ __Named_exception(const string& __str);
+ virtual const char* what() const __STL_NOTHROW { return _M_name; }
+
+private:
+ enum { _S_bufsize = 256 };
+ char _M_name[_S_bufsize];
+};
+
+class logic_error : public __Named_exception {
+public:
+ logic_error(const string& __s) : __Named_exception(__s) {}
+};
+
+class runtime_error : public __Named_exception {
+public:
+ runtime_error(const string& __s) : __Named_exception(__s) {}
+};
+
+class domain_error : public logic_error {
+public:
+ domain_error(const string& __arg) : logic_error(__arg) {}
+};
+
+class invalid_argument : public logic_error {
+public:
+ invalid_argument(const string& __arg) : logic_error(__arg) {}
+};
+
+class length_error : public logic_error {
+public:
+ length_error(const string& __arg) : logic_error(__arg) {}
+};
+
+class out_of_range : public logic_error {
+public:
+ out_of_range(const string& __arg) : logic_error(__arg) {}
+};
+
+class range_error : public runtime_error {
+public:
+ range_error(const string& __arg) : runtime_error(__arg) {}
+};
+
+class overflow_error : public runtime_error {
+public:
+ overflow_error(const string& __arg) : runtime_error(__arg) {}
+};
+
+class underflow_error : public runtime_error {
+public:
+ underflow_error(const string& __arg) : runtime_error(__arg) {}
+};
+
+__STL_END_NAMESPACE
+
+#endif /* Not o32, and no exceptions */
+
+#endif /* _CPP_STDEXCEPT */
+
+// Local Variables:
+// mode:C++
+// End:
+
diff --git a/libstdc++-v3/bits/std_streambuf.h b/libstdc++-v3/bits/std_streambuf.h
new file mode 100644
index 0000000..6aa9204
--- /dev/null
+++ b/libstdc++-v3/bits/std_streambuf.h
@@ -0,0 +1,460 @@
+// Stream buffer classes -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.5 Stream buffers
+//
+
+#ifndef _CPP_STREAMBUF
+#define _CPP_STREAMBUF 1
+
+#include <bits/c++config.h>
+#include <bits/std_iosfwd.h>
+#include <bits/std_cstdio.h> // For SEEK_SET, SEEK_CUR, SEEK_END
+#include <bits/localefwd.h>
+#include <bits/ios_base.h>
+
+namespace std {
+
+ template<typename _CharT, typename _Traits>
+ static streamsize
+ _S_copy_streambufs(basic_ios<_CharT, _Traits>& __ios,
+ basic_streambuf<_CharT, _Traits>* __sbin,
+ basic_streambuf<_CharT, _Traits>* __sbout);
+
+ // 27.5.2 Template class basic_streambuf<_CharT, _Traits>
+ template<typename _CharT, typename _Traits>
+ class basic_streambuf
+ {
+ public:
+ // Types:
+ typedef _CharT char_type;
+ typedef typename _Traits::int_type int_type;
+ typedef typename _Traits::pos_type pos_type;
+ typedef typename _Traits::off_type off_type;
+ typedef _Traits traits_type;
+
+ // Non-standard Types:
+ typedef ctype<_CharT> __ctype_type;
+ typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
+
+ friend class basic_ios<char_type, traits_type>;
+ friend class basic_istream<char_type, traits_type>;
+ friend class basic_ostream<char_type, traits_type>;
+ friend class istreambuf_iterator<char_type, traits_type>;
+ friend class ostreambuf_iterator<char_type, traits_type>;
+
+ friend streamsize
+ _S_copy_streambufs<>(basic_ios<_CharT, _Traits>& __ios,
+ basic_streambuf<_CharT, _Traits>* __sbin,
+ basic_streambuf<_CharT, _Traits>* __sbout);
+
+ protected:
+
+ // Pointer to the beginning of internally-allocated
+ // space. Filebuf manually allocates/deallocates this, whereas
+ // stringstreams attempt to use the built-in intelligence of the
+ // string class. If you are managing memory, set this. If not,
+ // leave it NULL.
+ char_type* _M_buf;
+
+ // Size of internal buffer, in bytes.
+ int_type _M_buf_size;
+
+ // True iff _M_in_* and _M_out_* buffers should always point to
+ // the same place. True for fstreams, false for sstreams.
+ bool _M_buf_unified;
+
+ // This is based on _IO_FILE, just reordered to be more
+ // consistent, and is intended to be the most minimal abstraction
+ // for an internal buffer.
+ // get == input == read
+ // put == output == write
+ char_type* _M_in_cur; // Current read area.
+ char_type* _M_in_beg; // Start of get area.
+ char_type* _M_in_end; // End of get area.
+ char_type* _M_out_cur; // Current put area.
+ char_type* _M_out_beg; // Start of put area.
+ char_type* _M_out_end; // End of put area.
+
+ // Place to stash in || out || in | out settings for current streambuf.
+ ios_base::openmode _M_mode;
+
+ // Current locale setting.
+ locale _M_locale_buf;
+
+ // True iff locale is initialized.
+ bool _M_locale_set;
+
+ // Cached use_facet<ctype>, which is based on the current locale info.
+ const __ctype_type* _M_fctype_buf;
+
+ // Correctly sets the _M_out_cur pointer, and bumps the
+ // appropriate _M_*_end pointers as well. Necessary for the
+ // un-tied stringbufs, in in|out mode.
+ // Invariant:
+ // __n + _M_out_[cur, end] <= _M_buf + _M_buf_size
+ // Assuming all _M_*_[beg, cur, end] pointers are operating on
+ // the same range:
+ // _M_buf <= _M_*_ <= _M_buf + _M_buf_size
+ void
+ _M_buf_bump(off_type __n) // argument needs to be +-
+ {
+ bool __testin = _M_mode & ios_base::in;
+ bool __testout = _M_mode & ios_base::out;
+ _M_out_cur += __n;
+ if (_M_buf_unified && __testin)
+ _M_in_cur = _M_out_cur;
+ if (_M_out_cur > _M_out_end)
+ {
+ _M_out_end = _M_out_cur;
+ if (__testin && __testout && _M_out_end > _M_in_end)
+ _M_in_end = _M_out_cur;
+ }
+ }
+
+ // These three functions are used to clarify internal buffer
+ // maintance. After an overflow, or after a seekoff call that
+ // started at beg or end, or possibly when the stream becomes
+ // unbuffered, and a myrid other obscure corner cases, the
+ // internal buffer does not truly reflect the contents of the
+ // external buffer. At this point, for whatever reason, it is in
+ // an indeterminate state.
+ void
+ _M_set_indeterminate(void)
+ {
+ if (_M_mode & ios_base::in)
+ this->setg(_M_buf, _M_buf, _M_buf);
+ if (_M_mode & ios_base::out)
+ this->setp(_M_buf, _M_buf);
+ }
+
+ void
+ _M_set_determinate(off_type __off)
+ {
+ bool __testin = _M_mode & ios_base::in;
+ bool __testout = _M_mode & ios_base::out;
+ if (__testin)
+ {
+ this->setg(_M_buf, _M_buf, _M_buf + __off);
+ if (!__testout)
+ _M_buf_size = static_cast<int_type>(__off);
+ }
+ if (__testout)
+ this->setp(_M_buf, _M_buf + __off);
+
+ }
+
+ bool
+ _M_is_indeterminate(void)
+ {
+ bool __retval = false;
+ if (_M_mode & ios_base::in)
+ __retval = _M_in_beg == _M_in_cur && _M_in_cur == _M_in_end;
+ if (_M_mode & ios_base::out)
+ __retval = _M_out_beg == _M_out_cur && _M_out_cur == _M_out_end;
+ return __retval;
+ }
+
+ public:
+ virtual
+ ~basic_streambuf()
+ {
+ _M_buf_unified = false;
+ _M_buf_size = 0;
+ _M_mode = ios_base::openmode(0);
+ _M_fctype_buf = NULL;
+ _M_locale_set = false;
+ }
+
+ // Locales:
+ locale
+ pubimbue(const locale &__loc)
+ {
+ locale __tmp(this->getloc());
+ this->imbue(__loc);
+ return __tmp;
+ }
+
+ locale
+ getloc() const
+ {
+ if (_M_locale_set)
+ return _M_locale_buf;
+ else
+ return locale();
+ }
+
+ // Buffer and positioning:
+ __streambuf_type*
+ pubsetbuf(char_type* __s, streamsize __n)
+ { return this->setbuf(__s, __n); }
+
+ pos_type
+ pubseekoff(off_type __off, ios_base::seekdir __way,
+ ios_base::openmode __mode = ios_base::in | ios_base::out)
+ { return this->seekoff(__off, __way, __mode); }
+
+ pos_type
+ pubseekpos(pos_type __sp,
+ ios_base::openmode __mode = ios_base::in | ios_base::out)
+ { return this->seekpos(__sp, __mode); }
+
+ int
+ pubsync() { return this->sync(); }
+
+ // Get and put areas:
+ // Get area:
+ streamsize
+ in_avail()
+ {
+ streamsize __retval;
+ if (_M_in_cur && _M_in_cur < _M_in_end)
+ __retval = this->egptr() - this->gptr();
+ else
+ __retval = this->showmanyc();
+ return __retval;
+ }
+
+ int_type
+ snextc()
+ {
+ int_type __eof = traits_type::eof();
+ return (this->sbumpc() == __eof ? __eof : this->sgetc());
+ }
+
+ int_type
+ sbumpc();
+
+ int_type
+ sgetc()
+ {
+ int_type __retval;
+ if (_M_in_cur && _M_in_cur < _M_in_end)
+ __retval = traits_type::to_int_type(*gptr());
+ else
+ __retval = this->underflow();
+ return __retval;
+ }
+
+ streamsize
+ sgetn(char_type* __s, streamsize __n)
+ { return this->xsgetn(__s, __n); }
+
+ // Putback:
+ int_type
+ sputbackc(char_type __c);
+
+ int_type
+ sungetc();
+
+ // Put area:
+ int_type
+ sputc(char_type __c);
+
+ streamsize
+ sputn(const char_type* __s, streamsize __n)
+ { return this->xsputn(__s, __n); }
+
+ protected:
+ basic_streambuf()
+ : _M_buf(NULL), _M_buf_size(0), _M_buf_unified(false),
+ _M_in_cur(0), _M_in_beg(0), _M_in_end(0), _M_out_cur(0), _M_out_beg(0),
+ _M_out_end(0), _M_mode(ios_base::openmode(0)),
+ _M_locale_buf(locale()), _M_locale_set(false)
+ { _M_fctype_buf = &use_facet<__ctype_type>(this->getloc()); }
+
+ // Get area:
+ char_type*
+ eback() const { return _M_in_beg; }
+
+ char_type*
+ gptr() const { return _M_in_cur; }
+
+ char_type*
+ egptr() const { return _M_in_end; }
+
+ void
+ gbump(int __n) { _M_in_cur += __n; }
+
+ void
+ setg(char_type* __gbeg, char_type* __gnext, char_type* __gend)
+ {
+ _M_in_beg = __gbeg;
+ _M_in_cur = __gnext;
+ _M_in_end = __gend;
+ if (!(_M_mode & ios_base::in) && __gbeg && __gnext && __gend)
+ _M_mode = _M_mode | ios_base::in;
+ }
+
+ // Put area:
+ char_type*
+ pbase() const { return _M_out_beg; }
+
+ char_type*
+ pptr() const { return _M_out_cur; }
+
+ char_type*
+ epptr() const { return _M_out_end; }
+
+ void
+ pbump(int __n) { _M_out_cur += __n; }
+
+ void
+ setp(char_type* __pbeg, char_type* __pend)
+ {
+ _M_out_beg = _M_out_cur = __pbeg;
+ _M_out_end = __pend;
+ if (!(_M_mode & ios_base::out) && __pbeg && __pend)
+ _M_mode = _M_mode | ios_base::out;
+ // The output sequence is highly tied to _M_buf and
+ // _M_buf_size in addition to the actual pointers into the
+ // buffer. Because of this, (re)set _M_buf_size here, as
+ // sputc/xsputn need _M_buf_size to be accurate. (The
+ // corresponding input functions rely instead on _M_in_end.)
+ _M_buf_size = max(_M_buf_size, static_cast<int_type>(__pend - __pbeg));
+ }
+
+ // Virtual functions:
+ // Locales:
+ virtual void
+ imbue(const locale& __loc)
+ {
+ _M_locale_set = true;
+ if (_M_locale_buf != __loc)
+ {
+ _M_locale_buf = __loc;
+ _M_fctype_buf = &use_facet<__ctype_type>(_M_locale_buf);
+ }
+ }
+
+ // Buffer management and positioning:
+ virtual basic_streambuf<char_type,_Traits>*
+ setbuf(char_type*, streamsize)
+ { return this; }
+
+ virtual pos_type
+ seekoff(off_type, ios_base::seekdir,
+ ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
+ { return pos_type(off_type(-1)); }
+
+ virtual pos_type
+ seekpos(pos_type,
+ ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
+ { return pos_type(off_type(-1)); }
+
+ virtual int
+ sync() { return 0; }
+
+ // Get area:
+ virtual streamsize
+ showmanyc() { return 0; }
+
+ virtual streamsize
+ xsgetn(char_type* __s, streamsize __n);
+
+ virtual int_type
+ underflow()
+ { return traits_type::eof(); }
+
+ virtual int_type
+ uflow()
+ {
+ int_type __retval = traits_type::eof();
+ bool __testeof = this->underflow() == __retval;
+ bool __testpending = _M_in_cur && _M_in_cur < _M_in_end;
+
+ if (!__testeof && __testpending)
+ {
+ __retval = traits_type::to_int_type(*_M_in_cur);
+ ++_M_in_cur;
+ if (_M_buf_unified && _M_mode & ios_base::out)
+ ++_M_out_cur;
+ }
+ return __retval;
+ }
+
+ // Putback:
+ virtual int_type
+ pbackfail(int_type /* __c */ = traits_type::eof())
+ { return traits_type::eof(); }
+
+ // Put area:
+ virtual streamsize
+ xsputn(const char_type* __s, streamsize __n);
+
+ virtual int_type
+ overflow(int_type /* __c */ = traits_type::eof())
+ { return traits_type::eof(); }
+
+#ifdef _GLIBCPP_DEPRICATED
+ public:
+ void
+ stossc()
+ {
+ if (_M_in_cur < _M_in_end)
+ ++_M_in_cur;
+ else
+ this->uflow();
+ }
+#endif
+
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ private:
+ basic_streambuf(const __streambuf_type&);
+
+ __streambuf_type&
+ operator=(const __streambuf_type&);
+#endif
+ };
+
+ typedef basic_streambuf<char> streambuf;
+ typedef basic_streambuf<wchar_t> wstreambuf;
+
+} // namespace std
+
+#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
+# define export
+#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
+#include <bits/streambuf.tcc>
+#endif
+#endif
+
+#endif /* _CPP_STREAMBUF */
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_string.h b/libstdc++-v3/bits/std_string.h
new file mode 100644
index 0000000..6008eca
--- /dev/null
+++ b/libstdc++-v3/bits/std_string.h
@@ -0,0 +1,63 @@
+// Components for manipulating sequences of characters -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 21 Strings library
+//
+
+#ifndef _CPP_STRING
+#define _CPP_STRING 1
+
+#include <bits/c++config.h>
+#include <bits/stl_string_fwd.h>
+#include <bits/std_iterator.h>
+#include <bits/char_traits.h>
+#include <bits/type_traits.h>
+#include <bits/std_iosfwd.h> // for operators >>, <<, and getline decls
+#include <bits/basic_string.h>
+
+#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
+# include <bits/std_algorithm.h> // for find_if
+# include <bits/string.tcc>
+#endif
+
+#endif /* _CPP_STRING */
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/std_strstream.h b/libstdc++-v3/bits/std_strstream.h
new file mode 100644
index 0000000..2f784b3
--- /dev/null
+++ b/libstdc++-v3/bits/std_strstream.h
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 1998
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+// WARNING: The classes defined in this header are DEPRECATED. This
+// header is defined in section D.7.1 of the C++ standard, and it
+// MAY BE REMOVED in a future standard revision. You should use the
+// header <sstream> instead.
+
+#ifndef __SGI_STL_STRSTREAM
+#define __SGI_STL_STRSTREAM
+
+#if defined(__sgi) && !defined(__GNUC__) && !defined(_STANDARD_C_PLUS_PLUS)
+#error This header file requires the -LANG:std option
+#endif
+
+#include <bits/std_iosfwd.h>
+#include <bits/std_ios.h>
+#include <bits/std_istream.h>
+#include <bits/std_ostream.h>
+#include <bits/std_string.h>
+
+__STL_BEGIN_NAMESPACE
+
+//----------------------------------------------------------------------
+// Class strstreambuf, a streambuf class that manages an array of char.
+// Note that this class is not a template.
+
+class strstreambuf : public basic_streambuf<char, char_traits<char> >
+{
+public: // Types.
+ typedef char_traits<char> _Traits;
+ typedef basic_streambuf<char, _Traits> _Base;
+
+public: // Constructor, destructor
+ explicit strstreambuf(streamsize __initial_capacity = 0);
+ strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
+
+ strstreambuf(char* __get, streamsize __n, char* __put = 0);
+ strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
+ strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
+
+ strstreambuf(const char* __get, streamsize __n);
+ strstreambuf(const signed char* __get, streamsize __n);
+ strstreambuf(const unsigned char* __get, streamsize __n);
+
+ virtual ~strstreambuf();
+
+public: // strstreambuf operations.
+ void freeze(bool = true);
+ char* str();
+ int pcount() const;
+
+protected: // Overridden virtual member functions.
+ virtual int_type overflow(int_type __c = _Traits::eof());
+ virtual int_type pbackfail(int_type __c = _Traits::eof());
+ virtual int_type underflow();
+ virtual _Base* setbuf(char* __buf, streamsize __n);
+ virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
+ ios_base::openmode __mode
+ = ios_base::in | ios_base::out);
+ virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
+ = ios_base::in | ios_base::out);
+
+private: // Helper functions.
+ // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
+ char* _M_alloc(size_t);
+ void _M_free(char*);
+
+ // Helper function used in constructors.
+ void _M_setup(char* __get, char* __put, streamsize __n);
+
+private: // Data members.
+ void* (*_M_alloc_fun)(size_t);
+ void (*_M_free_fun)(void*);
+
+ bool _M_dynamic : 1;
+ bool _M_frozen : 1;
+ bool _M_constant : 1;
+};
+
+//----------------------------------------------------------------------
+// Class istrstream, an istream that manages a strstreambuf.
+
+class istrstream : public basic_istream<char>
+{
+public:
+ explicit istrstream(char*);
+ explicit istrstream(const char*);
+ istrstream(char* , streamsize);
+ istrstream(const char*, streamsize);
+ virtual ~istrstream();
+
+ strstreambuf* rdbuf() const;
+ char* str();
+
+private:
+ strstreambuf _M_buf;
+};
+
+//----------------------------------------------------------------------
+// Class ostrstream
+
+class ostrstream : public basic_ostream<char>
+{
+public:
+ ostrstream();
+ ostrstream(char*, int, ios_base::openmode = ios_base::out);
+ virtual ~ostrstream();
+
+ strstreambuf* rdbuf() const;
+ void freeze(bool = true);
+ char* str();
+ int pcount() const;
+
+private:
+ strstreambuf _M_buf;
+};
+
+//----------------------------------------------------------------------
+// Class strstream
+
+class strstream : public basic_iostream<char>
+{
+public:
+ typedef char char_type;
+ typedef char_traits<char>::int_type int_type;
+ typedef char_traits<char>::pos_type pos_type;
+ typedef char_traits<char>::off_type off_type;
+
+ strstream();
+ strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
+ virtual ~strstream();
+
+ strstreambuf* rdbuf() const;
+ void freeze(bool = true);
+ int pcount() const;
+ char* str();
+
+private:
+ strstreambuf _M_buf;
+};
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_STRSTREAM */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_typeinfo.h b/libstdc++-v3/bits/std_typeinfo.h
new file mode 100644
index 0000000..1bce795
--- /dev/null
+++ b/libstdc++-v3/bits/std_typeinfo.h
@@ -0,0 +1,80 @@
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+
+#ifndef _CPP_TYPEINFO
+#define _CPP_TYPEINFO 1
+
+#include <bits/c++config.h>
+#include <bits/std_exception.h>
+
+#ifdef __GNUG__
+# include_next <typeinfo>
+#else
+
+__STL_BEGIN_NAMESPACE
+
+ class type_info {
+ public:
+ virtual ~type_info();
+ bool operator==(const type_info& rhs) const;
+ bool operator!=(const type_info& rhs) const;
+ bool before(const type_info& rhs) const;
+ const char* name() const;
+ private:
+ type_info(const type_info& rhs);
+ type_info& operator=(const type_info& rhs);
+ };
+
+ class bad_cast : public exception {
+ public:
+ bad_cast() throw();
+ bad_cast(const bad_cast&) throw();
+ bad_cast& operator=(const bad_cast&) throw();
+ virtual ~bad_cast() throw();
+ virtual const char* what() const throw();
+ };
+
+ class bad_typeid : public exception {
+ public:
+ bad_typeid() throw();
+ bad_typeid(const bad_typeid&) throw();
+ bad_typeid& operator=(const bad_typeid&) throw();
+ virtual ~bad_typeid() throw();
+ virtual const char* what() const throw();
+ };
+
+__STL_END_NAMESPACE
+
+#endif
+
+#endif /* _CPP_TYPEINFO */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_utility.h b/libstdc++-v3/bits/std_utility.h
new file mode 100644
index 0000000..e10dae3
--- /dev/null
+++ b/libstdc++-v3/bits/std_utility.h
@@ -0,0 +1,38 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_UTILITY
+#define _CPP_UTILITY 1
+
+#include <bits/stl_config.h>
+#include <bits/stl_relops.h>
+#include <bits/stl_pair.h>
+
+#endif /* _CPP_UTILITY */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/std_valarray.h b/libstdc++-v3/bits/std_valarray.h
new file mode 100644
index 0000000..3a5f0c7
--- /dev/null
+++ b/libstdc++-v3/bits/std_valarray.h
@@ -0,0 +1,748 @@
+// The template and inlines for the -*- C++ -*- valarray class.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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 Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
+
+#ifndef _CPP_VALARRAY
+#define _CPP_VALARRAY 1
+
+#include <bits/c++config.h>
+#include <bits/std_cstddef.h>
+#include <bits/std_cmath.h>
+#include <bits/std_cstdlib.h>
+#include <bits/std_numeric.h>
+#include <bits/std_functional.h>
+#include <bits/std_algorithm.h>
+
+namespace std {
+
+ template<class _Clos, typename _Tp> class _Expr;
+
+ template<typename _Tp1, typename _Tp2> class _ValArray;
+
+ template<template<class> class _Oper,
+ template<class, class> class _Meta, class _Dom> struct _UnClos;
+
+ template<template<class> class _Oper,
+ template<class, class> class _Meta1,
+ template<class, class> class _Meta2,
+ class _Dom1, class _Dom2> class _BinClos;
+
+ template<template<class, class> class _Meta, class _Dom> class _SClos;
+
+ template<template<class, class> class _Meta, class _Dom> class _GClos;
+
+ template<template<class, class> class _Meta, class _Dom> class _IClos;
+
+ template<template<class, class> class _Meta, class _Dom> class _ValFunClos;
+
+ template<template<class, class> class _Meta, class _Dom> class _RefFunClos;
+
+ template<class _Tp> struct _Unary_plus;
+ template<class _Tp> struct _Bitwise_and;
+ template<class _Tp> struct _Bitwise_or;
+ template<class _Tp> struct _Bitwise_xor;
+ template<class _Tp> struct _Bitwise_not;
+ template<class _Tp> struct _Shift_left;
+ template<class _Tp> struct _Shift_right;
+
+ template<class _Tp> class valarray; // An array of type _Tp
+ class slice; // BLAS-like slice out of an array
+ template<class _Tp> class slice_array;
+ class gslice; // generalized slice out of an array
+ template<class _Tp> class gslice_array;
+ template<class _Tp> class mask_array; // masked array
+ template<class _Tp> class indirect_array; // indirected array
+
+}
+
+#include <bits/valarray_array.h>
+#include <bits/valarray_meta.h>
+
+namespace std {
+
+ template<class _Tp> class valarray
+ {
+ public:
+ typedef _Tp value_type;
+
+ // _lib.valarray.cons_ construct/destroy:
+ valarray();
+ explicit valarray(size_t);
+ valarray(const _Tp&, size_t);
+ valarray(const _Tp* __restrict__, size_t);
+ valarray(const valarray&);
+ valarray(const slice_array<_Tp>&);
+ valarray(const gslice_array<_Tp>&);
+ valarray(const mask_array<_Tp>&);
+ valarray(const indirect_array<_Tp>&);
+ template<class _Dom>
+ valarray(const _Expr<_Dom,_Tp>& __e);
+ ~valarray();
+
+ // _lib.valarray.assign_ assignment:
+ valarray<_Tp>& operator=(const valarray<_Tp>&);
+ valarray<_Tp>& operator=(const _Tp&);
+ valarray<_Tp>& operator=(const slice_array<_Tp>&);
+ valarray<_Tp>& operator=(const gslice_array<_Tp>&);
+ valarray<_Tp>& operator=(const mask_array<_Tp>&);
+ valarray<_Tp>& operator=(const indirect_array<_Tp>&);
+
+ template<class _Dom> valarray<_Tp>&
+ operator= (const _Expr<_Dom,_Tp>&);
+
+ // _lib.valarray.access_ element access:
+ _Tp operator[](size_t) const;
+ _Tp& operator[](size_t);
+ // _lib.valarray.sub_ subset operations:
+ _Expr<_SClos<_ValArray,_Tp>, _Tp> operator[](slice) const;
+ slice_array<_Tp> operator[](slice);
+ _Expr<_GClos<_ValArray,_Tp>, _Tp> operator[](const gslice&) const;
+ gslice_array<_Tp> operator[](const gslice&);
+ valarray<_Tp> operator[](const valarray<bool>&) const;
+ mask_array<_Tp> operator[](const valarray<bool>&);
+ _Expr<_IClos<_ValArray, _Tp>, _Tp>
+ operator[](const valarray<size_t>&) const;
+ indirect_array<_Tp> operator[](const valarray<size_t>&);
+
+ // _lib.valarray.unary_ unary operators:
+ _Expr<_UnClos<_Unary_plus,_ValArray,_Tp>,_Tp> operator+ () const;
+ _Expr<_UnClos<negate,_ValArray,_Tp>,_Tp> operator- () const;
+ _Expr<_UnClos<_Bitwise_not,_ValArray,_Tp>,_Tp> operator~ () const;
+ _Expr<_UnClos<logical_not,_ValArray,_Tp>,bool> operator! () const;
+
+ // _lib.valarray.cassign_ computed assignment:
+ valarray<_Tp>& operator*= (const _Tp&);
+ valarray<_Tp>& operator/= (const _Tp&);
+ valarray<_Tp>& operator%= (const _Tp&);
+ valarray<_Tp>& operator+= (const _Tp&);
+ valarray<_Tp>& operator-= (const _Tp&);
+ valarray<_Tp>& operator^= (const _Tp&);
+ valarray<_Tp>& operator&= (const _Tp&);
+ valarray<_Tp>& operator|= (const _Tp&);
+ valarray<_Tp>& operator<<=(const _Tp&);
+ valarray<_Tp>& operator>>=(const _Tp&);
+ valarray<_Tp>& operator*= (const valarray<_Tp>&);
+ valarray<_Tp>& operator/= (const valarray<_Tp>&);
+ valarray<_Tp>& operator%= (const valarray<_Tp>&);
+ valarray<_Tp>& operator+= (const valarray<_Tp>&);
+ valarray<_Tp>& operator-= (const valarray<_Tp>&);
+ valarray<_Tp>& operator^= (const valarray<_Tp>&);
+ valarray<_Tp>& operator|= (const valarray<_Tp>&);
+ valarray<_Tp>& operator&= (const valarray<_Tp>&);
+ valarray<_Tp>& operator<<=(const valarray<_Tp>&);
+ valarray<_Tp>& operator>>=(const valarray<_Tp>&);
+
+ template<class _Dom>
+ valarray<_Tp>& operator*= (const _Expr<_Dom,_Tp>&);
+ template<class _Dom>
+ valarray<_Tp>& operator/= (const _Expr<_Dom,_Tp>&);
+ template<class _Dom>
+ valarray<_Tp>& operator%= (const _Expr<_Dom,_Tp>&);
+ template<class _Dom>
+ valarray<_Tp>& operator+= (const _Expr<_Dom,_Tp>&);
+ template<class _Dom>
+ valarray<_Tp>& operator-= (const _Expr<_Dom,_Tp>&);
+ template<class _Dom>
+ valarray<_Tp>& operator^= (const _Expr<_Dom,_Tp>&);
+ template<class _Dom>
+ valarray<_Tp>& operator|= (const _Expr<_Dom,_Tp>&);
+ template<class _Dom>
+ valarray<_Tp>& operator&= (const _Expr<_Dom,_Tp>&);
+ template<class _Dom>
+ valarray<_Tp>& operator<<=(const _Expr<_Dom,_Tp>&);
+ template<class _Dom>
+ valarray<_Tp>& operator>>=(const _Expr<_Dom,_Tp>&);
+
+
+ // _lib.valarray.members_ member functions:
+ size_t size() const;
+ _Tp sum() const;
+ _Tp min() const;
+ _Tp max() const;
+
+// // FIXME: Extension
+// _Tp product () const;
+
+ valarray<_Tp> shift (int) const;
+ valarray<_Tp> cshift(int) const;
+ _Expr<_ValFunClos<_ValArray,_Tp>,_Tp> apply(_Tp func(_Tp)) const;
+ _Expr<_RefFunClos<_ValArray,_Tp>,_Tp> apply(_Tp func(const _Tp&)) const;
+ void resize(size_t __size, _Tp __c = _Tp());
+
+ private:
+ size_t _M_size;
+ _Tp* __restrict__ _M_data;
+
+ friend class _Array<_Tp>;
+ };
+
+
+ template<typename _Tp> struct _Unary_plus : unary_function<_Tp,_Tp> {
+ _Tp operator() (const _Tp& __t) const { return __t; }
+ };
+
+ template<typename _Tp> struct _Bitwise_and : binary_function<_Tp,_Tp,_Tp> {
+ _Tp operator() (_Tp __x, _Tp __y) const { return __x & __y; }
+ };
+
+ template<typename _Tp> struct _Bitwise_or : binary_function<_Tp,_Tp,_Tp> {
+ _Tp operator() (_Tp __x, _Tp __y) const { return __x | __y; }
+ };
+
+ template<typename _Tp> struct _Bitwise_xor : binary_function<_Tp,_Tp,_Tp> {
+ _Tp operator() (_Tp __x, _Tp __y) const { return __x ^ __y; }
+ };
+
+ template<typename _Tp> struct _Bitwise_not : unary_function<_Tp,_Tp> {
+ _Tp operator() (_Tp __t) const { return ~__t; }
+ };
+
+ template<typename _Tp> struct _Shift_left : unary_function<_Tp,_Tp> {
+ _Tp operator() (_Tp __x, _Tp __y) const { return __x << __y; }
+ };
+
+ template<typename _Tp> struct _Shift_right : unary_function<_Tp,_Tp> {
+ _Tp operator() (_Tp __x, _Tp __y) const { return __x >> __y; }
+ };
+
+
+ template<typename _Tp>
+ inline _Tp
+ valarray<_Tp>::operator[] (size_t __i) const
+ { return _M_data[__i]; }
+
+ template<typename _Tp>
+ _Tp&
+ valarray<_Tp>::operator[] (size_t __i)
+ { return _M_data[__i]; }
+
+} // std::
+
+#include <bits/slice.h>
+#include <bits/slice_array.h>
+#include <bits/gslice.h>
+#include <bits/gslice_array.h>
+#include <bits/mask_array.h>
+#include <bits/indirect_array.h>
+
+namespace std {
+
+ template<typename _Tp>
+ inline valarray<_Tp>::valarray () : _M_size (0), _M_data (0) {}
+
+ template<typename _Tp>
+ inline valarray<_Tp>::valarray (size_t __n)
+ : _M_size(__n),
+ _M_data(static_cast<_Tp*__restrict__>
+ (__valarray_get_memory(__n * sizeof (_Tp))))
+ { __valarray_default_construct(_M_data, _M_data + __n); }
+
+ template<typename _Tp>
+ inline valarray<_Tp>::valarray (const _Tp& __t, size_t __n)
+ : _M_size(__n),
+ _M_data(static_cast<_Tp*__restrict__>
+ (__valarray_get_memory(__n * sizeof (_Tp))))
+ { __valarray_fill_construct (_M_data, _M_data + __n, __t); }
+
+ template<typename _Tp>
+ inline valarray<_Tp>::valarray (const _Tp* __restrict__ __p, size_t __n)
+ : _M_size(__n),
+ _M_data(static_cast<_Tp*__restrict__>
+ (__valarray_get_memory(__n * sizeof (_Tp))))
+ { __valarray_copy_construct (__p, __p + __n, _M_data); }
+
+ template<typename _Tp>
+ inline valarray<_Tp>::valarray (const valarray<_Tp>& __v)
+ : _M_size(__v._M_size),
+ _M_data(static_cast<_Tp*__restrict__>
+ (__valarray_get_memory(__v._M_size * sizeof (_Tp))))
+ { __valarray_copy_construct (__v._M_data, __v._M_data + _M_size, _M_data); }
+
+ template<typename _Tp>
+ inline valarray<_Tp>::valarray (const slice_array<_Tp>& __sa)
+ : _M_size(__sa._M_sz),
+ _M_data(static_cast<_Tp*__restrict__>
+ (__valarray_get_memory(__sa._M_sz * sizeof (_Tp))))
+ {
+ __valarray_copy_construct
+ (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data));
+ }
+
+ template<typename _Tp>
+ inline valarray<_Tp>::valarray (const gslice_array<_Tp>& __ga)
+ : _M_size(__ga._M_index.size()),
+ _M_data(static_cast<_Tp*__restrict__>
+ (__valarray_get_memory(_M_size * sizeof (_Tp))))
+ {
+ __valarray_copy_construct
+ (__ga._M_array, _Array<size_t>(__ga._M_index),
+ _Array<_Tp>(_M_data), _M_size);
+ }
+
+ template<typename _Tp>
+ inline valarray<_Tp>::valarray (const mask_array<_Tp>& __ma)
+ : _M_size(__ma._M_sz),
+ _M_data(static_cast<_Tp*__restrict__>
+ (__valarray_get_memory(__ma._M_sz * sizeof (_Tp))))
+ {
+ __valarray_copy_construct
+ (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size);
+ }
+
+ template<typename _Tp>
+ inline valarray<_Tp>::valarray (const indirect_array<_Tp>& __ia)
+ : _M_size(__ia._M_sz),
+ _M_data(static_cast<_Tp*__restrict__>
+ (__valarray_get_memory(__ia._M_sz * sizeof (_Tp))))
+ {
+ __valarray_copy_construct
+ (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);
+ }
+
+ template<typename _Tp> template<class _Dom>
+ inline valarray<_Tp>::valarray (const _Expr<_Dom, _Tp>& __e)
+ : _M_size(__e.size ()),
+ _M_data(static_cast<_Tp*__restrict__>
+ (__valarray_copy_construct(_M_size * sizeof (_Tp))))
+ { __valarray_copy_construct (__e, _M_size, _Array<_Tp>(_M_data)); }
+
+ template<typename _Tp>
+ inline valarray<_Tp>::~valarray ()
+ {
+ __valarray_destroy_elements(_M_data, _M_data + _M_size);
+ __valarray_release_memory(_M_data);
+ }
+
+ template<typename _Tp>
+ inline valarray<_Tp>&
+ valarray<_Tp>::operator= (const valarray<_Tp>& __v)
+ {
+ __valarray_copy(__v._M_data, _M_size, _M_data);
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline valarray<_Tp>&
+ valarray<_Tp>::operator= (const _Tp& __t)
+ {
+ __valarray_fill (_M_data, _M_size, __t);
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline valarray<_Tp>&
+ valarray<_Tp>::operator= (const slice_array<_Tp>& __sa)
+ {
+ __valarray_copy (__sa._M_array, __sa._M_sz,
+ __sa._M_stride, _Array<_Tp>(_M_data));
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline valarray<_Tp>&
+ valarray<_Tp>::operator= (const gslice_array<_Tp>& __ga)
+ {
+ __valarray_copy (__ga._M_array, _Array<size_t>(__ga._M_index),
+ _Array<_Tp>(_M_data), _M_size);
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline valarray<_Tp>&
+ valarray<_Tp>::operator= (const mask_array<_Tp>& __ma)
+ {
+ __valarray_copy (__ma._M_array, __ma._M_mask,
+ _Array<_Tp>(_M_data), _M_size);
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline valarray<_Tp>&
+ valarray<_Tp>::operator= (const indirect_array<_Tp>& __ia)
+ {
+ __valarray_copy (__ia._M_array, __ia._M_index,
+ _Array<_Tp>(_M_data), _M_size);
+ return *this;
+ }
+
+ template<typename _Tp> template<class _Dom>
+ inline valarray<_Tp>&
+ valarray<_Tp>::operator= (const _Expr<_Dom, _Tp>& __e)
+ {
+ __valarray_copy (__e, _M_size, _Array<_Tp>(_M_data));
+ return *this;
+ }
+
+ template<typename _Tp>
+ inline _Expr<_SClos<_ValArray,_Tp>, _Tp>
+ valarray<_Tp>::operator[] (slice __s) const
+ {
+ typedef _SClos<_ValArray,_Tp> _Closure;
+ return _Expr<_Closure, _Tp> (_Closure (_Array<_Tp>(_M_data), __s));
+ }
+
+ template<typename _Tp>
+ inline slice_array<_Tp>
+ valarray<_Tp>::operator[] (slice __s)
+ {
+ return slice_array<_Tp> (_Array<_Tp>(_M_data), __s);
+ }
+
+ template<typename _Tp>
+ inline _Expr<_GClos<_ValArray,_Tp>, _Tp>
+ valarray<_Tp>::operator[] (const gslice& __gs) const
+ {
+ typedef _GClos<_ValArray,_Tp> _Closure;
+ return _Expr<_Closure, _Tp>
+ (_Closure (_Array<_Tp>(_M_data), __gs._M_index->_M_index));
+ }
+
+ template<typename _Tp>
+ inline gslice_array<_Tp>
+ valarray<_Tp>::operator[] (const gslice& __gs)
+ {
+ return gslice_array<_Tp>
+ (_Array<_Tp>(_M_data), __gs._M_index->_M_index);
+ }
+
+ template<typename _Tp>
+ inline valarray<_Tp>
+ valarray<_Tp>::operator[] (const valarray<bool>& __m) const
+ {
+ size_t __s (0);
+ size_t __e (__m.size ());
+ for (size_t __i=0; __i<__e; ++__i)
+ if (__m[__i]) ++__s;
+ return valarray<_Tp> (mask_array<_Tp> (_Array<_Tp>(_M_data), __s,
+ _Array<bool> (__m)));
+ }
+
+ template<typename _Tp>
+ inline mask_array<_Tp>
+ valarray<_Tp>::operator[] (const valarray<bool>& __m)
+ {
+ size_t __s (0);
+ size_t __e (__m.size ());
+ for (size_t __i=0; __i<__e; ++__i)
+ if (__m[__i]) ++__s;
+ return mask_array<_Tp> (_Array<_Tp>(_M_data), __s, _Array<bool> (__m));
+ }
+
+ template<typename _Tp>
+ inline _Expr<_IClos<_ValArray,_Tp>, _Tp>
+ valarray<_Tp>::operator[] (const valarray<size_t>& __i) const
+ {
+ typedef _IClos<_ValArray,_Tp> _Closure;
+ return _Expr<_Closure, _Tp> (_Closure (*this, __i));
+ }
+
+ template<typename _Tp>
+ inline indirect_array<_Tp>
+ valarray<_Tp>::operator[] (const valarray<size_t>& __i)
+ {
+ return indirect_array<_Tp> (_Array<_Tp>(_M_data), __i.size(),
+ _Array<size_t> (__i));
+ }
+
+ template<class _Tp>
+ inline size_t valarray<_Tp>::size () const { return _M_size; }
+
+ template<class _Tp>
+ inline _Tp
+ valarray<_Tp>::sum () const
+ {
+ return __valarray_sum(_M_data, _M_data + _M_size);
+ }
+
+// template<typename _Tp>
+// inline _Tp
+// valarray<_Tp>::product () const
+// {
+// return __valarray_product(_M_data, _M_data + _M_size);
+// }
+
+ template <class _Tp>
+ inline valarray<_Tp>
+ valarray<_Tp>::shift (int __n) const
+ {
+ _Tp* const __a = static_cast<_Tp*>
+ (__builtin_alloca (sizeof(_Tp) * _M_size));
+ if (! __n) // __n == 0: no shift
+ __valarray_copy_construct(_M_data, _M_data + _M_size, __a);
+ else if (__n > 0) { // __n > 0: shift left
+ if (__n > _M_size)
+ __valarray_default_construct(__a, __a + __n);
+ else {
+ __valarray_copy_construct(_M_data+__n, _M_data + _M_size, __a);
+ __valarray_default_construct(__a+_M_size-__n, __a + _M_size);
+ }
+ }
+ else { // __n < 0: shift right
+ __valarray_copy_construct (_M_data, _M_data+_M_size+__n, __a-__n);
+ __valarray_default_construct(__a, __a - __n);
+ }
+ return valarray<_Tp> (__a, _M_size);
+ }
+
+ template <class _Tp>
+ inline valarray<_Tp>
+ valarray<_Tp>::cshift (int __n) const
+ {
+ _Tp* const __a = static_cast<_Tp*>
+ (__builtin_alloca (sizeof(_Tp) * _M_size));
+ if (! __n) // __n == 0: no cshift
+ __valarray_copy_construct(_M_data, _M_data + _M_size, __a);
+ else if (__n > 0) { // __n > 0: cshift left
+ __valarray_copy_construct(_M_data, _M_data+__n, __a+_M_size-__n);
+ __valarray_copy_construct(_M_data+__n, _M_data + _M_size, __a);
+ }
+ else { // __n < 0: cshift right
+ __valarray_copy_construct
+ (_M_data + _M_size+__n, _M_data + _M_size, __a);
+ __valarray_copy_construct
+ (_M_data, _M_data + _M_size+__n, __a - __n);
+ }
+ return valarray<_Tp> (__a, _M_size);
+ }
+
+ template <class _Tp>
+ inline void
+ valarray<_Tp>::resize (size_t __n, _Tp __c)
+ {
+ if (_M_size != __n) {
+ __valarray_destroy_elements(_M_data, _M_data + _M_size);
+ __valarray_release_memory(_M_data);
+ _M_size = __n;
+ _M_data = static_cast<_Tp*__restrict__>
+ (__valarray_get_memory(__n * sizeof (_Tp)));
+ __valarray_fill_construct(_M_data, _M_data + __n, __c);
+ }
+ else {
+ // this is so to make valarray<valarray<T> > work
+ // even though it is not required by the standard.
+ __valarray_destroy_elements(_M_data, _M_data + _M_size);
+ __valarray_fill_construct(_M_data, _M_data + _M_size, __c);
+ }
+ }
+
+ template<typename _Tp>
+ inline _Tp
+ valarray<_Tp>::min() const
+ {
+ return *min_element (_M_data, _M_data+_M_size);
+ }
+
+ template<typename _Tp>
+ inline _Tp
+ valarray<_Tp>::max() const
+ {
+ return *max_element (_M_data, _M_data+_M_size);
+ }
+
+ template<class _Tp>
+ inline _Expr<_ValFunClos<_ValArray,_Tp>,_Tp>
+ valarray<_Tp>::apply (_Tp func (_Tp)) const
+ {
+ typedef _ValFunClos<_ValArray,_Tp> _Closure;
+ return _Expr<_Closure,_Tp> (_Closure (*this, func));
+ }
+
+ template<class _Tp>
+ inline _Expr<_RefFunClos<_ValArray,_Tp>,_Tp>
+ valarray<_Tp>::apply (_Tp func (const _Tp &)) const
+ {
+ typedef _RefFunClos<_ValArray,_Tp> _Closure;
+ return _Expr<_Closure,_Tp> (_Closure (*this, func));
+ }
+
+#define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name) \
+ template<typename _Tp> \
+ inline _Expr<_UnClos<_Name,_ValArray,_Tp>, _Tp> \
+ valarray<_Tp>::operator##_Op() const \
+ { \
+ typedef _UnClos<_Name,_ValArray,_Tp> _Closure; \
+ return _Expr<_Closure, _Tp> (_Closure (*this)); \
+ }
+
+ _DEFINE_VALARRAY_UNARY_OPERATOR(+, _Unary_plus)
+ _DEFINE_VALARRAY_UNARY_OPERATOR(-, negate)
+ _DEFINE_VALARRAY_UNARY_OPERATOR(~, _Bitwise_not)
+
+#undef _DEFINE_VALARRAY_UNARY_OPERATOR
+
+ template<typename _Tp>
+ inline _Expr<_UnClos<logical_not,_ValArray,_Tp>, bool>
+ valarray<_Tp>::operator!() const
+ {
+ typedef _UnClos<logical_not,_ValArray,_Tp> _Closure;
+ return _Expr<_Closure, bool> (_Closure (*this));
+ }
+
+#define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \
+ template<class _Tp> \
+ inline valarray<_Tp> & \
+ valarray<_Tp>::operator##_Op##= (const _Tp &__t) \
+ { \
+ _Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, __t); \
+ return *this; \
+ } \
+ \
+ template<class _Tp> \
+ inline valarray<_Tp> & \
+ valarray<_Tp>::operator##_Op##= (const valarray<_Tp> &__v) \
+ { \
+ _Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, \
+ _Array<_Tp>(__v._M_data)); \
+ return *this; \
+ }
+
+_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, plus)
+_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, minus)
+_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, multiplies)
+_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, divides)
+_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, modulus)
+_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, xor)
+_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, and)
+_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, or)
+_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, shift_left)
+_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, shift_right)
+
+#undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT
+
+
+} // std::
+
+
+namespace std {
+
+#define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \
+ template<class _Tp> template<class _Dom> \
+ inline valarray<_Tp> & \
+ valarray<_Tp>::operator##_Op##= (const _Expr<_Dom,_Tp> &__e) \
+ { \
+ _Array_augmented_##_Name (_Array<_Tp>(_M_data), __e, _M_size); \
+ return *this; \
+ }
+
+_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, plus)
+_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, minus)
+_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, multiplies)
+_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, divides)
+_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, modulus)
+_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, xor)
+_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, and)
+_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, or)
+_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, shift_left)
+_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, shift_right)
+
+#undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
+
+
+#define _DEFINE_BINARY_OPERATOR(_Op, _Name) \
+ template<typename _Tp> \
+ inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>, _Tp> \
+ operator##_Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \
+ { \
+ typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
+ return _Expr<_Closure, _Tp> (_Closure (__v, __w)); \
+ } \
+ \
+ template<typename _Tp> \
+ inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,_Tp> \
+ operator##_Op (const valarray<_Tp> &__v, const _Tp &__t) \
+ { \
+ typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
+ return _Expr<_Closure, _Tp> (_Closure (__v, __t)); \
+ } \
+ \
+ template<typename _Tp> \
+ inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,_Tp> \
+ operator##_Op (const _Tp &__t, const valarray<_Tp> &__v) \
+ { \
+ typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
+ return _Expr<_Closure, _Tp> (_Closure (__t, __v)); \
+ }
+
+_DEFINE_BINARY_OPERATOR(+, plus)
+_DEFINE_BINARY_OPERATOR(-, minus)
+_DEFINE_BINARY_OPERATOR(*, multiplies)
+_DEFINE_BINARY_OPERATOR(/, divides)
+_DEFINE_BINARY_OPERATOR(%, modulus)
+_DEFINE_BINARY_OPERATOR(^, _Bitwise_xor)
+_DEFINE_BINARY_OPERATOR(&, _Bitwise_and)
+_DEFINE_BINARY_OPERATOR(|, _Bitwise_or)
+_DEFINE_BINARY_OPERATOR(<<, _Shift_left)
+_DEFINE_BINARY_OPERATOR(>>, _Shift_right)
+
+#undef _DEFINE_BINARY_OPERATOR
+
+#define _DEFINE_LOGICAL_OPERATOR(_Op, _Name) \
+ template<typename _Tp> \
+ inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>,bool> \
+ operator##_Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \
+ { \
+ typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
+ return _Expr<_Closure, bool> (_Closure (__v, __w)); \
+ } \
+ \
+ template<class _Tp> \
+ inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,bool> \
+ operator##_Op (const valarray<_Tp> &__v, const _Tp &__t) \
+ { \
+ typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
+ return _Expr<_Closure, bool> (_Closure (__v, __t)); \
+ } \
+ \
+ template<class _Tp> \
+ inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,bool> \
+ operator##_Op (const _Tp &__t, const valarray<_Tp> &__v) \
+ { \
+ typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
+ return _Expr<_Closure, bool> (_Closure (__t, __v)); \
+ }
+
+_DEFINE_LOGICAL_OPERATOR(&&, logical_and)
+_DEFINE_LOGICAL_OPERATOR(||, logical_or)
+_DEFINE_LOGICAL_OPERATOR(==, equal_to)
+_DEFINE_LOGICAL_OPERATOR(!=, not_equal_to)
+_DEFINE_LOGICAL_OPERATOR(<, less)
+_DEFINE_LOGICAL_OPERATOR(>, greater)
+_DEFINE_LOGICAL_OPERATOR(<=, less_equal)
+_DEFINE_LOGICAL_OPERATOR(>=, greater_equal)
+
+#undef _DEFINE_VALARRAY_OPERATOR
+
+} // namespace std
+
+#endif // _CPP_VALARRAY
+
+// Local Variables:
+// mode:c++
+// End:
diff --git a/libstdc++-v3/bits/std_vector.h b/libstdc++-v3/bits/std_vector.h
new file mode 100644
index 0000000..08ac4bd
--- /dev/null
+++ b/libstdc++-v3/bits/std_vector.h
@@ -0,0 +1,42 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_VECTOR
+#define _CPP_VECTOR 1
+
+#include <bits/stl_range_errors.h>
+#include <bits/stl_algobase.h>
+#include <bits/stl_alloc.h>
+#include <bits/stl_construct.h>
+#include <bits/stl_uninitialized.h>
+#include <bits/stl_vector.h>
+#include <ext/stl_bvector.h>
+
+#endif /* _CPP_VECTOR */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_algo.h b/libstdc++-v3/bits/stl_algo.h
new file mode 100644
index 0000000..60d40f6
--- /dev/null
+++ b/libstdc++-v3/bits/stl_algo.h
@@ -0,0 +1,2900 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_ALGO_H
+#define __SGI_STL_INTERNAL_ALGO_H
+
+#include <bits/stl_heap.h>
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1209
+#endif
+
+// __median (an extension, not present in the C++ standard).
+
+template <class _Tp>
+inline const _Tp& __median(const _Tp& __a, const _Tp& __b, const _Tp& __c) {
+ if (__a < __b)
+ if (__b < __c)
+ return __b;
+ else if (__a < __c)
+ return __c;
+ else
+ return __a;
+ else if (__a < __c)
+ return __a;
+ else if (__b < __c)
+ return __c;
+ else
+ return __b;
+}
+
+template <class _Tp, class _Compare>
+inline const _Tp&
+__median(const _Tp& __a, const _Tp& __b, const _Tp& __c, _Compare __comp) {
+ if (__comp(__a, __b))
+ if (__comp(__b, __c))
+ return __b;
+ else if (__comp(__a, __c))
+ return __c;
+ else
+ return __a;
+ else if (__comp(__a, __c))
+ return __a;
+ else if (__comp(__b, __c))
+ return __c;
+ else
+ return __b;
+}
+
+// for_each. Apply a function to every element of a range.
+template <class _InputIter, class _Function>
+_Function for_each(_InputIter __first, _InputIter __last, _Function __f) {
+ for ( ; __first != __last; ++__first)
+ __f(*__first);
+ return __f;
+}
+
+// find and find_if.
+
+template <class _InputIter, class _Tp>
+inline _InputIter find(_InputIter __first, _InputIter __last,
+ const _Tp& __val,
+ input_iterator_tag)
+{
+ while (__first != __last && *__first != __val)
+ ++__first;
+ return __first;
+}
+
+template <class _InputIter, class _Predicate>
+inline _InputIter find_if(_InputIter __first, _InputIter __last,
+ _Predicate __pred,
+ input_iterator_tag)
+{
+ while (__first != __last && !__pred(*__first))
+ ++__first;
+ return __first;
+}
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _RandomAccessIter, class _Tp>
+_RandomAccessIter find(_RandomAccessIter __first, _RandomAccessIter __last,
+ const _Tp& __val,
+ random_access_iterator_tag)
+{
+ typename iterator_traits<_RandomAccessIter>::difference_type __trip_count
+ = (__last - __first) >> 2;
+
+ for ( ; __trip_count > 0 ; --__trip_count) {
+ if (*__first == __val) return __first;
+ ++__first;
+
+ if (*__first == __val) return __first;
+ ++__first;
+
+ if (*__first == __val) return __first;
+ ++__first;
+
+ if (*__first == __val) return __first;
+ ++__first;
+ }
+
+ switch(__last - __first) {
+ case 3:
+ if (*__first == __val) return __first;
+ ++__first;
+ case 2:
+ if (*__first == __val) return __first;
+ ++__first;
+ case 1:
+ if (*__first == __val) return __first;
+ ++__first;
+ case 0:
+ default:
+ return __last;
+ }
+}
+
+template <class _RandomAccessIter, class _Predicate>
+_RandomAccessIter find_if(_RandomAccessIter __first, _RandomAccessIter __last,
+ _Predicate __pred,
+ random_access_iterator_tag)
+{
+ typename iterator_traits<_RandomAccessIter>::difference_type __trip_count
+ = (__last - __first) >> 2;
+
+ for ( ; __trip_count > 0 ; --__trip_count) {
+ if (__pred(*__first)) return __first;
+ ++__first;
+
+ if (__pred(*__first)) return __first;
+ ++__first;
+
+ if (__pred(*__first)) return __first;
+ ++__first;
+
+ if (__pred(*__first)) return __first;
+ ++__first;
+ }
+
+ switch(__last - __first) {
+ case 3:
+ if (__pred(*__first)) return __first;
+ ++__first;
+ case 2:
+ if (__pred(*__first)) return __first;
+ ++__first;
+ case 1:
+ if (__pred(*__first)) return __first;
+ ++__first;
+ case 0:
+ default:
+ return __last;
+ }
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _InputIter, class _Tp>
+inline _InputIter find(_InputIter __first, _InputIter __last,
+ const _Tp& __val)
+{
+ return find(__first, __last, __val, __ITERATOR_CATEGORY(__first));
+}
+
+template <class _InputIter, class _Predicate>
+inline _InputIter find_if(_InputIter __first, _InputIter __last,
+ _Predicate __pred) {
+ return find_if(__first, __last, __pred, __ITERATOR_CATEGORY(__first));
+}
+
+// adjacent_find.
+
+template <class _ForwardIter>
+_ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last) {
+ if (__first == __last)
+ return __last;
+ _ForwardIter __next = __first;
+ while(++__next != __last) {
+ if (*__first == *__next)
+ return __first;
+ __first = __next;
+ }
+ return __last;
+}
+
+template <class _ForwardIter, class _BinaryPredicate>
+_ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last,
+ _BinaryPredicate __binary_pred) {
+ if (__first == __last)
+ return __last;
+ _ForwardIter __next = __first;
+ while(++__next != __last) {
+ if (__binary_pred(*__first, *__next))
+ return __first;
+ __first = __next;
+ }
+ return __last;
+}
+
+// count and count_if. There are two version of each, one whose return type
+// type is void and one (present only if we have partial specialization)
+// whose return type is iterator_traits<_InputIter>::difference_type. The
+// C++ standard only has the latter version, but the former, which was present
+// in the HP STL, is retained for backward compatibility.
+
+template <class _InputIter, class _Tp, class _Size>
+void count(_InputIter __first, _InputIter __last, const _Tp& __value,
+ _Size& __n) {
+ for ( ; __first != __last; ++__first)
+ if (*__first == __value)
+ ++__n;
+}
+
+template <class _InputIter, class _Predicate, class _Size>
+void count_if(_InputIter __first, _InputIter __last, _Predicate __pred,
+ _Size& __n) {
+ for ( ; __first != __last; ++__first)
+ if (__pred(*__first))
+ ++__n;
+}
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _InputIter, class _Tp>
+typename iterator_traits<_InputIter>::difference_type
+count(_InputIter __first, _InputIter __last, const _Tp& __value) {
+ typename iterator_traits<_InputIter>::difference_type __n = 0;
+ for ( ; __first != __last; ++__first)
+ if (*__first == __value)
+ ++__n;
+ return __n;
+}
+
+template <class _InputIter, class _Predicate>
+typename iterator_traits<_InputIter>::difference_type
+count_if(_InputIter __first, _InputIter __last, _Predicate __pred) {
+ typename iterator_traits<_InputIter>::difference_type __n = 0;
+ for ( ; __first != __last; ++__first)
+ if (__pred(*__first))
+ ++__n;
+ return __n;
+}
+
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+// search.
+
+template <class _ForwardIter1, class _ForwardIter2>
+_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
+ _ForwardIter2 __first2, _ForwardIter2 __last2)
+{
+ // Test for empty ranges
+ if (__first1 == __last1 || __first2 == __last2)
+ return __first1;
+
+ // Test for a pattern of length 1.
+ _ForwardIter2 __tmp(__first2);
+ ++__tmp;
+ if (__tmp == __last2)
+ return find(__first1, __last1, *__first2);
+
+ // General case.
+
+ _ForwardIter2 __p1, __p;
+
+ __p1 = __first2; ++__p1;
+
+ _ForwardIter1 __current = __first1;
+
+ while (__first1 != __last1) {
+ __first1 = find(__first1, __last1, *__first2);
+ if (__first1 == __last1)
+ return __last1;
+
+ __p = __p1;
+ __current = __first1;
+ if (++__current == __last1)
+ return __last1;
+
+ while (*__current == *__p) {
+ if (++__p == __last2)
+ return __first1;
+ if (++__current == __last1)
+ return __last1;
+ }
+
+ ++__first1;
+ }
+ return __first1;
+}
+
+template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>
+_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
+ _ForwardIter2 __first2, _ForwardIter2 __last2,
+ _BinaryPred __predicate)
+{
+ // Test for empty ranges
+ if (__first1 == __last1 || __first2 == __last2)
+ return __first1;
+
+ // Test for a pattern of length 1.
+ _ForwardIter2 __tmp(__first2);
+ ++__tmp;
+ if (__tmp == __last2) {
+ while (__first1 != __last1 && !__predicate(*__first1, *__first2))
+ ++__first1;
+ return __first1;
+ }
+
+ // General case.
+
+ _ForwardIter2 __p1, __p;
+
+ __p1 = __first2; ++__p1;
+
+ _ForwardIter1 __current = __first1;
+
+ while (__first1 != __last1) {
+ while (__first1 != __last1) {
+ if (__predicate(*__first1, *__first2))
+ break;
+ ++__first1;
+ }
+ while (__first1 != __last1 && !__predicate(*__first1, *__first2))
+ ++__first1;
+ if (__first1 == __last1)
+ return __last1;
+
+ __p = __p1;
+ __current = __first1;
+ if (++__current == __last1) return __last1;
+
+ while (__predicate(*__current, *__p)) {
+ if (++__p == __last2)
+ return __first1;
+ if (++__current == __last1)
+ return __last1;
+ }
+
+ ++__first1;
+ }
+ return __first1;
+}
+
+// search_n. Search for __count consecutive copies of __val.
+
+template <class _ForwardIter, class _Integer, class _Tp>
+_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
+ _Integer __count, const _Tp& __val) {
+ if (__count <= 0)
+ return __first;
+ else {
+ __first = find(__first, __last, __val);
+ while (__first != __last) {
+ _Integer __n = __count - 1;
+ _ForwardIter __i = __first;
+ ++__i;
+ while (__i != __last && __n != 0 && *__i == __val) {
+ ++__i;
+ --__n;
+ }
+ if (__n == 0)
+ return __first;
+ else
+ __first = find(__i, __last, __val);
+ }
+ return __last;
+ }
+}
+
+template <class _ForwardIter, class _Integer, class _Tp, class _BinaryPred>
+_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
+ _Integer __count, const _Tp& __val,
+ _BinaryPred __binary_pred) {
+ if (__count <= 0)
+ return __first;
+ else {
+ while (__first != __last) {
+ if (__binary_pred(*__first, __val))
+ break;
+ ++__first;
+ }
+ while (__first != __last) {
+ _Integer __n = __count - 1;
+ _ForwardIter __i = __first;
+ ++__i;
+ while (__i != __last && __n != 0 && __binary_pred(*__i, __val)) {
+ ++__i;
+ --__n;
+ }
+ if (__n == 0)
+ return __first;
+ else {
+ while (__i != __last) {
+ if (__binary_pred(*__i, __val))
+ break;
+ ++__i;
+ }
+ __first = __i;
+ }
+ }
+ return __last;
+ }
+}
+
+// swap_ranges
+
+template <class _ForwardIter1, class _ForwardIter2>
+_ForwardIter2 swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1,
+ _ForwardIter2 __first2) {
+ for ( ; __first1 != __last1; ++__first1, ++__first2)
+ iter_swap(__first1, __first2);
+ return __first2;
+}
+
+// transform
+
+template <class _InputIter, class _OutputIter, class _UnaryOperation>
+_OutputIter transform(_InputIter __first, _InputIter __last,
+ _OutputIter __result, _UnaryOperation __unary_op) {
+ for ( ; __first != __last; ++__first, ++__result)
+ *__result = __unary_op(*__first);
+ return __result;
+}
+
+template <class _InputIter1, class _InputIter2, class _OutputIter,
+ class _BinaryOperation>
+_OutputIter transform(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _OutputIter __result,
+ _BinaryOperation __binary_op) {
+ for ( ; __first1 != __last1; ++__first1, ++__first2, ++__result)
+ *__result = __binary_op(*__first1, *__first2);
+ return __result;
+}
+
+// replace, replace_if, replace_copy, replace_copy_if
+
+template <class _ForwardIter, class _Tp>
+void replace(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __old_value, const _Tp& __new_value) {
+ for ( ; __first != __last; ++__first)
+ if (*__first == __old_value)
+ *__first = __new_value;
+}
+
+template <class _ForwardIter, class _Predicate, class _Tp>
+void replace_if(_ForwardIter __first, _ForwardIter __last,
+ _Predicate __pred, const _Tp& __new_value) {
+ for ( ; __first != __last; ++__first)
+ if (__pred(*__first))
+ *__first = __new_value;
+}
+
+template <class _InputIter, class _OutputIter, class _Tp>
+_OutputIter replace_copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result,
+ const _Tp& __old_value, const _Tp& __new_value) {
+ for ( ; __first != __last; ++__first, ++__result)
+ *__result = *__first == __old_value ? __new_value : *__first;
+ return __result;
+}
+
+template <class Iterator, class _OutputIter, class _Predicate, class _Tp>
+_OutputIter replace_copy_if(Iterator __first, Iterator __last,
+ _OutputIter __result,
+ _Predicate __pred, const _Tp& __new_value) {
+ for ( ; __first != __last; ++__first, ++__result)
+ *__result = __pred(*__first) ? __new_value : *__first;
+ return __result;
+}
+
+// generate and generate_n
+
+template <class _ForwardIter, class _Generator>
+void generate(_ForwardIter __first, _ForwardIter __last, _Generator __gen) {
+ for ( ; __first != __last; ++__first)
+ *__first = __gen();
+}
+
+template <class _OutputIter, class _Size, class _Generator>
+_OutputIter generate_n(_OutputIter __first, _Size __n, _Generator __gen) {
+ for ( ; __n > 0; --__n, ++__first)
+ *__first = __gen();
+ return __first;
+}
+
+// remove, remove_if, remove_copy, remove_copy_if
+
+template <class _InputIter, class _OutputIter, class _Tp>
+_OutputIter remove_copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result, const _Tp& __value) {
+ for ( ; __first != __last; ++__first)
+ if (*__first != __value) {
+ *__result = *__first;
+ ++__result;
+ }
+ return __result;
+}
+
+template <class _InputIter, class _OutputIter, class _Predicate>
+_OutputIter remove_copy_if(_InputIter __first, _InputIter __last,
+ _OutputIter __result, _Predicate __pred) {
+ for ( ; __first != __last; ++__first)
+ if (!__pred(*__first)) {
+ *__result = *__first;
+ ++__result;
+ }
+ return __result;
+}
+
+template <class _ForwardIter, class _Tp>
+_ForwardIter remove(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __value) {
+ __first = find(__first, __last, __value);
+ _ForwardIter __i = __first;
+ return __first == __last ? __first
+ : remove_copy(++__i, __last, __first, __value);
+}
+
+template <class _ForwardIter, class _Predicate>
+_ForwardIter remove_if(_ForwardIter __first, _ForwardIter __last,
+ _Predicate __pred) {
+ __first = find_if(__first, __last, __pred);
+ _ForwardIter __i = __first;
+ return __first == __last ? __first
+ : remove_copy_if(++__i, __last, __first, __pred);
+}
+
+// unique and unique_copy
+
+template <class _InputIter, class _OutputIter, class _Tp>
+_OutputIter __unique_copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result, _Tp*) {
+ _Tp __value = *__first;
+ *__result = __value;
+ while (++__first != __last)
+ if (__value != *__first) {
+ __value = *__first;
+ *++__result = __value;
+ }
+ return ++__result;
+}
+
+template <class _InputIter, class _OutputIter>
+inline _OutputIter __unique_copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result,
+ output_iterator_tag) {
+ return __unique_copy(__first, __last, __result, __VALUE_TYPE(__first));
+}
+
+template <class _InputIter, class _ForwardIter>
+_ForwardIter __unique_copy(_InputIter __first, _InputIter __last,
+ _ForwardIter __result, forward_iterator_tag) {
+ *__result = *__first;
+ while (++__first != __last)
+ if (*__result != *__first) *++__result = *__first;
+ return ++__result;
+}
+
+template <class _InputIter, class _OutputIter>
+inline _OutputIter unique_copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result) {
+ if (__first == __last) return __result;
+ return __unique_copy(__first, __last, __result,
+ __ITERATOR_CATEGORY(__result));
+}
+
+template <class _InputIter, class _OutputIter, class _BinaryPredicate,
+ class _Tp>
+_OutputIter __unique_copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result,
+ _BinaryPredicate __binary_pred, _Tp*) {
+ _Tp __value = *__first;
+ *__result = __value;
+ while (++__first != __last)
+ if (!__binary_pred(__value, *__first)) {
+ __value = *__first;
+ *++__result = __value;
+ }
+ return ++__result;
+}
+
+template <class _InputIter, class _OutputIter, class _BinaryPredicate>
+inline _OutputIter __unique_copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result,
+ _BinaryPredicate __binary_pred,
+ output_iterator_tag) {
+ return __unique_copy(__first, __last, __result, __binary_pred,
+ __VALUE_TYPE(__first));
+}
+
+template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
+_ForwardIter __unique_copy(_InputIter __first, _InputIter __last,
+ _ForwardIter __result,
+ _BinaryPredicate __binary_pred,
+ forward_iterator_tag) {
+ *__result = *__first;
+ while (++__first != __last)
+ if (!__binary_pred(*__result, *__first)) *++__result = *__first;
+ return ++__result;
+}
+
+template <class _InputIter, class _OutputIter, class _BinaryPredicate>
+inline _OutputIter unique_copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result,
+ _BinaryPredicate __binary_pred) {
+ if (__first == __last) return __result;
+ return __unique_copy(__first, __last, __result, __binary_pred,
+ __ITERATOR_CATEGORY(__result));
+}
+
+template <class _ForwardIter>
+_ForwardIter unique(_ForwardIter __first, _ForwardIter __last) {
+ __first = adjacent_find(__first, __last);
+ return unique_copy(__first, __last, __first);
+}
+
+template <class _ForwardIter, class _BinaryPredicate>
+_ForwardIter unique(_ForwardIter __first, _ForwardIter __last,
+ _BinaryPredicate __binary_pred) {
+ __first = adjacent_find(__first, __last, __binary_pred);
+ return unique_copy(__first, __last, __first, __binary_pred);
+}
+
+// reverse and reverse_copy, and their auxiliary functions
+
+template <class _BidirectionalIter>
+void __reverse(_BidirectionalIter __first, _BidirectionalIter __last,
+ bidirectional_iterator_tag) {
+ while (true)
+ if (__first == __last || __first == --__last)
+ return;
+ else
+ iter_swap(__first++, __last);
+}
+
+template <class _RandomAccessIter>
+void __reverse(_RandomAccessIter __first, _RandomAccessIter __last,
+ random_access_iterator_tag) {
+ while (__first < __last)
+ iter_swap(__first++, --__last);
+}
+
+template <class _BidirectionalIter>
+inline void reverse(_BidirectionalIter __first, _BidirectionalIter __last) {
+ __reverse(__first, __last, __ITERATOR_CATEGORY(__first));
+}
+
+template <class _BidirectionalIter, class _OutputIter>
+_OutputIter reverse_copy(_BidirectionalIter __first,
+ _BidirectionalIter __last,
+ _OutputIter __result) {
+ while (__first != __last) {
+ --__last;
+ *__result = *__last;
+ ++__result;
+ }
+ return __result;
+}
+
+// rotate and rotate_copy, and their auxiliary functions
+
+template <class _EuclideanRingElement>
+_EuclideanRingElement __gcd(_EuclideanRingElement __m,
+ _EuclideanRingElement __n)
+{
+ while (__n != 0) {
+ _EuclideanRingElement __t = __m % __n;
+ __m = __n;
+ __n = __t;
+ }
+ return __m;
+}
+
+template <class _ForwardIter, class _Distance>
+_ForwardIter __rotate(_ForwardIter __first,
+ _ForwardIter __middle,
+ _ForwardIter __last,
+ _Distance*,
+ forward_iterator_tag) {
+ if (__first == __middle)
+ return __last;
+ if (__last == __middle)
+ return __first;
+
+ _ForwardIter __first2 = __middle;
+ do {
+ swap(*__first++, *__first2++);
+ if (__first == __middle)
+ __middle = __first2;
+ } while (__first2 != __last);
+
+ _ForwardIter __new_middle = __first;
+
+ __first2 = __middle;
+
+ while (__first2 != __last) {
+ swap (*__first++, *__first2++);
+ if (__first == __middle)
+ __middle = __first2;
+ else if (__first2 == __last)
+ __first2 = __middle;
+ }
+
+ return __new_middle;
+}
+
+
+template <class _BidirectionalIter, class _Distance>
+_BidirectionalIter __rotate(_BidirectionalIter __first,
+ _BidirectionalIter __middle,
+ _BidirectionalIter __last,
+ _Distance*,
+ bidirectional_iterator_tag) {
+ if (__first == __middle)
+ return __last;
+ if (__last == __middle)
+ return __first;
+
+ __reverse(__first, __middle, bidirectional_iterator_tag());
+ __reverse(__middle, __last, bidirectional_iterator_tag());
+
+ while (__first != __middle && __middle != __last)
+ swap (*__first++, *--__last);
+
+ if (__first == __middle) {
+ __reverse(__middle, __last, bidirectional_iterator_tag());
+ return __last;
+ }
+ else {
+ __reverse(__first, __middle, bidirectional_iterator_tag());
+ return __first;
+ }
+}
+
+template <class _RandomAccessIter, class _Distance, class _Tp>
+_RandomAccessIter __rotate(_RandomAccessIter __first,
+ _RandomAccessIter __middle,
+ _RandomAccessIter __last,
+ _Distance *, _Tp *) {
+
+ _Distance __n = __last - __first;
+ _Distance __k = __middle - __first;
+ _Distance __l = __n - __k;
+ _RandomAccessIter __result = __first + (__last - __middle);
+
+ if (__k == 0)
+ return __last;
+
+ else if (__k == __l) {
+ swap_ranges(__first, __middle, __middle);
+ return __result;
+ }
+
+ _Distance __d = __gcd(__n, __k);
+
+ for (_Distance __i = 0; __i < __d; __i++) {
+ _Tp __tmp = *__first;
+ _RandomAccessIter __p = __first;
+
+ if (__k < __l) {
+ for (_Distance __j = 0; __j < __l/__d; __j++) {
+ if (__p > __first + __l) {
+ *__p = *(__p - __l);
+ __p -= __l;
+ }
+
+ *__p = *(__p + __k);
+ __p += __k;
+ }
+ }
+
+ else {
+ for (_Distance __j = 0; __j < __k/__d - 1; __j ++) {
+ if (__p < __last - __k) {
+ *__p = *(__p + __k);
+ __p += __k;
+ }
+
+ *__p = * (__p - __l);
+ __p -= __l;
+ }
+ }
+
+ *__p = __tmp;
+ ++__first;
+ }
+
+ return __result;
+}
+
+template <class _ForwardIter>
+inline _ForwardIter rotate(_ForwardIter __first, _ForwardIter __middle,
+ _ForwardIter __last) {
+ return __rotate(__first, __middle, __last,
+ __DISTANCE_TYPE(__first),
+ __ITERATOR_CATEGORY(__first));
+}
+
+template <class _ForwardIter, class _OutputIter>
+_OutputIter rotate_copy(_ForwardIter __first, _ForwardIter __middle,
+ _ForwardIter __last, _OutputIter __result) {
+ return copy(__first, __middle, copy(__middle, __last, __result));
+}
+
+// Return a random number in the range [0, __n). This function encapsulates
+// whether we're using rand (part of the standard C library) or lrand48
+// (not standard, but a much better choice whenever it's available).
+
+template <class _Distance>
+inline _Distance __random_number(_Distance __n) {
+#ifdef __STL_NO_DRAND48
+ return rand() % __n;
+#else
+ return lrand48() % __n;
+#endif
+}
+
+// random_shuffle
+
+template <class _RandomAccessIter>
+inline void random_shuffle(_RandomAccessIter __first,
+ _RandomAccessIter __last) {
+ if (__first == __last) return;
+ for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i)
+ iter_swap(__i, __first + __random_number((__i - __first) + 1));
+}
+
+template <class _RandomAccessIter, class _RandomNumberGenerator>
+void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last,
+ _RandomNumberGenerator& __rand) {
+ if (__first == __last) return;
+ for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i)
+ iter_swap(__i, __first + __rand((__i - __first) + 1));
+}
+
+// random_sample and random_sample_n (extensions, not part of the standard).
+
+template <class _ForwardIter, class _OutputIter, class _Distance>
+_OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
+ _OutputIter __out, const _Distance __n)
+{
+ _Distance __remaining = 0;
+ distance(__first, __last, __remaining);
+ _Distance __m = min(__n, __remaining);
+
+ while (__m > 0) {
+ if (__random_number(__remaining) < __m) {
+ *__out = *__first;
+ ++__out;
+ --__m;
+ }
+
+ --__remaining;
+ ++__first;
+ }
+ return __out;
+}
+
+template <class _ForwardIter, class _OutputIter, class _Distance,
+ class _RandomNumberGenerator>
+_OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
+ _OutputIter __out, const _Distance __n,
+ _RandomNumberGenerator& __rand)
+{
+ _Distance __remaining = 0;
+ distance(__first, __last, __remaining);
+ _Distance __m = min(__n, __remaining);
+
+ while (__m > 0) {
+ if (__rand(__remaining) < __m) {
+ *__out = *__first;
+ ++__out;
+ --__m;
+ }
+
+ --__remaining;
+ ++__first;
+ }
+ return __out;
+}
+
+template <class _InputIter, class _RandomAccessIter, class _Distance>
+_RandomAccessIter __random_sample(_InputIter __first, _InputIter __last,
+ _RandomAccessIter __out,
+ const _Distance __n)
+{
+ _Distance __m = 0;
+ _Distance __t = __n;
+ for ( ; __first != __last && __m < __n; ++__m, ++__first)
+ __out[__m] = *__first;
+
+ while (__first != __last) {
+ ++__t;
+ _Distance __M = __random_number(__t);
+ if (__M < __n)
+ __out[__M] = *__first;
+ ++__first;
+ }
+
+ return __out + __m;
+}
+
+template <class _InputIter, class _RandomAccessIter,
+ class _RandomNumberGenerator, class _Distance>
+_RandomAccessIter __random_sample(_InputIter __first, _InputIter __last,
+ _RandomAccessIter __out,
+ _RandomNumberGenerator& __rand,
+ const _Distance __n)
+{
+ _Distance __m = 0;
+ _Distance __t = __n;
+ for ( ; __first != __last && __m < __n; ++__m, ++__first)
+ __out[__m] = *__first;
+
+ while (__first != __last) {
+ ++__t;
+ _Distance __M = __rand(__t);
+ if (__M < __n)
+ __out[__M] = *__first;
+ ++__first;
+ }
+
+ return __out + __m;
+}
+
+template <class _InputIter, class _RandomAccessIter>
+inline _RandomAccessIter
+random_sample(_InputIter __first, _InputIter __last,
+ _RandomAccessIter __out_first, _RandomAccessIter __out_last)
+{
+ return __random_sample(__first, __last,
+ __out_first, __out_last - __out_first);
+}
+
+
+template <class _InputIter, class _RandomAccessIter,
+ class _RandomNumberGenerator>
+inline _RandomAccessIter
+random_sample(_InputIter __first, _InputIter __last,
+ _RandomAccessIter __out_first, _RandomAccessIter __out_last,
+ _RandomNumberGenerator& __rand)
+{
+ return __random_sample(__first, __last,
+ __out_first, __rand,
+ __out_last - __out_first);
+}
+
+// partition, stable_partition, and their auxiliary functions
+
+template <class _ForwardIter, class _Predicate>
+_ForwardIter __partition(_ForwardIter __first,
+ _ForwardIter __last,
+ _Predicate __pred,
+ forward_iterator_tag) {
+ if (__first == __last) return __first;
+
+ while (__pred(*__first))
+ if (++__first == __last) return __first;
+
+ _ForwardIter __next = __first;
+
+ while (++__next != __last)
+ if (__pred(*__next)) {
+ swap(*__first, *__next);
+ ++__first;
+ }
+
+ return __first;
+}
+
+template <class _BidirectionalIter, class _Predicate>
+_BidirectionalIter __partition(_BidirectionalIter __first,
+ _BidirectionalIter __last,
+ _Predicate __pred,
+ bidirectional_iterator_tag) {
+ while (true) {
+ while (true)
+ if (__first == __last)
+ return __first;
+ else if (__pred(*__first))
+ ++__first;
+ else
+ break;
+ --__last;
+ while (true)
+ if (__first == __last)
+ return __first;
+ else if (!__pred(*__last))
+ --__last;
+ else
+ break;
+ iter_swap(__first, __last);
+ ++__first;
+ }
+}
+
+template <class _ForwardIter, class _Predicate>
+inline _ForwardIter partition(_ForwardIter __first,
+ _ForwardIter __last,
+ _Predicate __pred) {
+ return __partition(__first, __last, __pred, __ITERATOR_CATEGORY(__first));
+}
+
+
+template <class _ForwardIter, class _Predicate, class _Distance>
+_ForwardIter __inplace_stable_partition(_ForwardIter __first,
+ _ForwardIter __last,
+ _Predicate __pred, _Distance __len) {
+ if (__len == 1)
+ return __pred(*__first) ? __last : __first;
+ _ForwardIter __middle = __first;
+ advance(__middle, __len / 2);
+ return rotate(__inplace_stable_partition(__first, __middle, __pred,
+ __len / 2),
+ __middle,
+ __inplace_stable_partition(__middle, __last, __pred,
+ __len - __len / 2));
+}
+
+template <class _ForwardIter, class _Pointer, class _Predicate,
+ class _Distance>
+_ForwardIter __stable_partition_adaptive(_ForwardIter __first,
+ _ForwardIter __last,
+ _Predicate __pred, _Distance __len,
+ _Pointer __buffer,
+ _Distance __buffer_size)
+{
+ if (__len <= __buffer_size) {
+ _ForwardIter __result1 = __first;
+ _Pointer __result2 = __buffer;
+ for ( ; __first != __last ; ++__first)
+ if (__pred(*__first)) {
+ *__result1 = *__first;
+ ++__result1;
+ }
+ else {
+ *__result2 = *__first;
+ ++__result2;
+ }
+ copy(__buffer, __result2, __result1);
+ return __result1;
+ }
+ else {
+ _ForwardIter __middle = __first;
+ advance(__middle, __len / 2);
+ return rotate(__stable_partition_adaptive(
+ __first, __middle, __pred,
+ __len / 2, __buffer, __buffer_size),
+ __middle,
+ __stable_partition_adaptive(
+ __middle, __last, __pred,
+ __len - __len / 2, __buffer, __buffer_size));
+ }
+}
+
+template <class _ForwardIter, class _Predicate, class _Tp, class _Distance>
+inline _ForwardIter
+__stable_partition_aux(_ForwardIter __first, _ForwardIter __last,
+ _Predicate __pred, _Tp*, _Distance*)
+{
+ _Temporary_buffer<_ForwardIter, _Tp> __buf(__first, __last);
+ if (__buf.size() > 0)
+ return __stable_partition_adaptive(__first, __last, __pred,
+ _Distance(__buf.requested_size()),
+ __buf.begin(), __buf.size());
+ else
+ return __inplace_stable_partition(__first, __last, __pred,
+ _Distance(__buf.requested_size()));
+}
+
+template <class _ForwardIter, class _Predicate>
+inline _ForwardIter stable_partition(_ForwardIter __first,
+ _ForwardIter __last,
+ _Predicate __pred) {
+ if (__first == __last)
+ return __first;
+ else
+ return __stable_partition_aux(__first, __last, __pred,
+ __VALUE_TYPE(__first),
+ __DISTANCE_TYPE(__first));
+}
+
+template <class _RandomAccessIter, class _Tp>
+_RandomAccessIter __unguarded_partition(_RandomAccessIter __first,
+ _RandomAccessIter __last,
+ _Tp __pivot)
+{
+ while (true) {
+ while (*__first < __pivot)
+ ++__first;
+ --__last;
+ while (__pivot < *__last)
+ --__last;
+ if (!(__first < __last))
+ return __first;
+ iter_swap(__first, __last);
+ ++__first;
+ }
+}
+
+template <class _RandomAccessIter, class _Tp, class _Compare>
+_RandomAccessIter __unguarded_partition(_RandomAccessIter __first,
+ _RandomAccessIter __last,
+ _Tp __pivot, _Compare __comp)
+{
+ while (true) {
+ while (__comp(*__first, __pivot))
+ ++__first;
+ --__last;
+ while (__comp(__pivot, *__last))
+ --__last;
+ if (!(__first < __last))
+ return __first;
+ iter_swap(__first, __last);
+ ++__first;
+ }
+}
+
+const int __stl_threshold = 16;
+
+// sort() and its auxiliary functions.
+
+template <class _RandomAccessIter, class _Tp>
+void __unguarded_linear_insert(_RandomAccessIter __last, _Tp __val) {
+ _RandomAccessIter __next = __last;
+ --__next;
+ while (__val < *__next) {
+ *__last = *__next;
+ __last = __next;
+ --__next;
+ }
+ *__last = __val;
+}
+
+template <class _RandomAccessIter, class _Tp, class _Compare>
+void __unguarded_linear_insert(_RandomAccessIter __last, _Tp __val,
+ _Compare __comp) {
+ _RandomAccessIter __next = __last;
+ --__next;
+ while (__comp(__val, *__next)) {
+ *__last = *__next;
+ __last = __next;
+ --__next;
+ }
+ *__last = __val;
+}
+
+template <class _RandomAccessIter, class _Tp>
+inline void __linear_insert(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Tp*) {
+ _Tp __val = *__last;
+ if (__val < *__first) {
+ copy_backward(__first, __last, __last + 1);
+ *__first = __val;
+ }
+ else
+ __unguarded_linear_insert(__last, __val);
+}
+
+template <class _RandomAccessIter, class _Tp, class _Compare>
+inline void __linear_insert(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Tp*, _Compare __comp) {
+ _Tp __val = *__last;
+ if (__comp(__val, *__first)) {
+ copy_backward(__first, __last, __last + 1);
+ *__first = __val;
+ }
+ else
+ __unguarded_linear_insert(__last, __val, __comp);
+}
+
+template <class _RandomAccessIter>
+void __insertion_sort(_RandomAccessIter __first, _RandomAccessIter __last) {
+ if (__first == __last) return;
+ for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i)
+ __linear_insert(__first, __i, __VALUE_TYPE(__first));
+}
+
+template <class _RandomAccessIter, class _Compare>
+void __insertion_sort(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Compare __comp) {
+ if (__first == __last) return;
+ for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i)
+ __linear_insert(__first, __i, __VALUE_TYPE(__first), __comp);
+}
+
+template <class _RandomAccessIter, class _Tp>
+void __unguarded_insertion_sort_aux(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Tp*) {
+ for (_RandomAccessIter __i = __first; __i != __last; ++__i)
+ __unguarded_linear_insert(__i, _Tp(*__i));
+}
+
+template <class _RandomAccessIter>
+inline void __unguarded_insertion_sort(_RandomAccessIter __first,
+ _RandomAccessIter __last) {
+ __unguarded_insertion_sort_aux(__first, __last, __VALUE_TYPE(__first));
+}
+
+template <class _RandomAccessIter, class _Tp, class _Compare>
+void __unguarded_insertion_sort_aux(_RandomAccessIter __first,
+ _RandomAccessIter __last,
+ _Tp*, _Compare __comp) {
+ for (_RandomAccessIter __i = __first; __i != __last; ++__i)
+ __unguarded_linear_insert(__i, _Tp(*__i), __comp);
+}
+
+template <class _RandomAccessIter, class _Compare>
+inline void __unguarded_insertion_sort(_RandomAccessIter __first,
+ _RandomAccessIter __last,
+ _Compare __comp) {
+ __unguarded_insertion_sort_aux(__first, __last, __VALUE_TYPE(__first),
+ __comp);
+}
+
+template <class _RandomAccessIter>
+void __final_insertion_sort(_RandomAccessIter __first,
+ _RandomAccessIter __last) {
+ if (__last - __first > __stl_threshold) {
+ __insertion_sort(__first, __first + __stl_threshold);
+ __unguarded_insertion_sort(__first + __stl_threshold, __last);
+ }
+ else
+ __insertion_sort(__first, __last);
+}
+
+template <class _RandomAccessIter, class _Compare>
+void __final_insertion_sort(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Compare __comp) {
+ if (__last - __first > __stl_threshold) {
+ __insertion_sort(__first, __first + __stl_threshold, __comp);
+ __unguarded_insertion_sort(__first + __stl_threshold, __last, __comp);
+ }
+ else
+ __insertion_sort(__first, __last, __comp);
+}
+
+template <class _Size>
+inline _Size __lg(_Size __n) {
+ _Size __k;
+ for (__k = 0; __n != 1; __n >>= 1) ++__k;
+ return __k;
+}
+
+template <class _RandomAccessIter, class _Tp, class _Size>
+void __introsort_loop(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Tp*,
+ _Size __depth_limit)
+{
+ while (__last - __first > __stl_threshold) {
+ if (__depth_limit == 0) {
+ partial_sort(__first, __last, __last);
+ return;
+ }
+ --__depth_limit;
+ _RandomAccessIter __cut =
+ __unguarded_partition(__first, __last,
+ _Tp(__median(*__first,
+ *(__first + (__last - __first)/2),
+ *(__last - 1))));
+ __introsort_loop(__cut, __last, (_Tp*) 0, __depth_limit);
+ __last = __cut;
+ }
+}
+
+template <class _RandomAccessIter, class _Tp, class _Size, class _Compare>
+void __introsort_loop(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Tp*,
+ _Size __depth_limit, _Compare __comp)
+{
+ while (__last - __first > __stl_threshold) {
+ if (__depth_limit == 0) {
+ partial_sort(__first, __last, __last, __comp);
+ return;
+ }
+ --__depth_limit;
+ _RandomAccessIter __cut =
+ __unguarded_partition(__first, __last,
+ _Tp(__median(*__first,
+ *(__first + (__last - __first)/2),
+ *(__last - 1), __comp)),
+ __comp);
+ __introsort_loop(__cut, __last, (_Tp*) 0, __depth_limit, __comp);
+ __last = __cut;
+ }
+}
+
+template <class _RandomAccessIter>
+inline void sort(_RandomAccessIter __first, _RandomAccessIter __last) {
+ if (__first != __last) {
+ __introsort_loop(__first, __last,
+ __VALUE_TYPE(__first),
+ __lg(__last - __first) * 2);
+ __final_insertion_sort(__first, __last);
+ }
+}
+
+template <class _RandomAccessIter, class _Compare>
+inline void sort(_RandomAccessIter __first, _RandomAccessIter __last,
+ _Compare __comp) {
+ if (__first != __last) {
+ __introsort_loop(__first, __last,
+ __VALUE_TYPE(__first),
+ __lg(__last - __first) * 2,
+ __comp);
+ __final_insertion_sort(__first, __last, __comp);
+ }
+}
+
+// stable_sort() and its auxiliary functions.
+
+template <class _RandomAccessIter>
+void __inplace_stable_sort(_RandomAccessIter __first,
+ _RandomAccessIter __last) {
+ if (__last - __first < 15) {
+ __insertion_sort(__first, __last);
+ return;
+ }
+ _RandomAccessIter __middle = __first + (__last - __first) / 2;
+ __inplace_stable_sort(__first, __middle);
+ __inplace_stable_sort(__middle, __last);
+ __merge_without_buffer(__first, __middle, __last,
+ __middle - __first,
+ __last - __middle);
+}
+
+template <class _RandomAccessIter, class _Compare>
+void __inplace_stable_sort(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Compare __comp) {
+ if (__last - __first < 15) {
+ __insertion_sort(__first, __last, __comp);
+ return;
+ }
+ _RandomAccessIter __middle = __first + (__last - __first) / 2;
+ __inplace_stable_sort(__first, __middle, __comp);
+ __inplace_stable_sort(__middle, __last, __comp);
+ __merge_without_buffer(__first, __middle, __last,
+ __middle - __first,
+ __last - __middle,
+ __comp);
+}
+
+template <class _RandomAccessIter1, class _RandomAccessIter2,
+ class _Distance>
+void __merge_sort_loop(_RandomAccessIter1 __first,
+ _RandomAccessIter1 __last,
+ _RandomAccessIter2 __result, _Distance __step_size) {
+ _Distance __two_step = 2 * __step_size;
+
+ while (__last - __first >= __two_step) {
+ __result = merge(__first, __first + __step_size,
+ __first + __step_size, __first + __two_step,
+ __result);
+ __first += __two_step;
+ }
+
+ __step_size = min(_Distance(__last - __first), __step_size);
+ merge(__first, __first + __step_size, __first + __step_size, __last,
+ __result);
+}
+
+template <class _RandomAccessIter1, class _RandomAccessIter2,
+ class _Distance, class _Compare>
+void __merge_sort_loop(_RandomAccessIter1 __first,
+ _RandomAccessIter1 __last,
+ _RandomAccessIter2 __result, _Distance __step_size,
+ _Compare __comp) {
+ _Distance __two_step = 2 * __step_size;
+
+ while (__last - __first >= __two_step) {
+ __result = merge(__first, __first + __step_size,
+ __first + __step_size, __first + __two_step,
+ __result,
+ __comp);
+ __first += __two_step;
+ }
+ __step_size = min(_Distance(__last - __first), __step_size);
+
+ merge(__first, __first + __step_size,
+ __first + __step_size, __last,
+ __result,
+ __comp);
+}
+
+const int __stl_chunk_size = 7;
+
+template <class _RandomAccessIter, class _Distance>
+void __chunk_insertion_sort(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Distance __chunk_size)
+{
+ while (__last - __first >= __chunk_size) {
+ __insertion_sort(__first, __first + __chunk_size);
+ __first += __chunk_size;
+ }
+ __insertion_sort(__first, __last);
+}
+
+template <class _RandomAccessIter, class _Distance, class _Compare>
+void __chunk_insertion_sort(_RandomAccessIter __first,
+ _RandomAccessIter __last,
+ _Distance __chunk_size, _Compare __comp)
+{
+ while (__last - __first >= __chunk_size) {
+ __insertion_sort(__first, __first + __chunk_size, __comp);
+ __first += __chunk_size;
+ }
+ __insertion_sort(__first, __last, __comp);
+}
+
+template <class _RandomAccessIter, class _Pointer, class _Distance>
+void __merge_sort_with_buffer(_RandomAccessIter __first,
+ _RandomAccessIter __last,
+ _Pointer __buffer, _Distance*) {
+ _Distance __len = __last - __first;
+ _Pointer __buffer_last = __buffer + __len;
+
+ _Distance __step_size = __stl_chunk_size;
+ __chunk_insertion_sort(__first, __last, __step_size);
+
+ while (__step_size < __len) {
+ __merge_sort_loop(__first, __last, __buffer, __step_size);
+ __step_size *= 2;
+ __merge_sort_loop(__buffer, __buffer_last, __first, __step_size);
+ __step_size *= 2;
+ }
+}
+
+template <class _RandomAccessIter, class _Pointer, class _Distance,
+ class _Compare>
+void __merge_sort_with_buffer(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Pointer __buffer,
+ _Distance*, _Compare __comp) {
+ _Distance __len = __last - __first;
+ _Pointer __buffer_last = __buffer + __len;
+
+ _Distance __step_size = __stl_chunk_size;
+ __chunk_insertion_sort(__first, __last, __step_size, __comp);
+
+ while (__step_size < __len) {
+ __merge_sort_loop(__first, __last, __buffer, __step_size, __comp);
+ __step_size *= 2;
+ __merge_sort_loop(__buffer, __buffer_last, __first, __step_size, __comp);
+ __step_size *= 2;
+ }
+}
+
+template <class _RandomAccessIter, class _Pointer, class _Distance>
+void __stable_sort_adaptive(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Pointer __buffer,
+ _Distance __buffer_size) {
+ _Distance __len = (__last - __first + 1) / 2;
+ _RandomAccessIter __middle = __first + __len;
+ if (__len > __buffer_size) {
+ __stable_sort_adaptive(__first, __middle, __buffer, __buffer_size);
+ __stable_sort_adaptive(__middle, __last, __buffer, __buffer_size);
+ }
+ else {
+ __merge_sort_with_buffer(__first, __middle, __buffer, (_Distance*)0);
+ __merge_sort_with_buffer(__middle, __last, __buffer, (_Distance*)0);
+ }
+ __merge_adaptive(__first, __middle, __last, _Distance(__middle - __first),
+ _Distance(__last - __middle), __buffer, __buffer_size);
+}
+
+template <class _RandomAccessIter, class _Pointer, class _Distance,
+ class _Compare>
+void __stable_sort_adaptive(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Pointer __buffer,
+ _Distance __buffer_size, _Compare __comp) {
+ _Distance __len = (__last - __first + 1) / 2;
+ _RandomAccessIter __middle = __first + __len;
+ if (__len > __buffer_size) {
+ __stable_sort_adaptive(__first, __middle, __buffer, __buffer_size,
+ __comp);
+ __stable_sort_adaptive(__middle, __last, __buffer, __buffer_size,
+ __comp);
+ }
+ else {
+ __merge_sort_with_buffer(__first, __middle, __buffer, (_Distance*)0,
+ __comp);
+ __merge_sort_with_buffer(__middle, __last, __buffer, (_Distance*)0,
+ __comp);
+ }
+ __merge_adaptive(__first, __middle, __last, _Distance(__middle - __first),
+ _Distance(__last - __middle), __buffer, __buffer_size,
+ __comp);
+}
+
+template <class _RandomAccessIter, class _Tp, class _Distance>
+inline void __stable_sort_aux(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Tp*, _Distance*) {
+ _Temporary_buffer<_RandomAccessIter, _Tp> buf(__first, __last);
+ if (buf.begin() == 0)
+ __inplace_stable_sort(__first, __last);
+ else
+ __stable_sort_adaptive(__first, __last, buf.begin(),
+ _Distance(buf.size()));
+}
+
+template <class _RandomAccessIter, class _Tp, class _Distance, class _Compare>
+inline void __stable_sort_aux(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Tp*, _Distance*,
+ _Compare __comp) {
+ _Temporary_buffer<_RandomAccessIter, _Tp> buf(__first, __last);
+ if (buf.begin() == 0)
+ __inplace_stable_sort(__first, __last, __comp);
+ else
+ __stable_sort_adaptive(__first, __last, buf.begin(),
+ _Distance(buf.size()),
+ __comp);
+}
+
+template <class _RandomAccessIter>
+inline void stable_sort(_RandomAccessIter __first,
+ _RandomAccessIter __last) {
+ __stable_sort_aux(__first, __last,
+ __VALUE_TYPE(__first),
+ __DISTANCE_TYPE(__first));
+}
+
+template <class _RandomAccessIter, class _Compare>
+inline void stable_sort(_RandomAccessIter __first,
+ _RandomAccessIter __last, _Compare __comp) {
+ __stable_sort_aux(__first, __last,
+ __VALUE_TYPE(__first),
+ __DISTANCE_TYPE(__first),
+ __comp);
+}
+
+// partial_sort, partial_sort_copy, and auxiliary functions.
+
+template <class _RandomAccessIter, class _Tp>
+void __partial_sort(_RandomAccessIter __first, _RandomAccessIter __middle,
+ _RandomAccessIter __last, _Tp*) {
+ make_heap(__first, __middle);
+ for (_RandomAccessIter __i = __middle; __i < __last; ++__i)
+ if (*__i < *__first)
+ __pop_heap(__first, __middle, __i, _Tp(*__i),
+ __DISTANCE_TYPE(__first));
+ sort_heap(__first, __middle);
+}
+
+template <class _RandomAccessIter>
+inline void partial_sort(_RandomAccessIter __first,
+ _RandomAccessIter __middle,
+ _RandomAccessIter __last) {
+ __partial_sort(__first, __middle, __last, __VALUE_TYPE(__first));
+}
+
+template <class _RandomAccessIter, class _Tp, class _Compare>
+void __partial_sort(_RandomAccessIter __first, _RandomAccessIter __middle,
+ _RandomAccessIter __last, _Tp*, _Compare __comp) {
+ make_heap(__first, __middle, __comp);
+ for (_RandomAccessIter __i = __middle; __i < __last; ++__i)
+ if (__comp(*__i, *__first))
+ __pop_heap(__first, __middle, __i, _Tp(*__i), __comp,
+ __DISTANCE_TYPE(__first));
+ sort_heap(__first, __middle, __comp);
+}
+
+template <class _RandomAccessIter, class _Compare>
+inline void partial_sort(_RandomAccessIter __first,
+ _RandomAccessIter __middle,
+ _RandomAccessIter __last, _Compare __comp) {
+ __partial_sort(__first, __middle, __last, __VALUE_TYPE(__first), __comp);
+}
+
+template <class _InputIter, class _RandomAccessIter, class _Distance,
+ class _Tp>
+_RandomAccessIter __partial_sort_copy(_InputIter __first,
+ _InputIter __last,
+ _RandomAccessIter __result_first,
+ _RandomAccessIter __result_last,
+ _Distance*, _Tp*) {
+ if (__result_first == __result_last) return __result_last;
+ _RandomAccessIter __result_real_last = __result_first;
+ while(__first != __last && __result_real_last != __result_last) {
+ *__result_real_last = *__first;
+ ++__result_real_last;
+ ++__first;
+ }
+ make_heap(__result_first, __result_real_last);
+ while (__first != __last) {
+ if (*__first < *__result_first)
+ __adjust_heap(__result_first, _Distance(0),
+ _Distance(__result_real_last - __result_first),
+ _Tp(*__first));
+ ++__first;
+ }
+ sort_heap(__result_first, __result_real_last);
+ return __result_real_last;
+}
+
+template <class _InputIter, class _RandomAccessIter>
+inline _RandomAccessIter
+partial_sort_copy(_InputIter __first, _InputIter __last,
+ _RandomAccessIter __result_first,
+ _RandomAccessIter __result_last) {
+ return __partial_sort_copy(__first, __last, __result_first, __result_last,
+ __DISTANCE_TYPE(__result_first),
+ __VALUE_TYPE(__first));
+}
+
+template <class _InputIter, class _RandomAccessIter, class _Compare,
+ class _Distance, class _Tp>
+_RandomAccessIter __partial_sort_copy(_InputIter __first,
+ _InputIter __last,
+ _RandomAccessIter __result_first,
+ _RandomAccessIter __result_last,
+ _Compare __comp, _Distance*, _Tp*) {
+ if (__result_first == __result_last) return __result_last;
+ _RandomAccessIter __result_real_last = __result_first;
+ while(__first != __last && __result_real_last != __result_last) {
+ *__result_real_last = *__first;
+ ++__result_real_last;
+ ++__first;
+ }
+ make_heap(__result_first, __result_real_last, __comp);
+ while (__first != __last) {
+ if (__comp(*__first, *__result_first))
+ __adjust_heap(__result_first, _Distance(0),
+ _Distance(__result_real_last - __result_first),
+ _Tp(*__first),
+ __comp);
+ ++__first;
+ }
+ sort_heap(__result_first, __result_real_last, __comp);
+ return __result_real_last;
+}
+
+template <class _InputIter, class _RandomAccessIter, class _Compare>
+inline _RandomAccessIter
+partial_sort_copy(_InputIter __first, _InputIter __last,
+ _RandomAccessIter __result_first,
+ _RandomAccessIter __result_last, _Compare __comp) {
+ return __partial_sort_copy(__first, __last, __result_first, __result_last,
+ __comp,
+ __DISTANCE_TYPE(__result_first),
+ __VALUE_TYPE(__first));
+}
+
+// nth_element() and its auxiliary functions.
+
+template <class _RandomAccessIter, class _Tp>
+void __nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
+ _RandomAccessIter __last, _Tp*) {
+ while (__last - __first > 3) {
+ _RandomAccessIter __cut =
+ __unguarded_partition(__first, __last,
+ _Tp(__median(*__first,
+ *(__first + (__last - __first)/2),
+ *(__last - 1))));
+ if (__cut <= __nth)
+ __first = __cut;
+ else
+ __last = __cut;
+ }
+ __insertion_sort(__first, __last);
+}
+
+template <class _RandomAccessIter>
+inline void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
+ _RandomAccessIter __last) {
+ __nth_element(__first, __nth, __last, __VALUE_TYPE(__first));
+}
+
+template <class _RandomAccessIter, class _Tp, class _Compare>
+void __nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
+ _RandomAccessIter __last, _Tp*, _Compare __comp) {
+ while (__last - __first > 3) {
+ _RandomAccessIter __cut =
+ __unguarded_partition(__first, __last,
+ _Tp(__median(*__first,
+ *(__first + (__last - __first)/2),
+ *(__last - 1),
+ __comp)),
+ __comp);
+ if (__cut <= __nth)
+ __first = __cut;
+ else
+ __last = __cut;
+ }
+ __insertion_sort(__first, __last, __comp);
+}
+
+template <class _RandomAccessIter, class _Compare>
+inline void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
+ _RandomAccessIter __last, _Compare __comp) {
+ __nth_element(__first, __nth, __last, __VALUE_TYPE(__first), __comp);
+}
+
+
+// Binary search (lower_bound, upper_bound, equal_range, binary_search).
+
+template <class _ForwardIter, class _Tp, class _Distance>
+_ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __val, _Distance*)
+{
+ _Distance __len = 0;
+ distance(__first, __last, __len);
+ _Distance __half;
+ _ForwardIter __middle;
+
+ while (__len > 0) {
+ __half = __len >> 1;
+ __middle = __first;
+ advance(__middle, __half);
+ if (*__middle < __val) {
+ __first = __middle;
+ ++__first;
+ __len = __len - __half - 1;
+ }
+ else
+ __len = __half;
+ }
+ return __first;
+}
+
+template <class _ForwardIter, class _Tp>
+inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __val) {
+ return __lower_bound(__first, __last, __val,
+ __DISTANCE_TYPE(__first));
+}
+
+template <class _ForwardIter, class _Tp, class _Compare, class _Distance>
+_ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __val, _Compare __comp, _Distance*)
+{
+ _Distance __len = 0;
+ distance(__first, __last, __len);
+ _Distance __half;
+ _ForwardIter __middle;
+
+ while (__len > 0) {
+ __half = __len >> 1;
+ __middle = __first;
+ advance(__middle, __half);
+ if (__comp(*__middle, __val)) {
+ __first = __middle;
+ ++__first;
+ __len = __len - __half - 1;
+ }
+ else
+ __len = __half;
+ }
+ return __first;
+}
+
+template <class _ForwardIter, class _Tp, class _Compare>
+inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __val, _Compare __comp) {
+ return __lower_bound(__first, __last, __val, __comp,
+ __DISTANCE_TYPE(__first));
+}
+
+template <class _ForwardIter, class _Tp, class _Distance>
+_ForwardIter __upper_bound(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __val, _Distance*)
+{
+ _Distance __len = 0;
+ distance(__first, __last, __len);
+ _Distance __half;
+ _ForwardIter __middle;
+
+ while (__len > 0) {
+ __half = __len >> 1;
+ __middle = __first;
+ advance(__middle, __half);
+ if (__val < *__middle)
+ __len = __half;
+ else {
+ __first = __middle;
+ ++__first;
+ __len = __len - __half - 1;
+ }
+ }
+ return __first;
+}
+
+template <class _ForwardIter, class _Tp>
+inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __val) {
+ return __upper_bound(__first, __last, __val,
+ __DISTANCE_TYPE(__first));
+}
+
+template <class _ForwardIter, class _Tp, class _Compare, class _Distance>
+_ForwardIter __upper_bound(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __val, _Compare __comp, _Distance*)
+{
+ _Distance __len = 0;
+ distance(__first, __last, __len);
+ _Distance __half;
+ _ForwardIter __middle;
+
+ while (__len > 0) {
+ __half = __len >> 1;
+ __middle = __first;
+ advance(__middle, __half);
+ if (__comp(__val, *__middle))
+ __len = __half;
+ else {
+ __first = __middle;
+ ++__first;
+ __len = __len - __half - 1;
+ }
+ }
+ return __first;
+}
+
+template <class _ForwardIter, class _Tp, class _Compare>
+inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __val, _Compare __comp) {
+ return __upper_bound(__first, __last, __val, __comp,
+ __DISTANCE_TYPE(__first));
+}
+
+template <class _ForwardIter, class _Tp, class _Distance>
+pair<_ForwardIter, _ForwardIter>
+__equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
+ _Distance*)
+{
+ _Distance __len = 0;
+ distance(__first, __last, __len);
+ _Distance __half;
+ _ForwardIter __middle, __left, __right;
+
+ while (__len > 0) {
+ __half = __len >> 1;
+ __middle = __first;
+ advance(__middle, __half);
+ if (*__middle < __val) {
+ __first = __middle;
+ ++__first;
+ __len = __len - __half - 1;
+ }
+ else if (__val < *__middle)
+ __len = __half;
+ else {
+ __left = lower_bound(__first, __middle, __val);
+ advance(__first, __len);
+ __right = upper_bound(++__middle, __first, __val);
+ return pair<_ForwardIter, _ForwardIter>(__left, __right);
+ }
+ }
+ return pair<_ForwardIter, _ForwardIter>(__first, __first);
+}
+
+template <class _ForwardIter, class _Tp>
+inline pair<_ForwardIter, _ForwardIter>
+equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
+ return __equal_range(__first, __last, __val,
+ __DISTANCE_TYPE(__first));
+}
+
+template <class _ForwardIter, class _Tp, class _Compare, class _Distance>
+pair<_ForwardIter, _ForwardIter>
+__equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
+ _Compare __comp, _Distance*)
+{
+ _Distance __len = 0;
+ distance(__first, __last, __len);
+ _Distance __half;
+ _ForwardIter __middle, __left, __right;
+
+ while (__len > 0) {
+ __half = __len >> 1;
+ __middle = __first;
+ advance(__middle, __half);
+ if (__comp(*__middle, __val)) {
+ __first = __middle;
+ ++__first;
+ __len = __len - __half - 1;
+ }
+ else if (__comp(__val, *__middle))
+ __len = __half;
+ else {
+ __left = lower_bound(__first, __middle, __val, __comp);
+ advance(__first, __len);
+ __right = upper_bound(++__middle, __first, __val, __comp);
+ return pair<_ForwardIter, _ForwardIter>(__left, __right);
+ }
+ }
+ return pair<_ForwardIter, _ForwardIter>(__first, __first);
+}
+
+template <class _ForwardIter, class _Tp, class _Compare>
+inline pair<_ForwardIter, _ForwardIter>
+equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
+ _Compare __comp) {
+ return __equal_range(__first, __last, __val, __comp,
+ __DISTANCE_TYPE(__first));
+}
+
+template <class _ForwardIter, class _Tp>
+bool binary_search(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __val) {
+ _ForwardIter __i = lower_bound(__first, __last, __val);
+ return __i != __last && !(__val < *__i);
+}
+
+template <class _ForwardIter, class _Tp, class _Compare>
+bool binary_search(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __val,
+ _Compare __comp) {
+ _ForwardIter __i = lower_bound(__first, __last, __val, __comp);
+ return __i != __last && !__comp(__val, *__i);
+}
+
+// merge, with and without an explicitly supplied comparison function.
+
+template <class _InputIter1, class _InputIter2, class _OutputIter>
+_OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _OutputIter __result) {
+ while (__first1 != __last1 && __first2 != __last2) {
+ if (*__first2 < *__first1) {
+ *__result = *__first2;
+ ++__first2;
+ }
+ else {
+ *__result = *__first1;
+ ++__first1;
+ }
+ ++__result;
+ }
+ return copy(__first2, __last2, copy(__first1, __last1, __result));
+}
+
+template <class _InputIter1, class _InputIter2, class _OutputIter,
+ class _Compare>
+_OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _OutputIter __result, _Compare __comp) {
+ while (__first1 != __last1 && __first2 != __last2) {
+ if (__comp(*__first2, *__first1)) {
+ *__result = *__first2;
+ ++__first2;
+ }
+ else {
+ *__result = *__first1;
+ ++__first1;
+ }
+ ++__result;
+ }
+ return copy(__first2, __last2, copy(__first1, __last1, __result));
+}
+
+// inplace_merge and its auxiliary functions.
+
+template <class _BidirectionalIter, class _Distance>
+void __merge_without_buffer(_BidirectionalIter __first,
+ _BidirectionalIter __middle,
+ _BidirectionalIter __last,
+ _Distance __len1, _Distance __len2) {
+ if (__len1 == 0 || __len2 == 0)
+ return;
+ if (__len1 + __len2 == 2) {
+ if (*__middle < *__first)
+ iter_swap(__first, __middle);
+ return;
+ }
+ _BidirectionalIter __first_cut = __first;
+ _BidirectionalIter __second_cut = __middle;
+ _Distance __len11 = 0;
+ _Distance __len22 = 0;
+ if (__len1 > __len2) {
+ __len11 = __len1 / 2;
+ advance(__first_cut, __len11);
+ __second_cut = lower_bound(__middle, __last, *__first_cut);
+ distance(__middle, __second_cut, __len22);
+ }
+ else {
+ __len22 = __len2 / 2;
+ advance(__second_cut, __len22);
+ __first_cut = upper_bound(__first, __middle, *__second_cut);
+ distance(__first, __first_cut, __len11);
+ }
+ _BidirectionalIter __new_middle
+ = rotate(__first_cut, __middle, __second_cut);
+ __merge_without_buffer(__first, __first_cut, __new_middle,
+ __len11, __len22);
+ __merge_without_buffer(__new_middle, __second_cut, __last, __len1 - __len11,
+ __len2 - __len22);
+}
+
+template <class _BidirectionalIter, class _Distance, class _Compare>
+void __merge_without_buffer(_BidirectionalIter __first,
+ _BidirectionalIter __middle,
+ _BidirectionalIter __last,
+ _Distance __len1, _Distance __len2,
+ _Compare __comp) {
+ if (__len1 == 0 || __len2 == 0)
+ return;
+ if (__len1 + __len2 == 2) {
+ if (__comp(*__middle, *__first))
+ iter_swap(__first, __middle);
+ return;
+ }
+ _BidirectionalIter __first_cut = __first;
+ _BidirectionalIter __second_cut = __middle;
+ _Distance __len11 = 0;
+ _Distance __len22 = 0;
+ if (__len1 > __len2) {
+ __len11 = __len1 / 2;
+ advance(__first_cut, __len11);
+ __second_cut = lower_bound(__middle, __last, *__first_cut, __comp);
+ distance(__middle, __second_cut, __len22);
+ }
+ else {
+ __len22 = __len2 / 2;
+ advance(__second_cut, __len22);
+ __first_cut = upper_bound(__first, __middle, *__second_cut, __comp);
+ distance(__first, __first_cut, __len11);
+ }
+ _BidirectionalIter __new_middle
+ = rotate(__first_cut, __middle, __second_cut);
+ __merge_without_buffer(__first, __first_cut, __new_middle, __len11, __len22,
+ __comp);
+ __merge_without_buffer(__new_middle, __second_cut, __last, __len1 - __len11,
+ __len2 - __len22, __comp);
+}
+
+template <class _BidirectionalIter1, class _BidirectionalIter2,
+ class _Distance>
+_BidirectionalIter1 __rotate_adaptive(_BidirectionalIter1 __first,
+ _BidirectionalIter1 __middle,
+ _BidirectionalIter1 __last,
+ _Distance __len1, _Distance __len2,
+ _BidirectionalIter2 __buffer,
+ _Distance __buffer_size) {
+ _BidirectionalIter2 __buffer_end;
+ if (__len1 > __len2 && __len2 <= __buffer_size) {
+ __buffer_end = copy(__middle, __last, __buffer);
+ copy_backward(__first, __middle, __last);
+ return copy(__buffer, __buffer_end, __first);
+ }
+ else if (__len1 <= __buffer_size) {
+ __buffer_end = copy(__first, __middle, __buffer);
+ copy(__middle, __last, __first);
+ return copy_backward(__buffer, __buffer_end, __last);
+ }
+ else
+ return rotate(__first, __middle, __last);
+}
+
+template <class _BidirectionalIter1, class _BidirectionalIter2,
+ class _BidirectionalIter3>
+_BidirectionalIter3 __merge_backward(_BidirectionalIter1 __first1,
+ _BidirectionalIter1 __last1,
+ _BidirectionalIter2 __first2,
+ _BidirectionalIter2 __last2,
+ _BidirectionalIter3 __result) {
+ if (__first1 == __last1)
+ return copy_backward(__first2, __last2, __result);
+ if (__first2 == __last2)
+ return copy_backward(__first1, __last1, __result);
+ --__last1;
+ --__last2;
+ while (true) {
+ if (*__last2 < *__last1) {
+ *--__result = *__last1;
+ if (__first1 == __last1)
+ return copy_backward(__first2, ++__last2, __result);
+ --__last1;
+ }
+ else {
+ *--__result = *__last2;
+ if (__first2 == __last2)
+ return copy_backward(__first1, ++__last1, __result);
+ --__last2;
+ }
+ }
+}
+
+template <class _BidirectionalIter1, class _BidirectionalIter2,
+ class _BidirectionalIter3, class _Compare>
+_BidirectionalIter3 __merge_backward(_BidirectionalIter1 __first1,
+ _BidirectionalIter1 __last1,
+ _BidirectionalIter2 __first2,
+ _BidirectionalIter2 __last2,
+ _BidirectionalIter3 __result,
+ _Compare __comp) {
+ if (__first1 == __last1)
+ return copy_backward(__first2, __last2, __result);
+ if (__first2 == __last2)
+ return copy_backward(__first1, __last1, __result);
+ --__last1;
+ --__last2;
+ while (true) {
+ if (__comp(*__last2, *__last1)) {
+ *--__result = *__last1;
+ if (__first1 == __last1)
+ return copy_backward(__first2, ++__last2, __result);
+ --__last1;
+ }
+ else {
+ *--__result = *__last2;
+ if (__first2 == __last2)
+ return copy_backward(__first1, ++__last1, __result);
+ --__last2;
+ }
+ }
+}
+
+template <class _BidirectionalIter, class _Distance, class _Pointer>
+void __merge_adaptive(_BidirectionalIter __first,
+ _BidirectionalIter __middle,
+ _BidirectionalIter __last,
+ _Distance __len1, _Distance __len2,
+ _Pointer __buffer, _Distance __buffer_size) {
+ if (__len1 <= __len2 && __len1 <= __buffer_size) {
+ _Pointer __buffer_end = copy(__first, __middle, __buffer);
+ merge(__buffer, __buffer_end, __middle, __last, __first);
+ }
+ else if (__len2 <= __buffer_size) {
+ _Pointer __buffer_end = copy(__middle, __last, __buffer);
+ __merge_backward(__first, __middle, __buffer, __buffer_end, __last);
+ }
+ else {
+ _BidirectionalIter __first_cut = __first;
+ _BidirectionalIter __second_cut = __middle;
+ _Distance __len11 = 0;
+ _Distance __len22 = 0;
+ if (__len1 > __len2) {
+ __len11 = __len1 / 2;
+ advance(__first_cut, __len11);
+ __second_cut = lower_bound(__middle, __last, *__first_cut);
+ distance(__middle, __second_cut, __len22);
+ }
+ else {
+ __len22 = __len2 / 2;
+ advance(__second_cut, __len22);
+ __first_cut = upper_bound(__first, __middle, *__second_cut);
+ distance(__first, __first_cut, __len11);
+ }
+ _BidirectionalIter __new_middle =
+ __rotate_adaptive(__first_cut, __middle, __second_cut, __len1 - __len11,
+ __len22, __buffer, __buffer_size);
+ __merge_adaptive(__first, __first_cut, __new_middle, __len11,
+ __len22, __buffer, __buffer_size);
+ __merge_adaptive(__new_middle, __second_cut, __last, __len1 - __len11,
+ __len2 - __len22, __buffer, __buffer_size);
+ }
+}
+
+template <class _BidirectionalIter, class _Distance, class _Pointer,
+ class _Compare>
+void __merge_adaptive(_BidirectionalIter __first,
+ _BidirectionalIter __middle,
+ _BidirectionalIter __last,
+ _Distance __len1, _Distance __len2,
+ _Pointer __buffer, _Distance __buffer_size,
+ _Compare __comp) {
+ if (__len1 <= __len2 && __len1 <= __buffer_size) {
+ _Pointer __buffer_end = copy(__first, __middle, __buffer);
+ merge(__buffer, __buffer_end, __middle, __last, __first, __comp);
+ }
+ else if (__len2 <= __buffer_size) {
+ _Pointer __buffer_end = copy(__middle, __last, __buffer);
+ __merge_backward(__first, __middle, __buffer, __buffer_end, __last,
+ __comp);
+ }
+ else {
+ _BidirectionalIter __first_cut = __first;
+ _BidirectionalIter __second_cut = __middle;
+ _Distance __len11 = 0;
+ _Distance __len22 = 0;
+ if (__len1 > __len2) {
+ __len11 = __len1 / 2;
+ advance(__first_cut, __len11);
+ __second_cut = lower_bound(__middle, __last, *__first_cut, __comp);
+ distance(__middle, __second_cut, __len22);
+ }
+ else {
+ __len22 = __len2 / 2;
+ advance(__second_cut, __len22);
+ __first_cut = upper_bound(__first, __middle, *__second_cut, __comp);
+ distance(__first, __first_cut, __len11);
+ }
+ _BidirectionalIter __new_middle =
+ __rotate_adaptive(__first_cut, __middle, __second_cut, __len1 - __len11,
+ __len22, __buffer, __buffer_size);
+ __merge_adaptive(__first, __first_cut, __new_middle, __len11,
+ __len22, __buffer, __buffer_size, __comp);
+ __merge_adaptive(__new_middle, __second_cut, __last, __len1 - __len11,
+ __len2 - __len22, __buffer, __buffer_size, __comp);
+ }
+}
+
+template <class _BidirectionalIter, class _Tp, class _Distance>
+inline void __inplace_merge_aux(_BidirectionalIter __first,
+ _BidirectionalIter __middle,
+ _BidirectionalIter __last, _Tp*, _Distance*) {
+ _Distance __len1 = 0;
+ distance(__first, __middle, __len1);
+ _Distance __len2 = 0;
+ distance(__middle, __last, __len2);
+
+ _Temporary_buffer<_BidirectionalIter, _Tp> __buf(__first, __last);
+ if (__buf.begin() == 0)
+ __merge_without_buffer(__first, __middle, __last, __len1, __len2);
+ else
+ __merge_adaptive(__first, __middle, __last, __len1, __len2,
+ __buf.begin(), _Distance(__buf.size()));
+}
+
+template <class _BidirectionalIter, class _Tp,
+ class _Distance, class _Compare>
+inline void __inplace_merge_aux(_BidirectionalIter __first,
+ _BidirectionalIter __middle,
+ _BidirectionalIter __last, _Tp*, _Distance*,
+ _Compare __comp) {
+ _Distance __len1 = 0;
+ distance(__first, __middle, __len1);
+ _Distance __len2 = 0;
+ distance(__middle, __last, __len2);
+
+ _Temporary_buffer<_BidirectionalIter, _Tp> __buf(__first, __last);
+ if (__buf.begin() == 0)
+ __merge_without_buffer(__first, __middle, __last, __len1, __len2, __comp);
+ else
+ __merge_adaptive(__first, __middle, __last, __len1, __len2,
+ __buf.begin(), _Distance(__buf.size()),
+ __comp);
+}
+
+template <class _BidirectionalIter>
+inline void inplace_merge(_BidirectionalIter __first,
+ _BidirectionalIter __middle,
+ _BidirectionalIter __last) {
+ if (__first == __middle || __middle == __last)
+ return;
+ __inplace_merge_aux(__first, __middle, __last,
+ __VALUE_TYPE(__first), __DISTANCE_TYPE(__first));
+}
+
+template <class _BidirectionalIter, class _Compare>
+inline void inplace_merge(_BidirectionalIter __first,
+ _BidirectionalIter __middle,
+ _BidirectionalIter __last, _Compare __comp) {
+ if (__first == __middle || __middle == __last)
+ return;
+ __inplace_merge_aux(__first, __middle, __last,
+ __VALUE_TYPE(__first), __DISTANCE_TYPE(__first),
+ __comp);
+}
+
+// Set algorithms: includes, set_union, set_intersection, set_difference,
+// set_symmetric_difference. All of these algorithms have the precondition
+// that their input ranges are sorted and the postcondition that their output
+// ranges are sorted.
+
+template <class _InputIter1, class _InputIter2>
+bool includes(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2) {
+ while (__first1 != __last1 && __first2 != __last2)
+ if (*__first2 < *__first1)
+ return false;
+ else if(*__first1 < *__first2)
+ ++__first1;
+ else
+ ++__first1, ++__first2;
+
+ return __first2 == __last2;
+}
+
+template <class _InputIter1, class _InputIter2, class _Compare>
+bool includes(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2, _Compare __comp) {
+ while (__first1 != __last1 && __first2 != __last2)
+ if (__comp(*__first2, *__first1))
+ return false;
+ else if(__comp(*__first1, *__first2))
+ ++__first1;
+ else
+ ++__first1, ++__first2;
+
+ return __first2 == __last2;
+}
+
+template <class _InputIter1, class _InputIter2, class _OutputIter>
+_OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _OutputIter __result) {
+ while (__first1 != __last1 && __first2 != __last2) {
+ if (*__first1 < *__first2) {
+ *__result = *__first1;
+ ++__first1;
+ }
+ else if (*__first2 < *__first1) {
+ *__result = *__first2;
+ ++__first2;
+ }
+ else {
+ *__result = *__first1;
+ ++__first1;
+ ++__first2;
+ }
+ ++__result;
+ }
+ return copy(__first2, __last2, copy(__first1, __last1, __result));
+}
+
+template <class _InputIter1, class _InputIter2, class _OutputIter,
+ class _Compare>
+_OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _OutputIter __result, _Compare __comp) {
+ while (__first1 != __last1 && __first2 != __last2) {
+ if (__comp(*__first1, *__first2)) {
+ *__result = *__first1;
+ ++__first1;
+ }
+ else if (__comp(*__first2, *__first1)) {
+ *__result = *__first2;
+ ++__first2;
+ }
+ else {
+ *__result = *__first1;
+ ++__first1;
+ ++__first2;
+ }
+ ++__result;
+ }
+ return copy(__first2, __last2, copy(__first1, __last1, __result));
+}
+
+template <class _InputIter1, class _InputIter2, class _OutputIter>
+_OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _OutputIter __result) {
+ while (__first1 != __last1 && __first2 != __last2)
+ if (*__first1 < *__first2)
+ ++__first1;
+ else if (*__first2 < *__first1)
+ ++__first2;
+ else {
+ *__result = *__first1;
+ ++__first1;
+ ++__first2;
+ ++__result;
+ }
+ return __result;
+}
+
+template <class _InputIter1, class _InputIter2, class _OutputIter,
+ class _Compare>
+_OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _OutputIter __result, _Compare __comp) {
+ while (__first1 != __last1 && __first2 != __last2)
+ if (__comp(*__first1, *__first2))
+ ++__first1;
+ else if (__comp(*__first2, *__first1))
+ ++__first2;
+ else {
+ *__result = *__first1;
+ ++__first1;
+ ++__first2;
+ ++__result;
+ }
+ return __result;
+}
+
+template <class _InputIter1, class _InputIter2, class _OutputIter>
+_OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _OutputIter __result) {
+ while (__first1 != __last1 && __first2 != __last2)
+ if (*__first1 < *__first2) {
+ *__result = *__first1;
+ ++__first1;
+ ++__result;
+ }
+ else if (*__first2 < *__first1)
+ ++__first2;
+ else {
+ ++__first1;
+ ++__first2;
+ }
+ return copy(__first1, __last1, __result);
+}
+
+template <class _InputIter1, class _InputIter2, class _OutputIter,
+ class _Compare>
+_OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _OutputIter __result, _Compare __comp) {
+ while (__first1 != __last1 && __first2 != __last2)
+ if (__comp(*__first1, *__first2)) {
+ *__result = *__first1;
+ ++__first1;
+ ++__result;
+ }
+ else if (__comp(*__first2, *__first1))
+ ++__first2;
+ else {
+ ++__first1;
+ ++__first2;
+ }
+ return copy(__first1, __last1, __result);
+}
+
+template <class _InputIter1, class _InputIter2, class _OutputIter>
+_OutputIter
+set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _OutputIter __result) {
+ while (__first1 != __last1 && __first2 != __last2)
+ if (*__first1 < *__first2) {
+ *__result = *__first1;
+ ++__first1;
+ ++__result;
+ }
+ else if (*__first2 < *__first1) {
+ *__result = *__first2;
+ ++__first2;
+ ++__result;
+ }
+ else {
+ ++__first1;
+ ++__first2;
+ }
+ return copy(__first2, __last2, copy(__first1, __last1, __result));
+}
+
+template <class _InputIter1, class _InputIter2, class _OutputIter,
+ class _Compare>
+_OutputIter
+set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _OutputIter __result,
+ _Compare __comp) {
+ while (__first1 != __last1 && __first2 != __last2)
+ if (__comp(*__first1, *__first2)) {
+ *__result = *__first1;
+ ++__first1;
+ ++__result;
+ }
+ else if (__comp(*__first2, *__first1)) {
+ *__result = *__first2;
+ ++__first2;
+ ++__result;
+ }
+ else {
+ ++__first1;
+ ++__first2;
+ }
+ return copy(__first2, __last2, copy(__first1, __last1, __result));
+}
+
+// min_element and max_element, with and without an explicitly supplied
+// comparison function.
+
+template <class _ForwardIter>
+_ForwardIter max_element(_ForwardIter __first, _ForwardIter __last) {
+ if (__first == __last) return __first;
+ _ForwardIter __result = __first;
+ while (++__first != __last)
+ if (*__result < *__first)
+ __result = __first;
+ return __result;
+}
+
+template <class _ForwardIter, class _Compare>
+_ForwardIter max_element(_ForwardIter __first, _ForwardIter __last,
+ _Compare __comp) {
+ if (__first == __last) return __first;
+ _ForwardIter __result = __first;
+ while (++__first != __last)
+ if (__comp(*__result, *__first)) __result = __first;
+ return __result;
+}
+
+template <class _ForwardIter>
+_ForwardIter min_element(_ForwardIter __first, _ForwardIter __last) {
+ if (__first == __last) return __first;
+ _ForwardIter __result = __first;
+ while (++__first != __last)
+ if (*__first < *__result)
+ __result = __first;
+ return __result;
+}
+
+template <class _ForwardIter, class _Compare>
+_ForwardIter min_element(_ForwardIter __first, _ForwardIter __last,
+ _Compare __comp) {
+ if (__first == __last) return __first;
+ _ForwardIter __result = __first;
+ while (++__first != __last)
+ if (__comp(*__first, *__result))
+ __result = __first;
+ return __result;
+}
+
+// next_permutation and prev_permutation, with and without an explicitly
+// supplied comparison function.
+
+template <class _BidirectionalIter>
+bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last) {
+ if (__first == __last)
+ return false;
+ _BidirectionalIter __i = __first;
+ ++__i;
+ if (__i == __last)
+ return false;
+ __i = __last;
+ --__i;
+
+ for(;;) {
+ _BidirectionalIter __ii = __i;
+ --__i;
+ if (*__i < *__ii) {
+ _BidirectionalIter __j = __last;
+ while (!(*__i < *--__j))
+ {}
+ iter_swap(__i, __j);
+ reverse(__ii, __last);
+ return true;
+ }
+ if (__i == __first) {
+ reverse(__first, __last);
+ return false;
+ }
+ }
+}
+
+template <class _BidirectionalIter, class _Compare>
+bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
+ _Compare __comp) {
+ if (__first == __last)
+ return false;
+ _BidirectionalIter __i = __first;
+ ++__i;
+ if (__i == __last)
+ return false;
+ __i = __last;
+ --__i;
+
+ for(;;) {
+ _BidirectionalIter __ii = __i;
+ --__i;
+ if (__comp(*__i, *__ii)) {
+ _BidirectionalIter __j = __last;
+ while (!__comp(*__i, *--__j))
+ {}
+ iter_swap(__i, __j);
+ reverse(__ii, __last);
+ return true;
+ }
+ if (__i == __first) {
+ reverse(__first, __last);
+ return false;
+ }
+ }
+}
+
+template <class _BidirectionalIter>
+bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last) {
+ if (__first == __last)
+ return false;
+ _BidirectionalIter __i = __first;
+ ++__i;
+ if (__i == __last)
+ return false;
+ __i = __last;
+ --__i;
+
+ for(;;) {
+ _BidirectionalIter __ii = __i;
+ --__i;
+ if (*__ii < *__i) {
+ _BidirectionalIter __j = __last;
+ while (!(*--__j < *__i))
+ {}
+ iter_swap(__i, __j);
+ reverse(__ii, __last);
+ return true;
+ }
+ if (__i == __first) {
+ reverse(__first, __last);
+ return false;
+ }
+ }
+}
+
+template <class _BidirectionalIter, class _Compare>
+bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
+ _Compare __comp) {
+ if (__first == __last)
+ return false;
+ _BidirectionalIter __i = __first;
+ ++__i;
+ if (__i == __last)
+ return false;
+ __i = __last;
+ --__i;
+
+ for(;;) {
+ _BidirectionalIter __ii = __i;
+ --__i;
+ if (__comp(*__ii, *__i)) {
+ _BidirectionalIter __j = __last;
+ while (!__comp(*--__j, *__i))
+ {}
+ iter_swap(__i, __j);
+ reverse(__ii, __last);
+ return true;
+ }
+ if (__i == __first) {
+ reverse(__first, __last);
+ return false;
+ }
+ }
+}
+
+// find_first_of, with and without an explicitly supplied comparison function.
+
+template <class _InputIter, class _ForwardIter>
+_InputIter find_first_of(_InputIter __first1, _InputIter __last1,
+ _ForwardIter __first2, _ForwardIter __last2)
+{
+ for ( ; __first1 != __last1; ++__first1)
+ for (_ForwardIter __iter = __first2; __iter != __last2; ++__iter)
+ if (*__first1 == *__iter)
+ return __first1;
+ return __last1;
+}
+
+template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
+_InputIter find_first_of(_InputIter __first1, _InputIter __last1,
+ _ForwardIter __first2, _ForwardIter __last2,
+ _BinaryPredicate __comp)
+{
+ for ( ; __first1 != __last1; ++__first1)
+ for (_ForwardIter __iter = __first2; __iter != __last2; ++__iter)
+ if (__comp(*__first1, *__iter))
+ return __first1;
+ return __last1;
+}
+
+
+// find_end, with and without an explicitly supplied comparison function.
+// Search [first2, last2) as a subsequence in [first1, last1), and return
+// the *last* possible match. Note that find_end for bidirectional iterators
+// is much faster than for forward iterators.
+
+// find_end for forward iterators.
+template <class _ForwardIter1, class _ForwardIter2>
+_ForwardIter1 __find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
+ _ForwardIter2 __first2, _ForwardIter2 __last2,
+ forward_iterator_tag, forward_iterator_tag)
+{
+ if (__first2 == __last2)
+ return __last1;
+ else {
+ _ForwardIter1 __result = __last1;
+ while (1) {
+ _ForwardIter1 __new_result
+ = search(__first1, __last1, __first2, __last2);
+ if (__new_result == __last1)
+ return __result;
+ else {
+ __result = __new_result;
+ __first1 = __new_result;
+ ++__first1;
+ }
+ }
+ }
+}
+
+template <class _ForwardIter1, class _ForwardIter2,
+ class _BinaryPredicate>
+_ForwardIter1 __find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
+ _ForwardIter2 __first2, _ForwardIter2 __last2,
+ forward_iterator_tag, forward_iterator_tag,
+ _BinaryPredicate __comp)
+{
+ if (__first2 == __last2)
+ return __last1;
+ else {
+ _ForwardIter1 __result = __last1;
+ while (1) {
+ _ForwardIter1 __new_result
+ = search(__first1, __last1, __first2, __last2, __comp);
+ if (__new_result == __last1)
+ return __result;
+ else {
+ __result = __new_result;
+ __first1 = __new_result;
+ ++__first1;
+ }
+ }
+ }
+}
+
+// find_end for bidirectional iterators. Requires partial specialization.
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _BidirectionalIter1, class _BidirectionalIter2>
+_BidirectionalIter1
+__find_end(_BidirectionalIter1 __first1, _BidirectionalIter1 __last1,
+ _BidirectionalIter2 __first2, _BidirectionalIter2 __last2,
+ bidirectional_iterator_tag, bidirectional_iterator_tag)
+{
+ typedef reverse_iterator<_BidirectionalIter1> _RevIter1;
+ typedef reverse_iterator<_BidirectionalIter2> _RevIter2;
+
+ _RevIter1 __rlast1(__first1);
+ _RevIter2 __rlast2(__first2);
+ _RevIter1 __rresult = search(_RevIter1(__last1), __rlast1,
+ _RevIter2(__last2), __rlast2);
+
+ if (__rresult == __rlast1)
+ return __last1;
+ else {
+ _BidirectionalIter1 __result = __rresult.base();
+ advance(__result, -distance(__first2, __last2));
+ return __result;
+ }
+}
+
+template <class _BidirectionalIter1, class _BidirectionalIter2,
+ class _BinaryPredicate>
+_BidirectionalIter1
+__find_end(_BidirectionalIter1 __first1, _BidirectionalIter1 __last1,
+ _BidirectionalIter2 __first2, _BidirectionalIter2 __last2,
+ bidirectional_iterator_tag, bidirectional_iterator_tag,
+ _BinaryPredicate __comp)
+{
+ typedef reverse_iterator<_BidirectionalIter1> _RevIter1;
+ typedef reverse_iterator<_BidirectionalIter2> _RevIter2;
+
+ _RevIter1 __rlast1(__first1);
+ _RevIter2 __rlast2(__first2);
+ _RevIter1 __rresult = search(_RevIter1(__last1), __rlast1,
+ _RevIter2(__last2), __rlast2,
+ __comp);
+
+ if (__rresult == __rlast1)
+ return __last1;
+ else {
+ _BidirectionalIter1 __result = __rresult.base();
+ advance(__result, -distance(__first2, __last2));
+ return __result;
+ }
+}
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+// Dispatching functions for find_end.
+
+template <class _ForwardIter1, class _ForwardIter2>
+inline _ForwardIter1
+find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
+ _ForwardIter2 __first2, _ForwardIter2 __last2)
+{
+ return __find_end(__first1, __last1, __first2, __last2,
+ __ITERATOR_CATEGORY(__first1),
+ __ITERATOR_CATEGORY(__first2));
+}
+
+template <class _ForwardIter1, class _ForwardIter2,
+ class _BinaryPredicate>
+inline _ForwardIter1
+find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
+ _ForwardIter2 __first2, _ForwardIter2 __last2,
+ _BinaryPredicate __comp)
+{
+ return __find_end(__first1, __last1, __first2, __last2,
+ __ITERATOR_CATEGORY(__first1),
+ __ITERATOR_CATEGORY(__first2),
+ __comp);
+}
+
+// is_heap, a predicate testing whether or not a range is
+// a heap. This function is an extension, not part of the C++
+// standard.
+
+template <class _RandomAccessIter, class _Distance>
+bool __is_heap(_RandomAccessIter __first, _Distance __n)
+{
+ _Distance __parent = 0;
+ for (_Distance __child = 1; __child < __n; ++__child) {
+ if (__first[__parent] < __first[__child])
+ return false;
+ if ((__child & 1) == 0)
+ ++__parent;
+ }
+ return true;
+}
+
+template <class _RandomAccessIter, class _Distance, class _StrictWeakOrdering>
+bool __is_heap(_RandomAccessIter __first, _StrictWeakOrdering __comp,
+ _Distance __n)
+{
+ _Distance __parent = 0;
+ for (_Distance __child = 1; __child < __n; ++__child) {
+ if (__comp(__first[__parent], __first[__child]))
+ return false;
+ if ((__child & 1) == 0)
+ ++__parent;
+ }
+ return true;
+}
+
+template <class _RandomAccessIter>
+inline bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last)
+{
+ return __is_heap(__first, __last - __first);
+}
+
+
+template <class _RandomAccessIter, class _StrictWeakOrdering>
+inline bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last,
+ _StrictWeakOrdering __comp)
+{
+ return __is_heap(__first, __comp, __last - __first);
+}
+
+// is_sorted, a predicated testing whether a range is sorted in
+// nondescending order. This is an extension, not part of the C++
+// standard.
+
+template <class _ForwardIter>
+bool is_sorted(_ForwardIter __first, _ForwardIter __last)
+{
+ if (__first == __last)
+ return true;
+
+ _ForwardIter __next = __first;
+ for (++__next; __next != __last; __first = __next, ++__next) {
+ if (*__next < *__first)
+ return false;
+ }
+
+ return true;
+}
+
+template <class _ForwardIter, class _StrictWeakOrdering>
+bool is_sorted(_ForwardIter __first, _ForwardIter __last,
+ _StrictWeakOrdering __comp)
+{
+ if (__first == __last)
+ return true;
+
+ _ForwardIter __next = __first;
+ for (++__next; __next != __last; __first = __next, ++__next) {
+ if (__comp(*__next, *__first))
+ return false;
+ }
+
+ return true;
+}
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1209
+#endif
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_ALGO_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_algobase.h b/libstdc++-v3/bits/stl_algobase.h
new file mode 100644
index 0000000..b1bbd57
--- /dev/null
+++ b/libstdc++-v3/bits/stl_algobase.h
@@ -0,0 +1,652 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996-1998
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+
+#ifndef __SGI_STL_INTERNAL_ALGOBASE_H
+#define __SGI_STL_INTERNAL_ALGOBASE_H
+
+#include <bits/stl_config.h>
+#include <bits/stl_relops.h>
+#include <bits/stl_pair.h>
+#include <bits/type_traits.h>
+
+#include <bits/std_cstring.h>
+#include <bits/std_climits.h>
+#include <bits/std_cstdlib.h>
+#include <bits/std_cstddef.h>
+#include <bits/std_new.h>
+
+#ifdef __STL_USE_NEW_IOSTREAMS
+#include <iosfwd>
+#else /* __STL_USE_NEW_IOSTREAMS */
+#include <bits/std_iosfwd.h>
+#endif /* __STL_USE_NEW_IOSTREAMS */
+
+#include <bits/stl_iterator_base.h>
+#include <bits/stl_iterator.h>
+
+__STL_BEGIN_NAMESPACE
+
+// swap and iter_swap
+
+template <class _ForwardIter1, class _ForwardIter2, class _Tp>
+inline void __iter_swap(_ForwardIter1 __a, _ForwardIter2 __b, _Tp*) {
+ _Tp __tmp = *__a;
+ *__a = *__b;
+ *__b = __tmp;
+}
+
+template <class _ForwardIter1, class _ForwardIter2>
+inline void iter_swap(_ForwardIter1 __a, _ForwardIter2 __b) {
+ __iter_swap(__a, __b, __VALUE_TYPE(__a));
+}
+
+template <class _Tp>
+inline void swap(_Tp& __a, _Tp& __b) {
+ _Tp __tmp = __a;
+ __a = __b;
+ __b = __tmp;
+}
+
+//--------------------------------------------------
+// min and max
+
+#ifndef __BORLANDC__
+
+#undef min
+#undef max
+
+template <class _Tp>
+inline const _Tp& min(const _Tp& __a, const _Tp& __b) {
+ //return __b < __a ? __b : __a;
+ if (__b < __a) return __b; return __a;
+}
+
+template <class _Tp>
+inline const _Tp& max(const _Tp& __a, const _Tp& __b) {
+ //return __a < __b ? __b : __a;
+ if (__a < __b) return __b; return __a;
+}
+
+#endif /* __BORLANDC__ */
+
+template <class _Tp, class _Compare>
+inline const _Tp& min(const _Tp& __a, const _Tp& __b, _Compare __comp) {
+ //return __comp(__b, __a) ? __b : __a;
+ if (__comp(__b, __a)) return __b; return __a;
+}
+
+template <class _Tp, class _Compare>
+inline const _Tp& max(const _Tp& __a, const _Tp& __b, _Compare __comp) {
+ //return __comp(__a, __b) ? __b : __a;
+ if (__comp(__a, __b)) return __b; return __a;
+}
+
+//--------------------------------------------------
+// copy
+
+// All of these auxiliary functions serve two purposes. (1) Replace
+// calls to copy with memmove whenever possible. (Memmove, not memcpy,
+// because the input and output ranges are permitted to overlap.)
+// (2) If we're using random access iterators, then write the loop as
+// a for loop with an explicit count.
+
+template <class _InputIter, class _OutputIter, class _Distance>
+inline _OutputIter __copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result,
+ input_iterator_tag, _Distance*)
+{
+ for ( ; __first != __last; ++__result, ++__first)
+ *__result = *__first;
+ return __result;
+}
+
+template <class _RandomAccessIter, class _OutputIter, class _Distance>
+inline _OutputIter
+__copy(_RandomAccessIter __first, _RandomAccessIter __last,
+ _OutputIter __result, random_access_iterator_tag, _Distance*)
+{
+ for (_Distance __n = __last - __first; __n > 0; --__n) {
+ *__result = *__first;
+ ++__first;
+ ++__result;
+ }
+ return __result;
+}
+
+template <class _Tp>
+inline _Tp*
+__copy_trivial(const _Tp* __first, const _Tp* __last, _Tp* __result) {
+ memmove(__result, __first, sizeof(_Tp) * (__last - __first));
+ return __result + (__last - __first);
+}
+
+#if defined(__STL_FUNCTION_TMPL_PARTIAL_ORDER)
+
+template <class _InputIter, class _OutputIter>
+inline _OutputIter __copy_aux2(_InputIter __first, _InputIter __last,
+ _OutputIter __result, __false_type) {
+ return __copy(__first, __last, __result,
+ __ITERATOR_CATEGORY(__first),
+ __DISTANCE_TYPE(__first));
+}
+
+template <class _InputIter, class _OutputIter>
+inline _OutputIter __copy_aux2(_InputIter __first, _InputIter __last,
+ _OutputIter __result, __true_type) {
+ return __copy(__first, __last, __result,
+ __ITERATOR_CATEGORY(__first),
+ __DISTANCE_TYPE(__first));
+}
+
+template <class _Tp>
+inline _Tp* __copy_aux2(_Tp* __first, _Tp* __last, _Tp* __result,
+ __true_type) {
+ return __copy_trivial(__first, __last, __result);
+}
+
+template <class _Tp>
+inline _Tp* __copy_aux2(const _Tp* __first, const _Tp* __last, _Tp* __result,
+ __true_type) {
+ return __copy_trivial(__first, __last, __result);
+}
+
+
+template <class _InputIter, class _OutputIter, class _Tp>
+inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last,
+ _OutputIter __result, _Tp*) {
+ typedef typename __type_traits<_Tp>::has_trivial_assignment_operator
+ _Trivial;
+ return __copy_aux2(__first, __last, __result, _Trivial());
+}
+
+template<typename _InputIter, typename _OutputIter>
+inline _OutputIter __copy_ni2(_InputIter __first, _InputIter __last,
+ _OutputIter __result, __true_type) {
+ return _OutputIter(__copy_aux(__first, __last, __result.base(),
+ __VALUE_TYPE(__first)));
+}
+
+template<typename _InputIter, typename _OutputIter>
+inline _OutputIter __copy_ni2(_InputIter __first, _InputIter __last,
+ _OutputIter __result, __false_type) {
+ return __copy_aux(__first, __last, __result, __VALUE_TYPE(__first));
+}
+
+template<typename _InputIter, typename _OutputIter>
+inline _OutputIter __copy_ni1(_InputIter __first, _InputIter __last,
+ _OutputIter __result, __true_type) {
+ typedef typename _Is_normal_iterator<_OutputIter>::_Normal __Normal;
+ return __copy_ni2(__first.base(), __last.base(), __result, __Normal());
+}
+
+template<typename _InputIter, typename _OutputIter>
+inline _OutputIter __copy_ni1(_InputIter __first, _InputIter __last,
+ _OutputIter __result, __false_type) {
+ typedef typename _Is_normal_iterator<_OutputIter>::_Normal __Normal;
+ return __copy_ni2(__first, __last, __result, __Normal());
+}
+
+template <class _InputIter, class _OutputIter>
+inline _OutputIter copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result) {
+ typedef typename _Is_normal_iterator<_InputIter>::_Normal __Normal;
+ return __copy_ni1(__first, __last, __result, __Normal());
+}
+
+// Hack for compilers that don't have partial ordering of function templates
+// but do have partial specialization of class templates.
+#elif defined(__STL_CLASS_PARTIAL_SPECIALIZATION)
+
+template <class _InputIter, class _OutputIter, class _BoolType>
+struct __copy_dispatch {
+ static _OutputIter copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result) {
+ typedef typename iterator_traits<_InputIter>::iterator_category _Category;
+ typedef typename iterator_traits<_InputIter>::difference_type _Distance;
+ return __copy(__first, __last, __result, _Category(), (_Distance*) 0);
+ }
+};
+
+template <class _Tp>
+struct __copy_dispatch<_Tp*, _Tp*, __true_type>
+{
+ static _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) {
+ return __copy_trivial(__first, __last, __result);
+ }
+};
+
+template <class _Tp>
+struct __copy_dispatch<const _Tp*, _Tp*, __true_type>
+{
+ static _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) {
+ return __copy_trivial(__first, __last, __result);
+ }
+};
+
+template <class _InputIter, class _OutputIter>
+inline _OutputIter copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result) {
+ typedef typename iterator_traits<_InputIter>::value_type _Tp;
+ typedef typename __type_traits<_Tp>::has_trivial_assignment_operator
+ _Trivial;
+ return __copy_dispatch<_InputIter, _OutputIter, _Trivial>
+ ::copy(__first, __last, __result);
+}
+
+// Fallback for compilers with neither partial ordering nor partial
+// specialization. Define the faster version for the basic builtin
+// types.
+#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _InputIter, class _OutputIter>
+inline _OutputIter copy(_InputIter __first, _InputIter __last,
+ _OutputIter __result)
+{
+ return __copy(__first, __last, __result,
+ __ITERATOR_CATEGORY(__first),
+ __DISTANCE_TYPE(__first));
+}
+
+#define __SGI_STL_DECLARE_COPY_TRIVIAL(_Tp) \
+ inline _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) { \
+ return __copy_trivial(__first, __last, __result); \
+ }
+
+__SGI_STL_DECLARE_COPY_TRIVIAL(char)
+__SGI_STL_DECLARE_COPY_TRIVIAL(signed char)
+__SGI_STL_DECLARE_COPY_TRIVIAL(unsigned char)
+__SGI_STL_DECLARE_COPY_TRIVIAL(short)
+__SGI_STL_DECLARE_COPY_TRIVIAL(unsigned short)
+__SGI_STL_DECLARE_COPY_TRIVIAL(int)
+__SGI_STL_DECLARE_COPY_TRIVIAL(unsigned int)
+__SGI_STL_DECLARE_COPY_TRIVIAL(long)
+__SGI_STL_DECLARE_COPY_TRIVIAL(unsigned long)
+#ifdef __STL_HAS_WCHAR_T
+__SGI_STL_DECLARE_COPY_TRIVIAL(wchar_t)
+#endif
+#ifdef _STL_LONG_LONG
+__SGI_STL_DECLARE_COPY_TRIVIAL(long long)
+__SGI_STL_DECLARE_COPY_TRIVIAL(unsigned long long)
+#endif
+__SGI_STL_DECLARE_COPY_TRIVIAL(float)
+__SGI_STL_DECLARE_COPY_TRIVIAL(double)
+__SGI_STL_DECLARE_COPY_TRIVIAL(long double)
+
+#undef __SGI_STL_DECLARE_COPY_TRIVIAL
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+//--------------------------------------------------
+// copy_backward
+
+template <class _BidirectionalIter1, class _BidirectionalIter2,
+ class _Distance>
+inline _BidirectionalIter2 __copy_backward(_BidirectionalIter1 __first,
+ _BidirectionalIter1 __last,
+ _BidirectionalIter2 __result,
+ bidirectional_iterator_tag,
+ _Distance*)
+{
+ while (__first != __last)
+ *--__result = *--__last;
+ return __result;
+}
+
+template <class _RandomAccessIter, class _BidirectionalIter, class _Distance>
+inline _BidirectionalIter __copy_backward(_RandomAccessIter __first,
+ _RandomAccessIter __last,
+ _BidirectionalIter __result,
+ random_access_iterator_tag,
+ _Distance*)
+{
+ for (_Distance __n = __last - __first; __n > 0; --__n)
+ *--__result = *--__last;
+ return __result;
+}
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+// This dispatch class is a workaround for compilers that do not
+// have partial ordering of function templates. All we're doing is
+// creating a specialization so that we can turn a call to copy_backward
+// into a memmove whenever possible.
+
+template <class _BidirectionalIter1, class _BidirectionalIter2,
+ class _BoolType>
+struct __copy_backward_dispatch
+{
+ typedef typename iterator_traits<_BidirectionalIter1>::iterator_category
+ _Cat;
+ typedef typename iterator_traits<_BidirectionalIter1>::difference_type
+ _Distance;
+
+ static _BidirectionalIter2 copy(_BidirectionalIter1 __first,
+ _BidirectionalIter1 __last,
+ _BidirectionalIter2 __result) {
+ return __copy_backward(__first, __last, __result, _Cat(), (_Distance*) 0);
+ }
+};
+
+template <class _Tp>
+struct __copy_backward_dispatch<_Tp*, _Tp*, __true_type>
+{
+ static _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) {
+ const ptrdiff_t _Num = __last - __first;
+ memmove(__result - _Num, __first, sizeof(_Tp) * _Num);
+ return __result - _Num;
+ }
+};
+
+template <class _Tp>
+struct __copy_backward_dispatch<const _Tp*, _Tp*, __true_type>
+{
+ static _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) {
+ return __copy_backward_dispatch<_Tp*, _Tp*, __true_type>
+ ::copy(__first, __last, __result);
+ }
+};
+
+template <class _BI1, class _BI2>
+inline _BI2 __copy_backward_aux(_BI1 __first, _BI1 __last, _BI2 __result) {
+ typedef typename __type_traits<typename iterator_traits<_BI2>::value_type>
+ ::has_trivial_assignment_operator
+ _Trivial;
+ return __copy_backward_dispatch<_BI1, _BI2, _Trivial>
+ ::copy(__first, __last, __result);
+}
+
+template <typename _BI1, typename _BI2>
+inline _BI2 __copy_backward_output_normal_iterator(_BI1 __first, _BI1 __last,
+ _BI2 __result, __true_type) {
+ return _BI2(__copy_backward_aux(__first, __last, __result.base()));
+}
+
+template <typename _BI1, typename _BI2>
+inline _BI2 __copy_backward_output_normal_iterator(_BI1 __first, _BI1 __last,
+ _BI2 __result, __false_type){
+ return __copy_backward_aux(__first, __last, __result);
+}
+
+template <typename _BI1, typename _BI2>
+inline _BI2 __copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last,
+ _BI2 __result, __true_type) {
+ typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal;
+ return __copy_backward_output_normal_iterator(__first.base(), __last.base(),
+ __result, __Normal());
+}
+
+template <typename _BI1, typename _BI2>
+inline _BI2 __copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last,
+ _BI2 __result, __false_type) {
+ typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal;
+ return __copy_backward_output_normal_iterator(__first, __last, __result,
+ __Normal());
+}
+
+template <typename _BI1, typename _BI2>
+inline _BI2 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result) {
+ typedef typename _Is_normal_iterator<_BI1>::_Normal __Normal;
+ return __copy_backward_input_normal_iterator(__first, __last, __result,
+ __Normal());
+}
+
+#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _BI1, class _BI2>
+inline _BI2 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result) {
+ return __copy_backward(__first, __last, __result,
+ __ITERATOR_CATEGORY(__first),
+ __DISTANCE_TYPE(__first));
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+//--------------------------------------------------
+// copy_n (not part of the C++ standard)
+
+template <class _InputIter, class _Size, class _OutputIter>
+pair<_InputIter, _OutputIter> __copy_n(_InputIter __first, _Size __count,
+ _OutputIter __result,
+ input_iterator_tag) {
+ for ( ; __count > 0; --__count) {
+ *__result = *__first;
+ ++__first;
+ ++__result;
+ }
+ return pair<_InputIter, _OutputIter>(__first, __result);
+}
+
+template <class _RAIter, class _Size, class _OutputIter>
+inline pair<_RAIter, _OutputIter>
+__copy_n(_RAIter __first, _Size __count,
+ _OutputIter __result,
+ random_access_iterator_tag) {
+ _RAIter __last = __first + __count;
+ return pair<_RAIter, _OutputIter>(__last, copy(__first, __last, __result));
+}
+
+template <class _InputIter, class _Size, class _OutputIter>
+inline pair<_InputIter, _OutputIter>
+__copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
+ return __copy_n(__first, __count, __result,
+ __ITERATOR_CATEGORY(__first));
+}
+
+template <class _InputIter, class _Size, class _OutputIter>
+inline pair<_InputIter, _OutputIter>
+copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
+ return __copy_n(__first, __count, __result);
+}
+
+//--------------------------------------------------
+// fill and fill_n
+
+
+template <class _ForwardIter, class _Tp>
+void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __value) {
+ for ( ; __first != __last; ++__first)
+ *__first = __value;
+}
+
+template <class _OutputIter, class _Size, class _Tp>
+_OutputIter fill_n(_OutputIter __first, _Size __n, const _Tp& __value) {
+ for ( ; __n > 0; --__n, ++__first)
+ *__first = __value;
+ return __first;
+}
+
+//--------------------------------------------------
+// equal and mismatch
+
+template <class _InputIter1, class _InputIter2>
+pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
+ _InputIter1 __last1,
+ _InputIter2 __first2) {
+ while (__first1 != __last1 && *__first1 == *__first2) {
+ ++__first1;
+ ++__first2;
+ }
+ return pair<_InputIter1, _InputIter2>(__first1, __first2);
+}
+
+template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
+pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
+ _InputIter1 __last1,
+ _InputIter2 __first2,
+ _BinaryPredicate __binary_pred) {
+ while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) {
+ ++__first1;
+ ++__first2;
+ }
+ return pair<_InputIter1, _InputIter2>(__first1, __first2);
+}
+
+template <class _InputIter1, class _InputIter2>
+inline bool equal(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2) {
+ for ( ; __first1 != __last1; ++__first1, ++__first2)
+ if (*__first1 != *__first2)
+ return false;
+ return true;
+}
+
+template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
+inline bool equal(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _BinaryPredicate __binary_pred) {
+ for ( ; __first1 != __last1; ++__first1, ++__first2)
+ if (!__binary_pred(*__first1, *__first2))
+ return false;
+ return true;
+}
+
+//--------------------------------------------------
+// lexicographical_compare and lexicographical_compare_3way.
+// (the latter is not part of the C++ standard.)
+
+template <class _InputIter1, class _InputIter2>
+bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2) {
+ for ( ; __first1 != __last1 && __first2 != __last2
+ ; ++__first1, ++__first2) {
+ if (*__first1 < *__first2)
+ return true;
+ if (*__first2 < *__first1)
+ return false;
+ }
+ return __first1 == __last1 && __first2 != __last2;
+}
+
+template <class _InputIter1, class _InputIter2, class _Compare>
+bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _Compare __comp) {
+ for ( ; __first1 != __last1 && __first2 != __last2
+ ; ++__first1, ++__first2) {
+ if (__comp(*__first1, *__first2))
+ return true;
+ if (__comp(*__first2, *__first1))
+ return false;
+ }
+ return __first1 == __last1 && __first2 != __last2;
+}
+
+inline bool
+lexicographical_compare(const unsigned char* __first1,
+ const unsigned char* __last1,
+ const unsigned char* __first2,
+ const unsigned char* __last2)
+{
+ const size_t __len1 = __last1 - __first1;
+ const size_t __len2 = __last2 - __first2;
+ const int __result = memcmp(__first1, __first2, min(__len1, __len2));
+ return __result != 0 ? __result < 0 : __len1 < __len2;
+}
+
+inline bool lexicographical_compare(const char* __first1, const char* __last1,
+ const char* __first2, const char* __last2)
+{
+#if CHAR_MAX == SCHAR_MAX
+ return lexicographical_compare((const signed char*) __first1,
+ (const signed char*) __last1,
+ (const signed char*) __first2,
+ (const signed char*) __last2);
+#else /* CHAR_MAX == SCHAR_MAX */
+ return lexicographical_compare((const unsigned char*) __first1,
+ (const unsigned char*) __last1,
+ (const unsigned char*) __first2,
+ (const unsigned char*) __last2);
+#endif /* CHAR_MAX == SCHAR_MAX */
+}
+
+template <class _InputIter1, class _InputIter2>
+int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2)
+{
+ while (__first1 != __last1 && __first2 != __last2) {
+ if (*__first1 < *__first2)
+ return -1;
+ if (*__first2 < *__first1)
+ return 1;
+ ++__first1;
+ ++__first2;
+ }
+ if (__first2 == __last2) {
+ return !(__first1 == __last1);
+ }
+ else {
+ return -1;
+ }
+}
+
+inline int
+__lexicographical_compare_3way(const unsigned char* __first1,
+ const unsigned char* __last1,
+ const unsigned char* __first2,
+ const unsigned char* __last2)
+{
+ const ptrdiff_t __len1 = __last1 - __first1;
+ const ptrdiff_t __len2 = __last2 - __first2;
+ const int __result = memcmp(__first1, __first2, min(__len1, __len2));
+ return __result != 0 ? __result
+ : (__len1 == __len2 ? 0 : (__len1 < __len2 ? -1 : 1));
+}
+
+inline int
+__lexicographical_compare_3way(const char* __first1, const char* __last1,
+ const char* __first2, const char* __last2)
+{
+#if CHAR_MAX == SCHAR_MAX
+ return __lexicographical_compare_3way(
+ (const signed char*) __first1,
+ (const signed char*) __last1,
+ (const signed char*) __first2,
+ (const signed char*) __last2);
+#else
+ return __lexicographical_compare_3way((const unsigned char*) __first1,
+ (const unsigned char*) __last1,
+ (const unsigned char*) __first2,
+ (const unsigned char*) __last2);
+#endif
+}
+
+template <class _InputIter1, class _InputIter2>
+int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2)
+{
+ return __lexicographical_compare_3way(__first1, __last1, __first2, __last2);
+}
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_ALGOBASE_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_alloc.h b/libstdc++-v3/bits/stl_alloc.h
new file mode 100644
index 0000000..d28938b
--- /dev/null
+++ b/libstdc++-v3/bits/stl_alloc.h
@@ -0,0 +1,905 @@
+/*
+ * Copyright (c) 1996-1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_ALLOC_H
+#define __SGI_STL_INTERNAL_ALLOC_H
+
+#ifdef __SUNPRO_CC
+# define __PRIVATE public
+ // Extra access restrictions prevent us from really making some things
+ // private.
+#else
+# define __PRIVATE private
+#endif
+
+#ifdef __STL_STATIC_TEMPLATE_MEMBER_BUG
+# define __USE_MALLOC
+#endif
+
+
+// This implements some standard node allocators. These are
+// NOT the same as the allocators in the C++ draft standard or in
+// in the original STL. They do not encapsulate different pointer
+// types; indeed we assume that there is only one pointer type.
+// The allocation primitives are intended to allocate individual objects,
+// not larger arenas as with the original STL allocators.
+
+#ifndef __THROW_BAD_ALLOC
+# if defined(__STL_NO_BAD_ALLOC) || !defined(__STL_USE_EXCEPTIONS)
+# include <bits/std_cstdio.h>
+# include <bits/std_cstdlib.h>
+# define __THROW_BAD_ALLOC fprintf(stderr, "out of memory\n"); exit(1)
+# else /* Standard conforming out-of-memory handling */
+# include <bits/std_new.h>
+# define __THROW_BAD_ALLOC throw std::bad_alloc()
+# endif
+#endif
+
+#ifdef __STL_WIN32THREADS
+# include <windows.h>
+#endif
+
+#include <bits/std_cstddef.h>
+#include <bits/std_cstdlib.h>
+#include <bits/std_cstring.h>
+#include <bits/std_cassert.h>
+#ifndef __RESTRICT
+# define __RESTRICT
+#endif
+
+#ifdef __STL_THREADS
+# include <bits/stl_threads.h>
+# define __NODE_ALLOCATOR_THREADS true
+# ifdef __STL_SGI_THREADS
+ // We test whether threads are in use before locking.
+ // Perhaps this should be moved into stl_threads.h, but that
+ // probably makes it harder to avoid the procedure call when
+ // it isn't needed.
+ extern "C" {
+ extern int __us_rsthread_malloc;
+ }
+ // The above is copied from malloc.h. Including <malloc.h>
+ // would be cleaner but fails with certain levels of standard
+ // conformance.
+# define __NODE_ALLOCATOR_LOCK if (threads && __us_rsthread_malloc) \
+ { _S_node_allocator_lock._M_acquire_lock(); }
+# define __NODE_ALLOCATOR_UNLOCK if (threads && __us_rsthread_malloc) \
+ { _S_node_allocator_lock._M_release_lock(); }
+# else /* !__STL_SGI_THREADS */
+# define __NODE_ALLOCATOR_LOCK \
+ { if (threads) _S_node_allocator_lock._M_acquire_lock(); }
+# define __NODE_ALLOCATOR_UNLOCK \
+ { if (threads) _S_node_allocator_lock._M_release_lock(); }
+# endif
+#else
+// Thread-unsafe
+# define __NODE_ALLOCATOR_LOCK
+# define __NODE_ALLOCATOR_UNLOCK
+# define __NODE_ALLOCATOR_THREADS false
+#endif
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1174
+#endif
+
+// Malloc-based allocator. Typically slower than default alloc below.
+// Typically thread-safe and more storage efficient.
+#ifdef __STL_STATIC_TEMPLATE_MEMBER_BUG
+# ifdef __DECLARE_GLOBALS_HERE
+ void (* __malloc_alloc_oom_handler)() = 0;
+ // g++ 2.7.2 does not handle static template data members.
+# else
+ extern void (* __malloc_alloc_oom_handler)();
+# endif
+#endif
+
+template <int __inst>
+class __malloc_alloc_template {
+
+private:
+
+ static void* _S_oom_malloc(size_t);
+ static void* _S_oom_realloc(void*, size_t);
+
+#ifndef __STL_STATIC_TEMPLATE_MEMBER_BUG
+ static void (* __malloc_alloc_oom_handler)();
+#endif
+
+public:
+
+ static void* allocate(size_t __n)
+ {
+ void* __result = malloc(__n);
+ if (0 == __result) __result = _S_oom_malloc(__n);
+ return __result;
+ }
+
+ static void deallocate(void* __p, size_t /* __n */)
+ {
+ free(__p);
+ }
+
+ static void* reallocate(void* __p, size_t /* old_sz */, size_t __new_sz)
+ {
+ void* __result = realloc(__p, __new_sz);
+ if (0 == __result) __result = _S_oom_realloc(__p, __new_sz);
+ return __result;
+ }
+
+ static void (* __set_malloc_handler(void (*__f)()))()
+ {
+ void (* __old)() = __malloc_alloc_oom_handler;
+ __malloc_alloc_oom_handler = __f;
+ return(__old);
+ }
+
+};
+
+// malloc_alloc out-of-memory handling
+
+#ifndef __STL_STATIC_TEMPLATE_MEMBER_BUG
+template <int __inst>
+void (* __malloc_alloc_template<__inst>::__malloc_alloc_oom_handler)() = 0;
+#endif
+
+template <int __inst>
+void*
+__malloc_alloc_template<__inst>::_S_oom_malloc(size_t __n)
+{
+ void (* __my_malloc_handler)();
+ void* __result;
+
+ for (;;) {
+ __my_malloc_handler = __malloc_alloc_oom_handler;
+ if (0 == __my_malloc_handler) { __THROW_BAD_ALLOC; }
+ (*__my_malloc_handler)();
+ __result = malloc(__n);
+ if (__result) return(__result);
+ }
+}
+
+template <int __inst>
+void* __malloc_alloc_template<__inst>::_S_oom_realloc(void* __p, size_t __n)
+{
+ void (* __my_malloc_handler)();
+ void* __result;
+
+ for (;;) {
+ __my_malloc_handler = __malloc_alloc_oom_handler;
+ if (0 == __my_malloc_handler) { __THROW_BAD_ALLOC; }
+ (*__my_malloc_handler)();
+ __result = realloc(__p, __n);
+ if (__result) return(__result);
+ }
+}
+
+typedef __malloc_alloc_template<0> malloc_alloc;
+
+template<class _Tp, class _Alloc>
+class simple_alloc {
+
+public:
+ static _Tp* allocate(size_t __n)
+ { return 0 == __n ? 0 : (_Tp*) _Alloc::allocate(__n * sizeof (_Tp)); }
+ static _Tp* allocate(void)
+ { return (_Tp*) _Alloc::allocate(sizeof (_Tp)); }
+ static void deallocate(_Tp* __p, size_t __n)
+ { if (0 != __n) _Alloc::deallocate(__p, __n * sizeof (_Tp)); }
+ static void deallocate(_Tp* __p)
+ { _Alloc::deallocate(__p, sizeof (_Tp)); }
+};
+
+// Allocator adaptor to check size arguments for debugging.
+// Reports errors using assert. Checking can be disabled with
+// NDEBUG, but it's far better to just use the underlying allocator
+// instead when no checking is desired.
+// There is some evidence that this can confuse Purify.
+template <class _Alloc>
+class debug_alloc {
+
+private:
+
+ enum {_S_extra = 8}; // Size of space used to store size. Note
+ // that this must be large enough to preserve
+ // alignment.
+
+public:
+
+ static void* allocate(size_t __n)
+ {
+ char* __result = (char*)_Alloc::allocate(__n + (int) _S_extra);
+ *(size_t*)__result = __n;
+ return __result + (int) _S_extra;
+ }
+
+ static void deallocate(void* __p, size_t __n)
+ {
+ char* __real_p = (char*)__p - (int) _S_extra;
+ assert(*(size_t*)__real_p == __n);
+ _Alloc::deallocate(__real_p, __n + (int) _S_extra);
+ }
+
+ static void* reallocate(void* __p, size_t __old_sz, size_t __new_sz)
+ {
+ char* __real_p = (char*)__p - (int) _S_extra;
+ assert(*(size_t*)__real_p == __old_sz);
+ char* __result = (char*)
+ _Alloc::reallocate(__real_p, __old_sz + (int) _S_extra,
+ __new_sz + (int) _S_extra);
+ *(size_t*)__result = __new_sz;
+ return __result + (int) _S_extra;
+ }
+
+};
+
+
+# ifdef __USE_MALLOC
+
+typedef malloc_alloc alloc;
+typedef malloc_alloc single_client_alloc;
+
+# else
+
+
+// Default node allocator.
+// With a reasonable compiler, this should be roughly as fast as the
+// original STL class-specific allocators, but with less fragmentation.
+// Default_alloc_template parameters are experimental and MAY
+// DISAPPEAR in the future. Clients should just use alloc for now.
+//
+// Important implementation properties:
+// 1. If the client request an object of size > _MAX_BYTES, the resulting
+// object will be obtained directly from malloc.
+// 2. In all other cases, we allocate an object of size exactly
+// _S_round_up(requested_size). Thus the client has enough size
+// information that we can return the object to the proper free list
+// without permanently losing part of the object.
+//
+
+// The first template parameter specifies whether more than one thread
+// may use this allocator. It is safe to allocate an object from
+// one instance of a default_alloc and deallocate it with another
+// one. This effectively transfers its ownership to the second one.
+// This may have undesirable effects on reference locality.
+// The second parameter is unreferenced and serves only to allow the
+// creation of multiple default_alloc instances.
+// Node that containers built on different allocator instances have
+// different types, limiting the utility of this approach.
+#ifdef __SUNPRO_CC
+// breaks if we make these template class members:
+ enum {_ALIGN = 8};
+ enum {_MAX_BYTES = 128};
+ enum {_NFREELISTS = 16}; // _MAX_BYTES/_ALIGN
+#endif
+
+template <bool threads, int inst>
+class __default_alloc_template {
+
+private:
+ // Really we should use static const int x = N
+ // instead of enum { x = N }, but few compilers accept the former.
+# ifndef __SUNPRO_CC
+ enum {_ALIGN = 8};
+ enum {_MAX_BYTES = 128};
+ enum {_NFREELISTS = 16}; // _MAX_BYTES/_ALIGN
+# endif
+ static size_t
+ _S_round_up(size_t __bytes)
+ { return (((__bytes) + (size_t) _ALIGN-1) & ~((size_t) _ALIGN - 1)); }
+
+__PRIVATE:
+ union _Obj {
+ union _Obj* _M_free_list_link;
+ char _M_client_data[1]; /* The client sees this. */
+ };
+private:
+# ifdef __SUNPRO_CC
+ static _Obj* __STL_VOLATILE _S_free_list[];
+ // Specifying a size results in duplicate def for 4.1
+# else
+ static _Obj* __STL_VOLATILE _S_free_list[_NFREELISTS];
+# endif
+ static size_t _S_freelist_index(size_t __bytes) {
+ return (((__bytes) + (size_t)_ALIGN-1)/(size_t)_ALIGN - 1);
+ }
+
+ // Returns an object of size __n, and optionally adds to size __n free list.
+ static void* _S_refill(size_t __n);
+ // Allocates a chunk for nobjs of size size. nobjs may be reduced
+ // if it is inconvenient to allocate the requested number.
+ static char* _S_chunk_alloc(size_t __size, int& __nobjs);
+
+ // Chunk allocation state.
+ static char* _S_start_free;
+ static char* _S_end_free;
+ static size_t _S_heap_size;
+
+# ifdef __STL_THREADS
+ static _STL_mutex_lock _S_node_allocator_lock;
+# endif
+
+ // It would be nice to use _STL_auto_lock here. But we
+ // don't need the NULL check. And we do need a test whether
+ // threads have actually been started.
+ class _Lock;
+ friend class _Lock;
+ class _Lock {
+ public:
+ _Lock() { __NODE_ALLOCATOR_LOCK; }
+ ~_Lock() { __NODE_ALLOCATOR_UNLOCK; }
+ };
+
+public:
+
+ /* __n must be > 0 */
+ static void* allocate(size_t __n)
+ {
+ void* __ret = 0;
+
+ if (__n > (size_t) _MAX_BYTES) {
+ __ret = malloc_alloc::allocate(__n);
+ }
+ else {
+ _Obj* __STL_VOLATILE* __my_free_list
+ = _S_free_list + _S_freelist_index(__n);
+ // Acquire the lock here with a constructor call.
+ // This ensures that it is released in exit or during stack
+ // unwinding.
+# ifndef _NOTHREADS
+ /*REFERENCED*/
+ _Lock __lock_instance;
+# endif
+ _Obj* __RESTRICT __result = *__my_free_list;
+ if (__result == 0)
+ __ret = _S_refill(_S_round_up(__n));
+ else {
+ *__my_free_list = __result -> _M_free_list_link;
+ __ret = __result;
+ }
+ }
+
+ return __ret;
+ };
+
+ /* __p may not be 0 */
+ static void deallocate(void* __p, size_t __n)
+ {
+ if (__n > (size_t) _MAX_BYTES)
+ malloc_alloc::deallocate(__p, __n);
+ else {
+ _Obj* __STL_VOLATILE* __my_free_list
+ = _S_free_list + _S_freelist_index(__n);
+ _Obj* __q = (_Obj*)__p;
+
+ // acquire lock
+# ifndef _NOTHREADS
+ /*REFERENCED*/
+ _Lock __lock_instance;
+# endif /* _NOTHREADS */
+ __q -> _M_free_list_link = *__my_free_list;
+ *__my_free_list = __q;
+ // lock is released here
+ }
+ }
+
+ static void* reallocate(void* __p, size_t __old_sz, size_t __new_sz);
+
+} ;
+
+typedef __default_alloc_template<__NODE_ALLOCATOR_THREADS, 0> alloc;
+typedef __default_alloc_template<false, 0> single_client_alloc;
+
+
+
+/* We allocate memory in large chunks in order to avoid fragmenting */
+/* the malloc heap too much. */
+/* We assume that size is properly aligned. */
+/* We hold the allocation lock. */
+template <bool __threads, int __inst>
+char*
+__default_alloc_template<__threads, __inst>::_S_chunk_alloc(size_t __size,
+ int& __nobjs)
+{
+ char* __result;
+ size_t __total_bytes = __size * __nobjs;
+ size_t __bytes_left = _S_end_free - _S_start_free;
+
+ if (__bytes_left >= __total_bytes) {
+ __result = _S_start_free;
+ _S_start_free += __total_bytes;
+ return(__result);
+ } else if (__bytes_left >= __size) {
+ __nobjs = (int)(__bytes_left/__size);
+ __total_bytes = __size * __nobjs;
+ __result = _S_start_free;
+ _S_start_free += __total_bytes;
+ return(__result);
+ } else {
+ size_t __bytes_to_get =
+ 2 * __total_bytes + _S_round_up(_S_heap_size >> 4);
+ // Try to make use of the left-over piece.
+ if (__bytes_left > 0) {
+ _Obj* __STL_VOLATILE* __my_free_list =
+ _S_free_list + _S_freelist_index(__bytes_left);
+
+ ((_Obj*)_S_start_free) -> _M_free_list_link = *__my_free_list;
+ *__my_free_list = (_Obj*)_S_start_free;
+ }
+ _S_start_free = (char*)malloc(__bytes_to_get);
+ if (0 == _S_start_free) {
+ size_t __i;
+ _Obj* __STL_VOLATILE* __my_free_list;
+ _Obj* __p;
+ // Try to make do with what we have. That can't
+ // hurt. We do not try smaller requests, since that tends
+ // to result in disaster on multi-process machines.
+ for (__i = __size;
+ __i <= (size_t) _MAX_BYTES;
+ __i += (size_t) _ALIGN) {
+ __my_free_list = _S_free_list + _S_freelist_index(__i);
+ __p = *__my_free_list;
+ if (0 != __p) {
+ *__my_free_list = __p -> _M_free_list_link;
+ _S_start_free = (char*)__p;
+ _S_end_free = _S_start_free + __i;
+ return(_S_chunk_alloc(__size, __nobjs));
+ // Any leftover piece will eventually make it to the
+ // right free list.
+ }
+ }
+ _S_end_free = 0; // In case of exception.
+ _S_start_free = (char*)malloc_alloc::allocate(__bytes_to_get);
+ // This should either throw an
+ // exception or remedy the situation. Thus we assume it
+ // succeeded.
+ }
+ _S_heap_size += __bytes_to_get;
+ _S_end_free = _S_start_free + __bytes_to_get;
+ return(_S_chunk_alloc(__size, __nobjs));
+ }
+}
+
+
+/* Returns an object of size __n, and optionally adds to size __n free list.*/
+/* We assume that __n is properly aligned. */
+/* We hold the allocation lock. */
+template <bool __threads, int __inst>
+void*
+__default_alloc_template<__threads, __inst>::_S_refill(size_t __n)
+{
+ int __nobjs = 20;
+ char* __chunk = _S_chunk_alloc(__n, __nobjs);
+ _Obj* __STL_VOLATILE* __my_free_list;
+ _Obj* __result;
+ _Obj* __current_obj;
+ _Obj* __next_obj;
+ int __i;
+
+ if (1 == __nobjs) return(__chunk);
+ __my_free_list = _S_free_list + _S_freelist_index(__n);
+
+ /* Build free list in chunk */
+ __result = (_Obj*)__chunk;
+ *__my_free_list = __next_obj = (_Obj*)(__chunk + __n);
+ for (__i = 1; ; __i++) {
+ __current_obj = __next_obj;
+ __next_obj = (_Obj*)((char*)__next_obj + __n);
+ if (__nobjs - 1 == __i) {
+ __current_obj -> _M_free_list_link = 0;
+ break;
+ } else {
+ __current_obj -> _M_free_list_link = __next_obj;
+ }
+ }
+ return(__result);
+}
+
+template <bool threads, int inst>
+void*
+__default_alloc_template<threads, inst>::reallocate(void* __p,
+ size_t __old_sz,
+ size_t __new_sz)
+{
+ void* __result;
+ size_t __copy_sz;
+
+ if (__old_sz > (size_t) _MAX_BYTES && __new_sz > (size_t) _MAX_BYTES) {
+ return(realloc(__p, __new_sz));
+ }
+ if (_S_round_up(__old_sz) == _S_round_up(__new_sz)) return(__p);
+ __result = allocate(__new_sz);
+ __copy_sz = __new_sz > __old_sz? __old_sz : __new_sz;
+ memcpy(__result, __p, __copy_sz);
+ deallocate(__p, __old_sz);
+ return(__result);
+}
+
+#ifdef __STL_THREADS
+ template <bool __threads, int __inst>
+ _STL_mutex_lock
+ __default_alloc_template<__threads, __inst>::_S_node_allocator_lock
+ __STL_MUTEX_INITIALIZER;
+#endif
+
+
+template <bool __threads, int __inst>
+char* __default_alloc_template<__threads, __inst>::_S_start_free = 0;
+
+template <bool __threads, int __inst>
+char* __default_alloc_template<__threads, __inst>::_S_end_free = 0;
+
+template <bool __threads, int __inst>
+size_t __default_alloc_template<__threads, __inst>::_S_heap_size = 0;
+
+template <bool __threads, int __inst>
+__default_alloc_template<__threads, __inst>::_Obj* __STL_VOLATILE
+__default_alloc_template<__threads, __inst> ::_S_free_list[
+# ifdef __SUNPRO_CC
+ _NFREELISTS
+# else
+ __default_alloc_template<__threads, __inst>::_NFREELISTS
+# endif
+] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
+// The 16 zeros are necessary to make version 4.1 of the SunPro
+// compiler happy. Otherwise it appears to allocate too little
+// space for the array.
+
+#endif /* ! __USE_MALLOC */
+
+// This implements allocators as specified in the C++ standard.
+//
+// Note that standard-conforming allocators use many language features
+// that are not yet widely implemented. In particular, they rely on
+// member templates, partial specialization, partial ordering of function
+// templates, the typename keyword, and the use of the template keyword
+// to refer to a template member of a dependent type.
+
+#ifdef __STL_USE_STD_ALLOCATORS
+
+template <class _Tp>
+class allocator {
+ typedef alloc _Alloc; // The underlying allocator.
+public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef _Tp* pointer;
+ typedef const _Tp* const_pointer;
+ typedef _Tp& reference;
+ typedef const _Tp& const_reference;
+ typedef _Tp value_type;
+
+ template <class _Tp1> struct rebind {
+ typedef allocator<_Tp1> other;
+ };
+
+ allocator() __STL_NOTHROW {}
+ allocator(const allocator&) __STL_NOTHROW {}
+ template <class _Tp1> allocator(const allocator<_Tp1>&) __STL_NOTHROW {}
+ ~allocator() __STL_NOTHROW {}
+
+ pointer address(reference __x) const { return &__x; }
+ const_pointer address(const_reference __x) const { return &__x; }
+
+ // __n is permitted to be 0. The C++ standard says nothing about what
+ // the return value is when __n == 0.
+ _Tp* allocate(size_type __n, const void* = 0) {
+ return __n != 0 ? static_cast<_Tp*>(_Alloc::allocate(__n * sizeof(_Tp)))
+ : 0;
+ }
+
+ // __p is not permitted to be a null pointer.
+ void deallocate(pointer __p, size_type __n)
+ { _Alloc::deallocate(__p, __n * sizeof(_Tp)); }
+
+ size_type max_size() const __STL_NOTHROW
+ { return size_t(-1) / sizeof(_Tp); }
+
+ void construct(pointer __p, const _Tp& __val) { new(__p) _Tp(__val); }
+ void destroy(pointer __p) { __p->~_Tp(); }
+};
+
+template<>
+class allocator<void> {
+public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef void* pointer;
+ typedef const void* const_pointer;
+ typedef void value_type;
+
+ template <class _Tp1> struct rebind {
+ typedef allocator<_Tp1> other;
+ };
+};
+
+
+template <class _T1, class _T2>
+inline bool operator==(const allocator<_T1>&, const allocator<_T2>&)
+{
+ return true;
+}
+
+template <class _T1, class _T2>
+inline bool operator!=(const allocator<_T1>&, const allocator<_T2>&)
+{
+ return false;
+}
+
+// Allocator adaptor to turn an SGI-style allocator (e.g. alloc, malloc_alloc)
+// into a standard-conforming allocator. Note that this adaptor does
+// *not* assume that all objects of the underlying alloc class are
+// identical, nor does it assume that all of the underlying alloc's
+// member functions are static member functions. Note, also, that
+// __allocator<_Tp, alloc> is essentially the same thing as allocator<_Tp>.
+
+template <class _Tp, class _Alloc>
+struct __allocator {
+ _Alloc __underlying_alloc;
+
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef _Tp* pointer;
+ typedef const _Tp* const_pointer;
+ typedef _Tp& reference;
+ typedef const _Tp& const_reference;
+ typedef _Tp value_type;
+
+ template <class _Tp1> struct rebind {
+ typedef __allocator<_Tp1, _Alloc> other;
+ };
+
+ __allocator() __STL_NOTHROW {}
+ __allocator(const __allocator& __a) __STL_NOTHROW
+ : __underlying_alloc(__a.__underlying_alloc) {}
+ template <class _Tp1>
+ __allocator(const __allocator<_Tp1, _Alloc>& __a) __STL_NOTHROW
+ : __underlying_alloc(__a.__underlying_alloc) {}
+ ~__allocator() __STL_NOTHROW {}
+
+ pointer address(reference __x) const { return &__x; }
+ const_pointer address(const_reference __x) const { return &__x; }
+
+ // __n is permitted to be 0.
+ _Tp* allocate(size_type __n, const void* = 0) {
+ return __n != 0
+ ? static_cast<_Tp*>(__underlying_alloc.allocate(__n * sizeof(_Tp)))
+ : 0;
+ }
+
+ // __p is not permitted to be a null pointer.
+ void deallocate(pointer __p, size_type __n)
+ { __underlying_alloc.deallocate(__p, __n * sizeof(_Tp)); }
+
+ size_type max_size() const __STL_NOTHROW
+ { return size_t(-1) / sizeof(_Tp); }
+
+ void construct(pointer __p, const _Tp& __val) { new(__p) _Tp(__val); }
+ void destroy(pointer __p) { __p->~_Tp(); }
+};
+
+template <class _Alloc>
+class __allocator<void, _Alloc> {
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef void* pointer;
+ typedef const void* const_pointer;
+ typedef void value_type;
+
+ template <class _Tp1> struct rebind {
+ typedef __allocator<_Tp1, _Alloc> other;
+ };
+};
+
+template <class _Tp, class _Alloc>
+inline bool operator==(const __allocator<_Tp, _Alloc>& __a1,
+ const __allocator<_Tp, _Alloc>& __a2)
+{
+ return __a1.__underlying_alloc == __a2.__underlying_alloc;
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+template <class _Tp, class _Alloc>
+inline bool operator!=(const __allocator<_Tp, _Alloc>& __a1,
+ const __allocator<_Tp, _Alloc>& __a2)
+{
+ return __a1.__underlying_alloc != __a2.__underlying_alloc;
+}
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+// Comparison operators for all of the predifined SGI-style allocators.
+// This ensures that __allocator<malloc_alloc> (for example) will
+// work correctly.
+
+template <int inst>
+inline bool operator==(const __malloc_alloc_template<inst>&,
+ const __malloc_alloc_template<inst>&)
+{
+ return true;
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+template <int __inst>
+inline bool operator!=(const __malloc_alloc_template<__inst>&,
+ const __malloc_alloc_template<__inst>&)
+{
+ return false;
+}
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+#ifndef __USE_MALLOC
+template <bool __threads, int __inst>
+inline bool operator==(const __default_alloc_template<__threads, __inst>&,
+ const __default_alloc_template<__threads, __inst>&)
+{
+ return true;
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+template <bool __threads, int __inst>
+inline bool operator!=(const __default_alloc_template<__threads, __inst>&,
+ const __default_alloc_template<__threads, __inst>&)
+{
+ return false;
+}
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+#endif
+
+template <class _Alloc>
+inline bool operator==(const debug_alloc<_Alloc>&,
+ const debug_alloc<_Alloc>&) {
+ return true;
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+template <class _Alloc>
+inline bool operator!=(const debug_alloc<_Alloc>&,
+ const debug_alloc<_Alloc>&) {
+ return false;
+}
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+// Another allocator adaptor: _Alloc_traits. This serves two
+// purposes. First, make it possible to write containers that can use
+// either SGI-style allocators or standard-conforming allocator.
+// Second, provide a mechanism so that containers can query whether or
+// not the allocator has distinct instances. If not, the container
+// can avoid wasting a word of memory to store an empty object.
+
+// This adaptor uses partial specialization. The general case of
+// _Alloc_traits<_Tp, _Alloc> assumes that _Alloc is a
+// standard-conforming allocator, possibly with non-equal instances
+// and non-static members. (It still behaves correctly even if _Alloc
+// has static member and if all instances are equal. Refinements
+// affect performance, not correctness.)
+
+// There are always two members: allocator_type, which is a standard-
+// conforming allocator type for allocating objects of type _Tp, and
+// _S_instanceless, a static const member of type bool. If
+// _S_instanceless is true, this means that there is no difference
+// between any two instances of type allocator_type. Furthermore, if
+// _S_instanceless is true, then _Alloc_traits has one additional
+// member: _Alloc_type. This type encapsulates allocation and
+// deallocation of objects of type _Tp through a static interface; it
+// has two member functions, whose signatures are
+// static _Tp* allocate(size_t)
+// static void deallocate(_Tp*, size_t)
+
+// The fully general version.
+
+template <class _Tp, class _Allocator>
+struct _Alloc_traits
+{
+ static const bool _S_instanceless = false;
+ typedef typename _Allocator::__STL_TEMPLATE rebind<_Tp>::other
+ allocator_type;
+};
+
+template <class _Tp, class _Allocator>
+const bool _Alloc_traits<_Tp, _Allocator>::_S_instanceless;
+
+// The version for the default allocator.
+
+template <class _Tp, class _Tp1>
+struct _Alloc_traits<_Tp, allocator<_Tp1> >
+{
+ static const bool _S_instanceless = true;
+ typedef simple_alloc<_Tp, alloc> _Alloc_type;
+ typedef allocator<_Tp> allocator_type;
+};
+
+// Versions for the predefined SGI-style allocators.
+
+template <class _Tp, int __inst>
+struct _Alloc_traits<_Tp, __malloc_alloc_template<__inst> >
+{
+ static const bool _S_instanceless = true;
+ typedef simple_alloc<_Tp, __malloc_alloc_template<__inst> > _Alloc_type;
+ typedef __allocator<_Tp, __malloc_alloc_template<__inst> > allocator_type;
+};
+
+#ifndef __USE_MALLOC
+template <class _Tp, bool __threads, int __inst>
+struct _Alloc_traits<_Tp, __default_alloc_template<__threads, __inst> >
+{
+ static const bool _S_instanceless = true;
+ typedef simple_alloc<_Tp, __default_alloc_template<__threads, __inst> >
+ _Alloc_type;
+ typedef __allocator<_Tp, __default_alloc_template<__threads, __inst> >
+ allocator_type;
+};
+#endif
+
+template <class _Tp, class _Alloc>
+struct _Alloc_traits<_Tp, debug_alloc<_Alloc> >
+{
+ static const bool _S_instanceless = true;
+ typedef simple_alloc<_Tp, debug_alloc<_Alloc> > _Alloc_type;
+ typedef __allocator<_Tp, debug_alloc<_Alloc> > allocator_type;
+};
+
+// Versions for the __allocator adaptor used with the predefined
+// SGI-style allocators.
+
+template <class _Tp, class _Tp1, int __inst>
+struct _Alloc_traits<_Tp,
+ __allocator<_Tp1, __malloc_alloc_template<__inst> > >
+{
+ static const bool _S_instanceless = true;
+ typedef simple_alloc<_Tp, __malloc_alloc_template<__inst> > _Alloc_type;
+ typedef __allocator<_Tp, __malloc_alloc_template<__inst> > allocator_type;
+};
+
+#ifndef __USE_MALLOC
+template <class _Tp, class _Tp1, bool __thr, int __inst>
+struct _Alloc_traits<_Tp,
+ __allocator<_Tp1,
+ __default_alloc_template<__thr, __inst> > >
+{
+ static const bool _S_instanceless = true;
+ typedef simple_alloc<_Tp, __default_alloc_template<__thr,__inst> >
+ _Alloc_type;
+ typedef __allocator<_Tp, __default_alloc_template<__thr,__inst> >
+ allocator_type;
+};
+#endif
+
+template <class _Tp, class _Tp1, class _Alloc>
+struct _Alloc_traits<_Tp, __allocator<_Tp1, debug_alloc<_Alloc> > >
+{
+ static const bool _S_instanceless = true;
+ typedef simple_alloc<_Tp, debug_alloc<_Alloc> > _Alloc_type;
+ typedef __allocator<_Tp, debug_alloc<_Alloc> > allocator_type;
+};
+
+
+#endif /* __STL_USE_STD_ALLOCATORS */
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1174
+#endif
+
+__STL_END_NAMESPACE
+
+#undef __PRIVATE
+
+#endif /* __SGI_STL_INTERNAL_ALLOC_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_config.h b/libstdc++-v3/bits/stl_config.h
new file mode 100644
index 0000000..6e2200d
--- /dev/null
+++ b/libstdc++-v3/bits/stl_config.h
@@ -0,0 +1,490 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * Copyright (c) 1997
+ * Silicon Graphics
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ */
+
+#ifndef __STL_CONFIG_H
+# define __STL_CONFIG_H
+
+// Flags:
+// * __STL_NO_BOOL: defined if the compiler doesn't have bool as a builtin
+// type.
+// * __STL_HAS_WCHAR_T: defined if the compier has wchar_t as a builtin type.
+// * __STL_NO_DRAND48: defined if the compiler doesn't have the drand48
+// function.
+// * __STL_STATIC_TEMPLATE_MEMBER_BUG: defined if the compiler can't handle
+// static members of template classes.
+// * __STL_STATIC_CONST_INIT_BUG: defined if the compiler can't handle a
+// constant-initializer in the declaration of a static const data member
+// of integer type. (See section 9.4.2, paragraph 4, of the C++ standard.)
+// * __STL_CLASS_PARTIAL_SPECIALIZATION: defined if the compiler supports
+// partial specialization of template classes.
+// * __STL_PARTIAL_SPECIALIZATION_SYNTAX: defined if the compiler
+// supports partial specialization syntax for full specialization of
+// class templates. (Even if it doesn't actually support partial
+// specialization itself.)
+// * __STL_FUNCTION_TMPL_PARTIAL_ORDER: defined if the compiler supports
+// partial ordering of function templates. (a.k.a partial specialization
+// of function templates.)
+// * __STL_MEMBER_TEMPLATES: defined if the compiler supports template
+// member functions of classes.
+// * __STL_MEMBER_TEMPLATE_CLASSES: defined if the compiler supports
+// nested classes that are member templates of other classes.
+// * __STL_EXPLICIT_FUNCTION_TMPL_ARGS: defined if the compiler
+// supports calling a function template by providing its template
+// arguments explicitly.
+// * __STL_LIMITED_DEFAULT_TEMPLATES: defined if the compiler is unable
+// to handle default template parameters that depend on previous template
+// parameters.
+// * __STL_NON_TYPE_TMPL_PARAM_BUG: defined if the compiler has trouble with
+// function template argument deduction for non-type template parameters.
+// * __SGI_STL_NO_ARROW_OPERATOR: defined if the compiler is unable
+// to support the -> operator for iterators.
+// * __STL_DEFAULT_CONSTRUCTOR_BUG: defined if T() does not work properly
+// when T is a builtin type.
+// * __STL_USE_EXCEPTIONS: defined if the compiler (in the current compilation
+// mode) supports exceptions.
+// * __STL_USE_NAMESPACES: defined if the compiler has the necessary
+// support for namespaces.
+// * __STL_NO_EXCEPTION_HEADER: defined if the compiler does not have a
+// standard-conforming header <exception>.
+// * __STL_NO_BAD_ALLOC: defined if the compiler does not have a <new>
+// header, or if <new> does not contain a bad_alloc class. If a bad_alloc
+// class exists, it is assumed to be in namespace std.
+// * __STL_SGI_THREADS: defined if this is being compiled for an SGI IRIX
+// system in multithreaded mode, using native SGI threads instead of
+// pthreads.
+// * __STL_WIN32THREADS: defined if this is being compiled on a WIN32
+// compiler in multithreaded mode.
+// * __STL_PTHREADS: defined if we should use portable pthreads
+// synchronization.
+// * __STL_UITHREADS: defined if we should use UI / solaris / UnixWare threads
+// synchronization. UIthreads are similar to pthreads, but are based
+// on an earlier version of the Posix threads standard.
+// * __STL_LONG_LONG if the compiler has long long and unsigned long long
+// types. (They're not in the C++ standard, but they are expected to be
+// included in the forthcoming C9X standard.)
+// * __STL_THREADS is defined if thread safety is needed.
+// * __STL_VOLATILE is deifined to be "volatile" if threads are being
+// used, and the empty string otherwise.
+
+
+// User-settable macros that control compilation:
+// * __STL_USE_SGI_ALLOCATORS: if defined, then the STL will use older
+// SGI-style allocators, instead of standard-conforming allocators,
+// even if the compiler supports all of the language features needed
+// for standard-conforming allocators.
+// * __STL_NO_NAMESPACES: if defined, don't put the library in namespace
+// std, even if the compiler supports namespaces.
+// * __STL_NO_RELOPS_NAMESPACE: if defined, don't put the relational
+// operator templates (>, <=. >=, !=) in namespace std::rel_ops, even
+// if the compiler supports namespaces and partial ordering of
+// function templates.
+// * __STL_ASSERTIONS: if defined, then enable runtime checking through the
+// __stl_assert macro.
+// * _PTHREADS: if defined, use Posix threads for multithreading support.
+// * _UITHREADS:if defined, use SCO/Solaris/UI threads for multithreading
+// support
+// * _NOTHREADS: if defined, don't use any multithreading support.
+// * __STL_USE_NEW_IOSTREAMS: if defined, then the STL will use new,
+// standard-conforming iostreams (e.g. the <iosfwd> header). If not
+// defined, the STL will use old cfront-style iostreams (e.g. the
+// <iostream.h> header).
+
+// Other macros defined by this file:
+
+// * bool, true, and false, if __STL_NO_BOOL is defined.
+// * typename, as a null macro if it's not already a keyword.
+// * explicit, as a null macro if it's not already a keyword.
+// * namespace-related macros (__STD, __STL_BEGIN_NAMESPACE, etc.)
+// * exception-related macros (__STL_TRY, __STL_UNWIND, etc.)
+// * __stl_assert, either as a test or as a null macro, depending on
+// whether or not __STL_ASSERTIONS is defined.
+
+# if defined(_PTHREADS) && !defined(_NOTHREADS)
+# define __STL_PTHREADS
+# endif
+
+# if defined(_UITHREADS) && !defined(_PTHREADS) && !defined(_NOTHREADS)
+# define __STL_UITHREADS
+# endif
+
+# if defined(__sgi) && !defined(__GNUC__)
+# include <standards.h>
+# if !defined(_BOOL)
+# define __STL_NO_BOOL
+# endif
+# if defined(_MIPS_SIM) && _MIPS_SIM == _ABIO32
+# define __STL_STATIC_CONST_INIT_BUG
+# endif
+# if defined(_WCHAR_T_IS_KEYWORD)
+# define __STL_HAS_WCHAR_T
+# endif
+# if !defined(_TYPENAME_IS_KEYWORD)
+# define __STL_NEED_TYPENAME
+# endif
+# ifdef _PARTIAL_SPECIALIZATION_OF_CLASS_TEMPLATES
+# define __STL_CLASS_PARTIAL_SPECIALIZATION
+# endif
+# if (_COMPILER_VERSION >= 730) && defined(_MIPS_SIM) && _MIPS_SIM != _ABIO32
+# define __STL_FUNCTION_TMPL_PARTIAL_ORDER
+# endif
+# ifdef _MEMBER_TEMPLATES
+# define __STL_MEMBER_TEMPLATES
+# define __STL_MEMBER_TEMPLATE_CLASSES
+# endif
+# if defined(_MEMBER_TEMPLATE_KEYWORD)
+# define __STL_MEMBER_TEMPLATE_KEYWORD
+# endif
+# if defined(_STANDARD_C_PLUS_PLUS)
+# define __STL_EXPLICIT_FUNCTION_TMPL_ARGS
+# endif
+# if (_COMPILER_VERSION >= 730) && defined(_MIPS_SIM) && _MIPS_SIM != _ABIO32
+# define __STL_MEMBER_TEMPLATE_KEYWORD
+# endif
+# if defined(_MIPS_SIM) && _MIPS_SIM == _ABIO32
+# define __STL_DEFAULT_CONSTRUCTOR_BUG
+# endif
+# if !defined(_EXPLICIT_IS_KEYWORD)
+# define __STL_NEED_EXPLICIT
+# endif
+# ifdef __EXCEPTIONS
+# define __STL_USE_EXCEPTIONS
+# endif
+# if (_COMPILER_VERSION >= 721) && defined(_NAMESPACES)
+# define __STL_HAS_NAMESPACES
+# endif
+# if (_COMPILER_VERSION < 721)
+# define __STL_NO_EXCEPTION_HEADER
+# endif
+# if _COMPILER_VERSION < 730 || !defined(_STANDARD_C_PLUS_PLUS) || \
+ !defined(_NAMESPACES)
+# define __STL_NO_BAD_ALLOC
+# endif
+# if !defined(_NOTHREADS) && !defined(__STL_PTHREADS)
+# define __STL_SGI_THREADS
+# endif
+# if defined(_LONGLONG) && defined(_SGIAPI) && _SGIAPI
+# define __STL_LONG_LONG
+# endif
+# if _COMPILER_VERSION >= 730 && defined(_STANDARD_C_PLUS_PLUS)
+# define __STL_USE_NEW_IOSTREAMS
+# endif
+# if _COMPILER_VERSION >= 730 && defined(_STANDARD_C_PLUS_PLUS)
+# define __STL_CAN_THROW_RANGE_ERRORS
+# endif
+# if _COMPILER_VERSION >= 730 && defined(_STANDARD_C_PLUS_PLUS)
+# define __SGI_STL_USE_AUTO_PTR_CONVERSIONS
+# endif
+# endif
+
+
+/*
+ * Jochen Schlick '1999 - added new #defines (__STL)_UITHREADS (for
+ * providing SCO / Solaris / UI thread support)
+ * - added the necessary defines for the SCO UDK 7
+ * compiler (and its template friend behavior)
+ * - all UDK7 specific STL changes are based on the
+ * macro __USLC__ being defined
+ */
+// SCO UDK 7 compiler (UnixWare 7x, OSR 5, UnixWare 2x)
+# if defined(__USLC__)
+# define __STL_HAS_WCHAR_T
+# define __STL_CLASS_PARTIAL_SPECIALIZATION
+# define __STL_PARTIAL_SPECIALIZATION_SYNTAX
+# define __STL_FUNCTION_TMPL_PARTIAL_ORDER
+# define __STL_MEMBER_TEMPLATES
+# define __STL_MEMBER_TEMPLATE_CLASSES
+# define __STL_USE_EXCEPTIONS
+# define __STL_HAS_NAMESPACES
+# define __STL_USE_NAMESPACES
+# define __STL_LONG_LONG
+# if defined(_REENTRANT)
+# define _UITHREADS /* if UnixWare < 7.0.1 */
+# define __STL_UITHREADS
+// use the following defines instead of the UI threads defines when
+// you want to use POSIX threads
+//# define _PTHREADS /* only if UnixWare >=7.0.1 */
+//# define __STL_PTHREADS
+# endif
+# endif
+
+
+
+# ifdef __GNUC__
+# define __STL_HAS_WCHAR_T
+# define __STL_MEMBER_TEMPLATES
+# define __STL_MEMBER_TEMPLATE_CLASSES
+# define __STL_CLASS_PARTIAL_SPECIALIZATION
+# define __STL_PARTIAL_SPECIALIZATION_SYNTAX
+# define __STL_FUNCTION_TMPL_PARTIAL_ORDER
+# define __STL_EXPLICIT_FUNCTION_TMPL_ARGS
+# define __SGI_STL_USE_AUTO_PTR_CONVERSIONS
+# define __STL_HAS_NAMESPACES
+# define __STL_USE_NAMESPACES
+# define __STL_USE_EXCEPTIONS
+# define __STL_CAN_THROW_RANGE_ERRORS
+# define __STL_USE_STD_ALLOCATORS
+# define __USE_MALLOC // As the "underlying allocator"
+//# define __STL_USE_NEW_IOSTREAMS //990209 bkoz--use standard .h includes.
+# ifdef _REENTRANT
+# define __STL_THREADS
+# endif
+# ifdef _PTHREADS
+# define __STL_PTHREADS
+# endif
+# ifndef __STRICT_ANSI__
+# define __STL_LONG_LONG
+# endif
+# endif
+
+# if defined(__SUNPRO_CC)
+# define __STL_NO_BOOL
+# define __STL_NEED_TYPENAME
+# define __STL_NEED_EXPLICIT
+# define __STL_USE_EXCEPTIONS
+# ifdef _REENTRANT
+# define __STL_PTHREADS
+# endif
+# define __SGI_STL_NO_ARROW_OPERATOR
+# define __STL_PARTIAL_SPECIALIZATION_SYNTAX
+# define __STL_NO_EXCEPTION_HEADER
+# define __STL_NO_BAD_ALLOC
+# endif
+
+# if defined(__COMO__)
+# define __STL_MEMBER_TEMPLATES
+# define __STL_MEMBER_TEMPLATE_CLASSES
+# define __STL_CLASS_PARTIAL_SPECIALIZATION
+# define __STL_USE_EXCEPTIONS
+# define __STL_HAS_NAMESPACES
+# endif
+
+// Intel compiler, which uses the EDG front end.
+# if defined(__ICL)
+# define __STL_LONG_LONG
+# define __STL_MEMBER_TEMPLATES
+# define __STL_MEMBER_TEMPLATE_CLASSES
+# define __STL_FUNCTION_TMPL_PARTIAL_ORDER
+# define __STL_CLASS_PARTIAL_SPECIALIZATION
+# define __STL_NO_DRAND48
+# define __STL_HAS_NAMESPACES
+# define __STL_USE_EXCEPTIONS
+# define __STL_MEMBER_TEMPLATE_KEYWORD
+# ifdef _CPPUNWIND
+# define __STL_USE_EXCEPTIONS
+# endif
+# ifdef _MT
+# define __STL_WIN32THREADS
+# endif
+# endif
+
+// Mingw32, EGCS compiler using the Microsoft C runtime
+# if defined(__MINGW32__)
+# define __STL_NO_DRAND48
+# endif
+
+// Microsoft compiler.
+# if defined(_MSC_VER) && !defined(__ICL)
+# define __STL_NO_DRAND48
+# define __STL_STATIC_CONST_INIT_BUG
+# define __STL_NEED_TYPENAME
+# if _MSC_VER < 1100 /* 1000 is version 4.0, 1100 is 5.0, 1200 is 6.0. */
+# define __STL_NEED_EXPLICIT
+# define __STL_NO_BOOL
+# endif
+# if _MSC_VER > 1000
+# include <yvals.h>
+# define __STL_DONT_USE_BOOL_TYPEDEF
+# endif
+# define __STL_NON_TYPE_TMPL_PARAM_BUG
+# define __SGI_STL_NO_ARROW_OPERATOR
+# define __STL_DEFAULT_CONSTRUCTOR_BUG
+# ifdef _CPPUNWIND
+# define __STL_USE_EXCEPTIONS
+# endif
+# ifdef _MT
+# define __STL_WIN32THREADS
+# endif
+# if _MSC_VER >= 1200
+# define __STL_PARTIAL_SPECIALIZATION_SYNTAX
+# define __STL_HAS_NAMESPACES
+# define __STL_NO_NAMESPACES
+# define __STL_CAN_THROW_RANGE_ERRORS
+# endif
+# if _MSC_VER < 1100
+# define __STL_NO_EXCEPTION_HEADER
+# define __STL_NO_BAD_ALLOC
+# endif
+ // Because of a Microsoft front end bug, we must not provide a
+ // namespace qualifier when declaring a friend function.
+# define __STD_QUALIFIER
+# endif
+
+# if defined(__BORLANDC__)
+# define __STL_NO_BAD_ALLOC
+# define __STL_NO_DRAND48
+# define __STL_NEED_TYPENAME
+# define __STL_LIMITED_DEFAULT_TEMPLATES
+# define __SGI_STL_NO_ARROW_OPERATOR
+# define __STL_DEFAULT_CONSTRUCTOR_BUG
+# define __STL_NON_TYPE_TMPL_PARAM_BUG
+# ifdef _CPPUNWIND
+# define __STL_USE_EXCEPTIONS
+# endif
+# ifdef __MT__
+# define __STL_WIN32THREADS
+# endif
+# endif
+
+# if defined(__STL_NO_BOOL) && !defined(__STL_DONT_USE_BOOL_TYPEDEF)
+ typedef int bool;
+# define true 1
+# define false 0
+# endif
+
+# ifdef __STL_NEED_TYPENAME
+# define typename
+# endif
+
+# ifdef __STL_MEMBER_TEMPLATE_KEYWORD
+# define __STL_TEMPLATE template
+# else
+# define __STL_TEMPLATE
+# endif
+
+# ifdef __STL_NEED_EXPLICIT
+# define explicit
+# endif
+
+# ifdef __STL_EXPLICIT_FUNCTION_TMPL_ARGS
+# define __STL_NULL_TMPL_ARGS <>
+# else
+# define __STL_NULL_TMPL_ARGS
+# endif
+
+# if defined(__STL_CLASS_PARTIAL_SPECIALIZATION) \
+ || defined (__STL_PARTIAL_SPECIALIZATION_SYNTAX)
+# define __STL_TEMPLATE_NULL template<>
+# else
+# define __STL_TEMPLATE_NULL
+# endif
+
+// Use standard-conforming allocators if we have the necessary language
+// features. __STL_USE_SGI_ALLOCATORS is a hook so that users can
+// disable new-style allocators, and continue to use the same kind of
+// allocators as before, without having to edit library headers.
+# if defined(__STL_CLASS_PARTIAL_SPECIALIZATION) && \
+ defined(__STL_MEMBER_TEMPLATES) && \
+ defined(__STL_MEMBER_TEMPLATE_CLASSES) && \
+ !defined(__STL_NO_BOOL) && \
+ !defined(__STL_NON_TYPE_TMPL_PARAM_BUG) && \
+ !defined(__STL_LIMITED_DEFAULT_TEMPLATES) && \
+ !defined(__STL_USE_SGI_ALLOCATORS)
+# define __STL_USE_STD_ALLOCATORS
+# endif
+
+// __STL_NO_NAMESPACES is a hook so that users can disable namespaces
+// without having to edit library headers. __STL_NO_RELOPS_NAMESPACE is
+// a hook so that users can disable the std::rel_ops namespace, keeping
+// the relational operator template in namespace std, without having to
+// edit library headers.
+# if defined(__STL_HAS_NAMESPACES) && !defined(__STL_NO_NAMESPACES)
+# define __STL_USE_NAMESPACES
+# define __STD std
+# define __STL_BEGIN_NAMESPACE namespace std {
+# define __STL_END_NAMESPACE }
+# if defined(__STL_FUNCTION_TMPL_PARTIAL_ORDER) && \
+ !defined(__STL_NO_RELOPS_NAMESPACE)
+# define __STL_USE_NAMESPACE_FOR_RELOPS
+# define __STL_BEGIN_RELOPS_NAMESPACE namespace std { namespace rel_ops {
+# define __STL_END_RELOPS_NAMESPACE } }
+# define __STD_RELOPS std::rel_ops
+# else /* Use std::rel_ops namespace */
+# define __STL_USE_NAMESPACE_FOR_RELOPS
+# define __STL_BEGIN_RELOPS_NAMESPACE namespace std {
+# define __STL_END_RELOPS_NAMESPACE }
+# define __STD_RELOPS std
+# endif /* Use std::rel_ops namespace */
+# else
+# define __STD
+# define __STL_BEGIN_NAMESPACE
+# define __STL_END_NAMESPACE
+# undef __STL_USE_NAMESPACE_FOR_RELOPS
+# define __STL_BEGIN_RELOPS_NAMESPACE
+# define __STL_END_RELOPS_NAMESPACE
+# define __STD_RELOPS
+# undef __STL_USE_NAMESPACES
+# endif
+
+// Some versions of the EDG front end sometimes require an explicit
+// namespace spec where they shouldn't. This macro facilitates that.
+// If the bug becomes irrelevant, then all uses of __STD_QUALIFIER
+// should be removed. The 7.3 beta SGI compiler has this bug, but the
+// MR version is not expected to have it.
+
+# if defined(__STL_USE_NAMESPACES) && !defined(__STD_QUALIFIER)
+# define __STD_QUALIFIER std::
+# else
+# define __STD_QUALIFIER
+# endif
+
+# ifdef __STL_USE_EXCEPTIONS
+# define __STL_TRY try
+# define __STL_CATCH_ALL catch(...)
+# define __STL_THROW(x) throw x
+# define __STL_RETHROW throw
+# define __STL_NOTHROW throw()
+# define __STL_UNWIND(action) catch(...) { action; throw; }
+# else
+# define __STL_TRY
+# define __STL_CATCH_ALL if (false)
+# define __STL_THROW(x)
+# define __STL_RETHROW
+# define __STL_NOTHROW
+# define __STL_UNWIND(action)
+# endif
+
+#ifdef __STL_ASSERTIONS
+# include <stdio.h>
+# define __stl_assert(expr) \
+ if (!(expr)) { fprintf(stderr, "%s:%d STL assertion failure: %s\n", \
+ __FILE__, __LINE__, # expr); abort(); }
+#else
+# define __stl_assert(expr)
+#endif
+
+#if defined(__STL_WIN32THREADS) || defined(STL_SGI_THREADS) \
+ || defined(__STL_PTHREADS) || defined(__STL_UITHREADS)
+# define __STL_THREADS
+# define __STL_VOLATILE volatile
+#else
+# define __STL_VOLATILE
+#endif
+
+#endif /* __STL_CONFIG_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_construct.h b/libstdc++-v3/bits/stl_construct.h
new file mode 100644
index 0000000..b77bf15
--- /dev/null
+++ b/libstdc++-v3/bits/stl_construct.h
@@ -0,0 +1,90 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef _CPP_BITS_STL_CONSTRUCT_H
+#define _CPP_BITS_STL_CONSTRUCT_H 1
+
+#include <bits/std_new.h>
+
+__STL_BEGIN_NAMESPACE
+
+// construct and destroy. These functions are not part of the C++ standard,
+// and are provided for backward compatibility with the HP STL.
+
+template <class _Tp>
+inline void destroy(_Tp* __pointer) {
+ __pointer->_Tp::~_Tp();
+}
+
+template <class _Tp1, class _Tp2>
+inline void construct(_Tp1* __p, const _Tp2& __value) {
+ new (__p) _Tp1(__value);
+}
+
+template <class _Tp1>
+inline void construct(_Tp1* __p) {
+ new (__p) _Tp1();
+}
+
+template <class _ForwardIterator>
+void
+__destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type)
+{
+ for ( ; __first != __last; ++__first)
+ destroy(&*__first);
+}
+
+template <class _ForwardIterator>
+inline void __destroy_aux(_ForwardIterator, _ForwardIterator, __true_type) {}
+
+template <class _ForwardIterator, class _Tp>
+inline void
+__destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*)
+{
+ typedef typename __type_traits<_Tp>::has_trivial_destructor
+ _Trivial_destructor;
+ __destroy_aux(__first, __last, _Trivial_destructor());
+}
+
+template <class _ForwardIterator>
+inline void destroy(_ForwardIterator __first, _ForwardIterator __last) {
+ __destroy(__first, __last, __VALUE_TYPE(__first));
+}
+
+inline void destroy(char*, char*) {}
+inline void destroy(wchar_t*, wchar_t*) {}
+
+__STL_END_NAMESPACE
+
+#endif /* _CPP_BITS_STL_CONSTRUCT_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_deque.h b/libstdc++-v3/bits/stl_deque.h
new file mode 100644
index 0000000..4b0d20b
--- /dev/null
+++ b/libstdc++-v3/bits/stl_deque.h
@@ -0,0 +1,1768 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_DEQUE_H
+#define __SGI_STL_INTERNAL_DEQUE_H
+
+/* Class invariants:
+ * For any nonsingular iterator i:
+ * i.node is the address of an element in the map array. The
+ * contents of i.node is a pointer to the beginning of a node.
+ * i.first == *(i.node)
+ * i.last == i.first + node_size
+ * i.cur is a pointer in the range [i.first, i.last). NOTE:
+ * the implication of this is that i.cur is always a dereferenceable
+ * pointer, even if i is a past-the-end iterator.
+ * Start and Finish are always nonsingular iterators. NOTE: this means
+ * that an empty deque must have one node, and that a deque
+ * with N elements, where N is the buffer size, must have two nodes.
+ * For every node other than start.node and finish.node, every element
+ * in the node is an initialized object. If start.node == finish.node,
+ * then [start.cur, finish.cur) are initialized objects, and
+ * the elements outside that range are uninitialized storage. Otherwise,
+ * [start.cur, start.last) and [finish.first, finish.cur) are initialized
+ * objects, and [start.first, start.cur) and [finish.cur, finish.last)
+ * are uninitialized storage.
+ * [map, map + map_size) is a valid, non-empty range.
+ * [start.node, finish.node] is a valid range contained within
+ * [map, map + map_size).
+ * A pointer in the range [map, map + map_size) points to an allocated node
+ * if and only if the pointer is in the range [start.node, finish.node].
+ */
+
+
+/*
+ * In previous versions of deque, node_size was fixed by the
+ * implementation. In this version, however, users can select
+ * the node size. Deque has three template parameters; the third,
+ * a number of type size_t, is the number of elements per node.
+ * If the third template parameter is 0 (which is the default),
+ * then deque will use a default node size.
+ *
+ * The only reason for using an alternate node size is if your application
+ * requires a different performance tradeoff than the default. If,
+ * for example, your program contains many deques each of which contains
+ * only a few elements, then you might want to save memory (possibly
+ * by sacrificing some speed) by using smaller nodes.
+ *
+ * Unfortunately, some compilers have trouble with non-type template
+ * parameters; stl_config.h defines __STL_NON_TYPE_TMPL_PARAM_BUG if
+ * that is the case. If your compiler is one of them, then you will
+ * not be able to use alternate node sizes; you will have to use the
+ * default value.
+ */
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1174
+#pragma set woff 1375
+#endif
+
+// Note: this function is simply a kludge to work around several compilers'
+// bugs in handling constant expressions.
+inline size_t
+__deque_buf_size(size_t __n, size_t __size)
+{
+ return __n != 0 ? __n : (__size < 512 ? size_t(512 / __size) : size_t(1));
+}
+
+#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
+template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz>
+struct _Deque_iterator {
+ typedef _Deque_iterator<_Tp,_Tp&,_Tp*,__bufsiz> iterator;
+ typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*,__bufsiz> const_iterator;
+ static size_t
+ _S_buffer_size() { return __deque_buf_size(__bufsiz, sizeof(_Tp)); }
+#else /* __STL_NON_TYPE_TMPL_PARAM_BUG */
+template <class _Tp, class _Ref, class _Ptr>
+struct _Deque_iterator {
+ typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator;
+ typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
+ static size_t
+ _S_buffer_size() { return __deque_buf_size(0, sizeof(_Tp)); }
+#endif
+
+ typedef random_access_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef _Ptr pointer;
+ typedef _Ref reference;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef _Tp** _Map_pointer;
+
+ typedef _Deque_iterator _Self;
+
+ _Tp* _M_cur;
+ _Tp* _M_first;
+ _Tp* _M_last;
+ _Map_pointer _M_node;
+
+ _Deque_iterator(_Tp* __x, _Map_pointer __y)
+ : _M_cur(__x), _M_first(*__y),
+ _M_last(*__y + _S_buffer_size()), _M_node(__y) {}
+ _Deque_iterator() : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) {}
+ _Deque_iterator(const iterator& __x)
+ : _M_cur(__x._M_cur), _M_first(__x._M_first),
+ _M_last(__x._M_last), _M_node(__x._M_node) {}
+
+ reference operator*() const { return *_M_cur; }
+#ifndef __SGI_STL_NO_ARROW_OPERATOR
+ pointer operator->() const { return _M_cur; }
+#endif /* __SGI_STL_NO_ARROW_OPERATOR */
+
+ difference_type operator-(const _Self& __x) const {
+ return difference_type(_S_buffer_size()) * (_M_node - __x._M_node - 1) +
+ (_M_cur - _M_first) + (__x._M_last - __x._M_cur);
+ }
+
+ _Self& operator++() {
+ ++_M_cur;
+ if (_M_cur == _M_last) {
+ _M_set_node(_M_node + 1);
+ _M_cur = _M_first;
+ }
+ return *this;
+ }
+ _Self operator++(int) {
+ _Self __tmp = *this;
+ ++*this;
+ return __tmp;
+ }
+
+ _Self& operator--() {
+ if (_M_cur == _M_first) {
+ _M_set_node(_M_node - 1);
+ _M_cur = _M_last;
+ }
+ --_M_cur;
+ return *this;
+ }
+ _Self operator--(int) {
+ _Self __tmp = *this;
+ --*this;
+ return __tmp;
+ }
+
+ _Self& operator+=(difference_type __n)
+ {
+ difference_type __offset = __n + (_M_cur - _M_first);
+ if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
+ _M_cur += __n;
+ else {
+ difference_type __node_offset =
+ __offset > 0 ? __offset / difference_type(_S_buffer_size())
+ : -difference_type((-__offset - 1) / _S_buffer_size()) - 1;
+ _M_set_node(_M_node + __node_offset);
+ _M_cur = _M_first +
+ (__offset - __node_offset * difference_type(_S_buffer_size()));
+ }
+ return *this;
+ }
+
+ _Self operator+(difference_type __n) const
+ {
+ _Self __tmp = *this;
+ return __tmp += __n;
+ }
+
+ _Self& operator-=(difference_type __n) { return *this += -__n; }
+
+ _Self operator-(difference_type __n) const {
+ _Self __tmp = *this;
+ return __tmp -= __n;
+ }
+
+ reference operator[](difference_type __n) const { return *(*this + __n); }
+
+ bool operator==(const _Self& __x) const { return _M_cur == __x._M_cur; }
+ bool operator!=(const _Self& __x) const { return !(*this == __x); }
+ bool operator<(const _Self& __x) const {
+ return (_M_node == __x._M_node) ?
+ (_M_cur < __x._M_cur) : (_M_node < __x._M_node);
+ }
+ bool operator>(const _Self& __x) const { return __x < *this; }
+ bool operator<=(const _Self& __x) const { return !(__x < *this); }
+ bool operator>=(const _Self& __x) const { return !(*this < __x); }
+
+ void _M_set_node(_Map_pointer __new_node) {
+ _M_node = __new_node;
+ _M_first = *__new_node;
+ _M_last = _M_first + difference_type(_S_buffer_size());
+ }
+};
+
+#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
+
+template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz>
+inline random_access_iterator_tag
+iterator_category(const _Deque_iterator<_Tp,_Ref,_Ptr,__bufsiz>&) {
+ return random_access_iterator_tag();
+}
+
+template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz>
+inline _Tp*
+value_type(const _Deque_iterator<_Tp,_Ref,_Ptr,__bufsiz>&) {
+ return 0;
+}
+
+template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz>
+inline ptrdiff_t*
+distance_type(const _Deque_iterator<_Tp,_Ref,_Ptr,__bufsiz>&) {
+ return 0;
+}
+
+#else /* __STL_NON_TYPE_TMPL_PARAM_BUG */
+
+template <class _Tp, class _Ref, class _Ptr>
+inline random_access_iterator_tag
+iterator_category(const _Deque_iterator<_Tp,_Ref,_Ptr>&)
+{
+ return random_access_iterator_tag();
+}
+
+template <class _Tp, class _Ref, class _Ptr>
+inline _Tp*
+value_type(const _Deque_iterator<_Tp,_Ref,_Ptr>&) { return 0; }
+
+template <class _Tp, class _Ref, class _Ptr>
+inline ptrdiff_t*
+distance_type(const _Deque_iterator<_Tp,_Ref,_Ptr>&) {
+ return 0;
+}
+
+#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+// Deque base class. It has two purposes. First, its constructor
+// and destructor allocate (but don't initialize) storage. This makes
+// exception safety easier. Second, the base class encapsulates all of
+// the differences between SGI-style allocators and standard-conforming
+// allocators.
+
+#ifdef __STL_USE_STD_ALLOCATORS
+
+// Base class for ordinary allocators.
+template <class _Tp, class _Alloc, size_t __bufsiz, bool __is_static>
+class _Deque_alloc_base {
+public:
+ typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type;
+ allocator_type get_allocator() const { return _M_node_allocator; }
+
+ _Deque_alloc_base(const allocator_type& __a)
+ : _M_node_allocator(__a), _M_map_allocator(__a),
+ _M_map(0), _M_map_size(0)
+ {}
+
+protected:
+ typedef typename _Alloc_traits<_Tp*, _Alloc>::allocator_type
+ _Map_allocator_type;
+
+ allocator_type _M_node_allocator;
+ _Map_allocator_type _M_map_allocator;
+
+ _Tp* _M_allocate_node() {
+ return _M_node_allocator.allocate(__deque_buf_size(__bufsiz,sizeof(_Tp)));
+ }
+ void _M_deallocate_node(_Tp* __p) {
+ _M_node_allocator.deallocate(__p, __deque_buf_size(__bufsiz,sizeof(_Tp)));
+ }
+ _Tp** _M_allocate_map(size_t __n)
+ { return _M_map_allocator.allocate(__n); }
+ void _M_deallocate_map(_Tp** __p, size_t __n)
+ { _M_map_allocator.deallocate(__p, __n); }
+
+ _Tp** _M_map;
+ size_t _M_map_size;
+};
+
+// Specialization for instanceless allocators.
+template <class _Tp, class _Alloc, size_t __bufsiz>
+class _Deque_alloc_base<_Tp, _Alloc, __bufsiz, true>
+{
+public:
+ typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type;
+ allocator_type get_allocator() const { return allocator_type(); }
+
+ _Deque_alloc_base(const allocator_type&) : _M_map(0), _M_map_size(0) {}
+
+protected:
+ typedef typename _Alloc_traits<_Tp, _Alloc>::_Alloc_type _Node_alloc_type;
+ typedef typename _Alloc_traits<_Tp*, _Alloc>::_Alloc_type _Map_alloc_type;
+
+ _Tp* _M_allocate_node() {
+ return _Node_alloc_type::allocate(__deque_buf_size(__bufsiz,
+ sizeof(_Tp)));
+ }
+ void _M_deallocate_node(_Tp* __p) {
+ _Node_alloc_type::deallocate(__p, __deque_buf_size(__bufsiz,
+ sizeof(_Tp)));
+ }
+ _Tp** _M_allocate_map(size_t __n)
+ { return _Map_alloc_type::allocate(__n); }
+ void _M_deallocate_map(_Tp** __p, size_t __n)
+ { _Map_alloc_type::deallocate(__p, __n); }
+
+ _Tp** _M_map;
+ size_t _M_map_size;
+};
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+class _Deque_base
+ : public _Deque_alloc_base<_Tp,_Alloc,__bufsiz,
+ _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
+{
+public:
+ typedef _Deque_alloc_base<_Tp,_Alloc,__bufsiz,
+ _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
+ _Base;
+ typedef typename _Base::allocator_type allocator_type;
+ typedef _Deque_iterator<_Tp,_Tp&,_Tp*,__bufsiz> iterator;
+ typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*, __bufsiz> const_iterator;
+
+ _Deque_base(const allocator_type& __a, size_t __num_elements)
+ : _Base(__a), _M_start(), _M_finish()
+ { _M_initialize_map(__num_elements); }
+ _Deque_base(const allocator_type& __a)
+ : _Base(__a), _M_start(), _M_finish() {}
+ ~_Deque_base();
+
+protected:
+ void _M_initialize_map(size_t);
+ void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
+ void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish);
+ enum { _S_initial_map_size = 8 };
+
+protected:
+ iterator _M_start;
+ iterator _M_finish;
+};
+
+#else /* __STL_USE_STD_ALLOCATORS */
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+class _Deque_base {
+public:
+#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
+ typedef _Deque_iterator<_Tp,_Tp&,_Tp*,__bufsiz> iterator;
+ typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*, __bufsiz> const_iterator;
+#else /* __STL_NON_TYPE_TMPL_PARAM_BUG */
+ typedef _Deque_iterator<_Tp,_Tp&,_Tp*> iterator;
+ typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*> const_iterator;
+#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
+
+ typedef _Alloc allocator_type;
+ allocator_type get_allocator() const { return allocator_type(); }
+
+ _Deque_base(const allocator_type&, size_t __num_elements)
+ : _M_map(0), _M_map_size(0), _M_start(), _M_finish() {
+ _M_initialize_map(__num_elements);
+ }
+ _Deque_base(const allocator_type&)
+ : _M_map(0), _M_map_size(0), _M_start(), _M_finish() {}
+ ~_Deque_base();
+
+protected:
+ void _M_initialize_map(size_t);
+ void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
+ void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish);
+ enum { _S_initial_map_size = 8 };
+
+protected:
+ _Tp** _M_map;
+ size_t _M_map_size;
+ iterator _M_start;
+ iterator _M_finish;
+
+ typedef simple_alloc<_Tp, _Alloc> _Node_alloc_type;
+ typedef simple_alloc<_Tp*, _Alloc> _Map_alloc_type;
+
+ _Tp* _M_allocate_node()
+ { return _Node_alloc_type::allocate(__deque_buf_size(__bufsiz,
+ sizeof(_Tp))); }
+ void _M_deallocate_node(_Tp* __p)
+ { _Node_alloc_type::deallocate(__p, __deque_buf_size(__bufsiz,
+ sizeof(_Tp))); }
+ _Tp** _M_allocate_map(size_t __n)
+ { return _Map_alloc_type::allocate(__n); }
+ void _M_deallocate_map(_Tp** __p, size_t __n)
+ { _Map_alloc_type::deallocate(__p, __n); }
+};
+
+#endif /* __STL_USE_STD_ALLOCATORS */
+
+// Non-inline member functions from _Deque_base.
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+_Deque_base<_Tp,_Alloc,__bufsiz>::~_Deque_base() {
+ if (_M_map) {
+ _M_destroy_nodes(_M_start._M_node, _M_finish._M_node + 1);
+ _M_deallocate_map(_M_map, _M_map_size);
+ }
+}
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+void
+_Deque_base<_Tp,_Alloc,__bufsiz>::_M_initialize_map(size_t __num_elements)
+{
+ size_t __num_nodes =
+ __num_elements / __deque_buf_size(__bufsiz, sizeof(_Tp)) + 1;
+
+ _M_map_size = max((size_t) _S_initial_map_size, __num_nodes + 2);
+ _M_map = _M_allocate_map(_M_map_size);
+
+ _Tp** __nstart = _M_map + (_M_map_size - __num_nodes) / 2;
+ _Tp** __nfinish = __nstart + __num_nodes;
+
+ __STL_TRY {
+ _M_create_nodes(__nstart, __nfinish);
+ }
+ __STL_UNWIND((_M_deallocate_map(_M_map, _M_map_size),
+ _M_map = 0, _M_map_size = 0));
+ _M_start._M_set_node(__nstart);
+ _M_finish._M_set_node(__nfinish - 1);
+ _M_start._M_cur = _M_start._M_first;
+ _M_finish._M_cur = _M_finish._M_first +
+ __num_elements % __deque_buf_size(__bufsiz, sizeof(_Tp));
+}
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+void
+_Deque_base<_Tp,_Alloc,__bufsiz>::_M_create_nodes(_Tp** __nstart,
+ _Tp** __nfinish)
+{
+ _Tp** __cur;
+ __STL_TRY {
+ for (__cur = __nstart; __cur < __nfinish; ++__cur)
+ *__cur = _M_allocate_node();
+ }
+ __STL_UNWIND(_M_destroy_nodes(__nstart, __cur));
+}
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+void
+_Deque_base<_Tp,_Alloc,__bufsiz>::_M_destroy_nodes(_Tp** __nstart,
+ _Tp** __nfinish)
+{
+ for (_Tp** __n = __nstart; __n < __nfinish; ++__n)
+ _M_deallocate_node(*__n);
+}
+
+// See __deque_buf_size(). The only reason that the default value is 0
+// is as a workaround for bugs in the way that some compilers handle
+// constant expressions.
+template <class _Tp, class _Alloc = allocator<_Tp>,
+ size_t __bufsiz = 0>
+class deque : protected _Deque_base<_Tp, _Alloc, __bufsiz> {
+ typedef _Deque_base<_Tp, _Alloc, __bufsiz> _Base;
+public: // Basic types
+ typedef _Tp value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+
+ typedef typename _Base::allocator_type allocator_type;
+ allocator_type get_allocator() const { return _Base::get_allocator(); }
+
+public: // Iterators
+ typedef typename _Base::iterator iterator;
+ typedef typename _Base::const_iterator const_iterator;
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+ typedef reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef reverse_iterator<iterator> reverse_iterator;
+#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+ typedef reverse_iterator<const_iterator, value_type, const_reference,
+ difference_type>
+ const_reverse_iterator;
+ typedef reverse_iterator<iterator, value_type, reference, difference_type>
+ reverse_iterator;
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+protected: // Internal typedefs
+ typedef pointer* _Map_pointer;
+ static size_t _S_buffer_size()
+ { return __deque_buf_size(__bufsiz, sizeof(_Tp)); }
+
+protected:
+#ifdef __STL_USE_NAMESPACES
+ using _Base::_M_initialize_map;
+ using _Base::_M_create_nodes;
+ using _Base::_M_destroy_nodes;
+ using _Base::_M_allocate_node;
+ using _Base::_M_deallocate_node;
+ using _Base::_M_allocate_map;
+ using _Base::_M_deallocate_map;
+
+ using _Base::_M_map;
+ using _Base::_M_map_size;
+ using _Base::_M_start;
+ using _Base::_M_finish;
+#endif /* __STL_USE_NAMESPACES */
+
+public: // Basic accessors
+ iterator begin() { return _M_start; }
+ iterator end() { return _M_finish; }
+ const_iterator begin() const { return _M_start; }
+ const_iterator end() const { return _M_finish; }
+
+ reverse_iterator rbegin() { return reverse_iterator(_M_finish); }
+ reverse_iterator rend() { return reverse_iterator(_M_start); }
+ const_reverse_iterator rbegin() const
+ { return const_reverse_iterator(_M_finish); }
+ const_reverse_iterator rend() const
+ { return const_reverse_iterator(_M_start); }
+
+ reference operator[](size_type __n)
+ { return _M_start[difference_type(__n)]; }
+ const_reference operator[](size_type __n) const
+ { return _M_start[difference_type(__n)]; }
+
+#ifdef __STL_THROW_RANGE_ERRORS
+ void _M_range_check(size_type __n) const {
+ if (__n >= this->size())
+ __stl_throw_range_error("deque");
+ }
+
+ reference at(size_type __n)
+ { _M_range_check(__n); return (*this)[__n]; }
+ const_reference at(size_type __n) const
+ { _M_range_check(__n); return (*this)[__n]; }
+#endif /* __STL_THROW_RANGE_ERRORS */
+
+ reference front() { return *_M_start; }
+ reference back() {
+ iterator __tmp = _M_finish;
+ --__tmp;
+ return *__tmp;
+ }
+ const_reference front() const { return *_M_start; }
+ const_reference back() const {
+ const_iterator __tmp = _M_finish;
+ --__tmp;
+ return *__tmp;
+ }
+
+ size_type size() const { return _M_finish - _M_start; }
+ size_type max_size() const { return size_type(-1); }
+ bool empty() const { return _M_finish == _M_start; }
+
+public: // Constructor, destructor.
+ explicit deque(const allocator_type& __a = allocator_type())
+ : _Base(__a, 0) {}
+ deque(const deque& __x) : _Base(__x.get_allocator(), __x.size())
+ { uninitialized_copy(__x.begin(), __x.end(), _M_start); }
+ deque(size_type __n, const value_type& __value,
+ const allocator_type& __a = allocator_type()) : _Base(__a, __n)
+ { _M_fill_initialize(__value); }
+ explicit deque(size_type __n) : _Base(allocator_type(), __n)
+ { _M_fill_initialize(value_type()); }
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+ // Check whether it's an integral type. If so, it's not an iterator.
+ template <class _InputIterator>
+ deque(_InputIterator __first, _InputIterator __last,
+ const allocator_type& __a = allocator_type()) : _Base(__a) {
+ typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
+ _M_initialize_dispatch(__first, __last, _Integral());
+ }
+
+ template <class _Integer>
+ void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) {
+ _M_initialize_map(__n);
+ _M_fill_initialize(__x);
+ }
+
+ template <class _InputIter>
+ void _M_initialize_dispatch(_InputIter __first, _InputIter __last,
+ __false_type) {
+ _M_range_initialize(__first, __last, __ITERATOR_CATEGORY(__first));
+ }
+
+#else /* __STL_MEMBER_TEMPLATES */
+
+ deque(const value_type* __first, const value_type* __last,
+ const allocator_type& __a = allocator_type())
+ : _Base(__a, __last - __first)
+ { uninitialized_copy(__first, __last, _M_start); }
+ deque(const_iterator __first, const_iterator __last,
+ const allocator_type& __a = allocator_type())
+ : _Base(__a, __last - __first)
+ { uninitialized_copy(__first, __last, _M_start); }
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ ~deque() { destroy(_M_start, _M_finish); }
+
+ deque& operator= (const deque& __x) {
+ const size_type __len = size();
+ if (&__x != this) {
+ if (__len >= __x.size())
+ erase(copy(__x.begin(), __x.end(), _M_start), _M_finish);
+ else {
+ const_iterator __mid = __x.begin() + difference_type(__len);
+ copy(__x.begin(), __mid, _M_start);
+ insert(_M_finish, __mid, __x.end());
+ }
+ }
+ return *this;
+ }
+
+ void swap(deque& __x) {
+ __STD::swap(_M_start, __x._M_start);
+ __STD::swap(_M_finish, __x._M_finish);
+ __STD::swap(_M_map, __x._M_map);
+ __STD::swap(_M_map_size, __x._M_map_size);
+ }
+
+public:
+ // assign(), a generalized assignment member function. Two
+ // versions: one that takes a count, and one that takes a range.
+ // The range version is a member template, so we dispatch on whether
+ // or not the type is an integer.
+
+ void _M_fill_assign(size_type __n, const _Tp& __val) {
+ if (__n > size()) {
+ fill(begin(), end(), __val);
+ insert(end(), __n - size(), __val);
+ }
+ else {
+ erase(begin() + __n, end());
+ fill(begin(), end(), __val);
+ }
+ }
+
+ void assign(size_type __n, const _Tp& __val) {
+ _M_fill_assign(__n, __val);
+ }
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+ template <class _InputIterator>
+ void assign(_InputIterator __first, _InputIterator __last) {
+ typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
+ _M_assign_dispatch(__first, __last, _Integral());
+ }
+
+private: // helper functions for assign()
+
+ template <class _Integer>
+ void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
+ { _M_fill_assign((size_type) __n, (_Tp) __val); }
+
+ template <class _InputIterator>
+ void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
+ __false_type) {
+ _M_assign_aux(__first, __last, __ITERATOR_CATEGORY(__first));
+ }
+
+ template <class _InputIterator>
+ void _M_assign_aux(_InputIterator __first, _InputIterator __last,
+ input_iterator_tag);
+
+ template <class _ForwardIterator>
+ void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
+ forward_iterator_tag) {
+ size_type __len = 0;
+ distance(__first, __last, __len);
+ if (__len > size()) {
+ _ForwardIterator __mid = __first;
+ advance(__mid, size());
+ copy(__first, __mid, begin());
+ insert(end(), __mid, __last);
+ }
+ else
+ erase(copy(__first, __last, begin()), end());
+ }
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+public: // push_* and pop_*
+
+ void push_back(const value_type& __t) {
+ if (_M_finish._M_cur != _M_finish._M_last - 1) {
+ construct(_M_finish._M_cur, __t);
+ ++_M_finish._M_cur;
+ }
+ else
+ _M_push_back_aux(__t);
+ }
+
+ void push_back() {
+ if (_M_finish._M_cur != _M_finish._M_last - 1) {
+ construct(_M_finish._M_cur);
+ ++_M_finish._M_cur;
+ }
+ else
+ _M_push_back_aux();
+ }
+
+ void push_front(const value_type& __t) {
+ if (_M_start._M_cur != _M_start._M_first) {
+ construct(_M_start._M_cur - 1, __t);
+ --_M_start._M_cur;
+ }
+ else
+ _M_push_front_aux(__t);
+ }
+
+ void push_front() {
+ if (_M_start._M_cur != _M_start._M_first) {
+ construct(_M_start._M_cur - 1);
+ --_M_start._M_cur;
+ }
+ else
+ _M_push_front_aux();
+ }
+
+
+ void pop_back() {
+ if (_M_finish._M_cur != _M_finish._M_first) {
+ --_M_finish._M_cur;
+ destroy(_M_finish._M_cur);
+ }
+ else
+ _M_pop_back_aux();
+ }
+
+ void pop_front() {
+ if (_M_start._M_cur != _M_start._M_last - 1) {
+ destroy(_M_start._M_cur);
+ ++_M_start._M_cur;
+ }
+ else
+ _M_pop_front_aux();
+ }
+
+public: // Insert
+
+ iterator insert(iterator position, const value_type& __x) {
+ if (position._M_cur == _M_start._M_cur) {
+ push_front(__x);
+ return _M_start;
+ }
+ else if (position._M_cur == _M_finish._M_cur) {
+ push_back(__x);
+ iterator __tmp = _M_finish;
+ --__tmp;
+ return __tmp;
+ }
+ else {
+ return _M_insert_aux(position, __x);
+ }
+ }
+
+ iterator insert(iterator __position)
+ { return insert(__position, value_type()); }
+
+ void insert(iterator __pos, size_type __n, const value_type& __x)
+ { _M_fill_insert(__pos, __n, __x); }
+
+ void _M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+ // Check whether it's an integral type. If so, it's not an iterator.
+ template <class _InputIterator>
+ void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
+ typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
+ _M_insert_dispatch(__pos, __first, __last, _Integral());
+ }
+
+ template <class _Integer>
+ void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
+ __true_type) {
+ _M_fill_insert(__pos, (size_type) __n, (value_type) __x);
+ }
+
+ template <class _InputIterator>
+ void _M_insert_dispatch(iterator __pos,
+ _InputIterator __first, _InputIterator __last,
+ __false_type) {
+ insert(__pos, __first, __last, __ITERATOR_CATEGORY(__first));
+ }
+
+#else /* __STL_MEMBER_TEMPLATES */
+
+ void insert(iterator __pos,
+ const value_type* __first, const value_type* __last);
+ void insert(iterator __pos,
+ const_iterator __first, const_iterator __last);
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ void resize(size_type __new_size, const value_type& __x) {
+ const size_type __len = size();
+ if (__new_size < __len)
+ erase(_M_start + __new_size, _M_finish);
+ else
+ insert(_M_finish, __new_size - __len, __x);
+ }
+
+ void resize(size_type new_size) { resize(new_size, value_type()); }
+
+public: // Erase
+ iterator erase(iterator __pos) {
+ iterator __next = __pos;
+ ++__next;
+ size_type __index = __pos - _M_start;
+ if (__index < (size() >> 1)) {
+ copy_backward(_M_start, __pos, __next);
+ pop_front();
+ }
+ else {
+ copy(__next, _M_finish, __pos);
+ pop_back();
+ }
+ return _M_start + __index;
+ }
+
+ iterator erase(iterator __first, iterator __last);
+ void clear();
+
+protected: // Internal construction/destruction
+
+ void _M_fill_initialize(const value_type& __value);
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+ template <class _InputIterator>
+ void _M_range_initialize(_InputIterator __first, _InputIterator __last,
+ input_iterator_tag);
+
+ template <class _ForwardIterator>
+ void _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
+ forward_iterator_tag);
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+protected: // Internal push_* and pop_*
+
+ void _M_push_back_aux(const value_type&);
+ void _M_push_back_aux();
+ void _M_push_front_aux(const value_type&);
+ void _M_push_front_aux();
+ void _M_pop_back_aux();
+ void _M_pop_front_aux();
+
+protected: // Internal insert functions
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+ template <class _InputIterator>
+ void insert(iterator __pos, _InputIterator __first, _InputIterator __last,
+ input_iterator_tag);
+
+ template <class _ForwardIterator>
+ void insert(iterator __pos,
+ _ForwardIterator __first, _ForwardIterator __last,
+ forward_iterator_tag);
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ iterator _M_insert_aux(iterator __pos, const value_type& __x);
+ iterator _M_insert_aux(iterator __pos);
+ void _M_insert_aux(iterator __pos, size_type __n, const value_type& __x);
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+ template <class _ForwardIterator>
+ void _M_insert_aux(iterator __pos,
+ _ForwardIterator __first, _ForwardIterator __last,
+ size_type __n);
+
+#else /* __STL_MEMBER_TEMPLATES */
+
+ void _M_insert_aux(iterator __pos,
+ const value_type* __first, const value_type* __last,
+ size_type __n);
+
+ void _M_insert_aux(iterator __pos,
+ const_iterator __first, const_iterator __last,
+ size_type __n);
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ iterator _M_reserve_elements_at_front(size_type __n) {
+ size_type __vacancies = _M_start._M_cur - _M_start._M_first;
+ if (__n > __vacancies)
+ _M_new_elements_at_front(__n - __vacancies);
+ return _M_start - difference_type(__n);
+ }
+
+ iterator _M_reserve_elements_at_back(size_type __n) {
+ size_type __vacancies = (_M_finish._M_last - _M_finish._M_cur) - 1;
+ if (__n > __vacancies)
+ _M_new_elements_at_back(__n - __vacancies);
+ return _M_finish + difference_type(__n);
+ }
+
+ void _M_new_elements_at_front(size_type __new_elements);
+ void _M_new_elements_at_back(size_type __new_elements);
+
+protected: // Allocation of _M_map and nodes
+
+ // Makes sure the _M_map has space for new nodes. Does not actually
+ // add the nodes. Can invalidate _M_map pointers. (And consequently,
+ // deque iterators.)
+
+ void _M_reserve_map_at_back (size_type __nodes_to_add = 1) {
+ if (__nodes_to_add + 1 > _M_map_size - (_M_finish._M_node - _M_map))
+ _M_reallocate_map(__nodes_to_add, false);
+ }
+
+ void _M_reserve_map_at_front (size_type __nodes_to_add = 1) {
+ if (__nodes_to_add > size_type(_M_start._M_node - _M_map))
+ _M_reallocate_map(__nodes_to_add, true);
+ }
+
+ void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
+
+#ifdef __STL_NON_TYPE_TMPL_PARAM_BUG
+public:
+ bool operator==(const deque<_Tp,_Alloc,0>& __x) const {
+ return size() == __x.size() && equal(begin(), end(), __x.begin());
+ }
+ bool operator!=(const deque<_Tp,_Alloc,0>& __x) const {
+ return size() != __x.size() || !equal(begin(), end(), __x.begin());
+ }
+ bool operator<(const deque<_Tp,_Alloc,0>& __x) const {
+ return lexicographical_compare(begin(), end(), __x.begin(), __x.end());
+ }
+ bool operator>(const deque<_Tp,_Alloc,0>& __x) const {
+ return __x < *this;
+ }
+ bool operator<=(const deque<_Tp,_Alloc,0>& __x) const {
+ return !(__x < *this);
+ }
+ bool operator>=(const deque<_Tp,_Alloc,0>& __x) const {
+ return !(*this < __x);
+ }
+#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
+};
+
+// Non-inline member functions
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+template <class _InputIter>
+void deque<_Tp, _Alloc, __bufsize>
+ ::_M_assign_aux(_InputIter __first, _InputIter __last, input_iterator_tag)
+{
+ iterator __cur = begin();
+ for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
+ *__cur = *__first;
+ if (__first == __last)
+ erase(__cur, end());
+ else
+ insert(end(), __first, __last);
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp, _Alloc, __bufsize>::_M_fill_insert(iterator __pos,
+ size_type __n,
+ const value_type& __x)
+{
+ if (__pos._M_cur == _M_start._M_cur) {
+ iterator __new_start = _M_reserve_elements_at_front(__n);
+ __STL_TRY {
+ uninitialized_fill(__new_start, _M_start, __x);
+ _M_start = __new_start;
+ }
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
+ }
+ else if (__pos._M_cur == _M_finish._M_cur) {
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
+ __STL_TRY {
+ uninitialized_fill(_M_finish, __new_finish, __x);
+ _M_finish = __new_finish;
+ }
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
+ __new_finish._M_node + 1));
+ }
+ else
+ _M_insert_aux(__pos, __n, __x);
+}
+
+#ifndef __STL_MEMBER_TEMPLATES
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+void deque<_Tp, _Alloc, __bufsize>::insert(iterator __pos,
+ const value_type* __first,
+ const value_type* __last) {
+ size_type __n = __last - __first;
+ if (__pos._M_cur == _M_start._M_cur) {
+ iterator __new_start = _M_reserve_elements_at_front(__n);
+ __STL_TRY {
+ uninitialized_copy(__first, __last, __new_start);
+ _M_start = __new_start;
+ }
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
+ }
+ else if (__pos._M_cur == _M_finish._M_cur) {
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
+ __STL_TRY {
+ uninitialized_copy(__first, __last, _M_finish);
+ _M_finish = __new_finish;
+ }
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
+ __new_finish._M_node + 1));
+ }
+ else
+ _M_insert_aux(__pos, __first, __last, __n);
+}
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+void deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos,
+ const_iterator __first,
+ const_iterator __last)
+{
+ size_type __n = __last - __first;
+ if (__pos._M_cur == _M_start._M_cur) {
+ iterator __new_start = _M_reserve_elements_at_front(__n);
+ __STL_TRY {
+ uninitialized_copy(__first, __last, __new_start);
+ _M_start = __new_start;
+ }
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
+ }
+ else if (__pos._M_cur == _M_finish._M_cur) {
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
+ __STL_TRY {
+ uninitialized_copy(__first, __last, _M_finish);
+ _M_finish = __new_finish;
+ }
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
+ __new_finish._M_node + 1));
+ }
+ else
+ _M_insert_aux(__pos, __first, __last, __n);
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+deque<_Tp,_Alloc,__bufsize>::iterator
+deque<_Tp,_Alloc,__bufsize>::erase(iterator __first, iterator __last)
+{
+ if (__first == _M_start && __last == _M_finish) {
+ clear();
+ return _M_finish;
+ }
+ else {
+ difference_type __n = __last - __first;
+ difference_type __elems_before = __first - _M_start;
+ if (static_cast<size_type>(__elems_before) < (size() - __n) / 2) {
+ copy_backward(_M_start, __first, __last);
+ iterator __new_start = _M_start + __n;
+ destroy(_M_start, __new_start);
+ _M_destroy_nodes(__new_start._M_node, _M_start._M_node);
+ _M_start = __new_start;
+ }
+ else {
+ copy(__last, _M_finish, __first);
+ iterator __new_finish = _M_finish - __n;
+ destroy(__new_finish, _M_finish);
+ _M_destroy_nodes(__new_finish._M_node + 1, _M_finish._M_node + 1);
+ _M_finish = __new_finish;
+ }
+ return _M_start + __elems_before;
+ }
+}
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+void deque<_Tp,_Alloc,__bufsize>::clear()
+{
+ for (_Map_pointer __node = _M_start._M_node + 1;
+ __node < _M_finish._M_node;
+ ++__node) {
+ destroy(*__node, *__node + _S_buffer_size());
+ _M_deallocate_node(*__node);
+ }
+
+ if (_M_start._M_node != _M_finish._M_node) {
+ destroy(_M_start._M_cur, _M_start._M_last);
+ destroy(_M_finish._M_first, _M_finish._M_cur);
+ _M_deallocate_node(_M_finish._M_first);
+ }
+ else
+ destroy(_M_start._M_cur, _M_finish._M_cur);
+
+ _M_finish = _M_start;
+}
+
+// Precondition: _M_start and _M_finish have already been initialized,
+// but none of the deque's elements have yet been constructed.
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_fill_initialize(const value_type& __value) {
+ _Map_pointer __cur;
+ __STL_TRY {
+ for (__cur = _M_start._M_node; __cur < _M_finish._M_node; ++__cur)
+ uninitialized_fill(*__cur, *__cur + _S_buffer_size(), __value);
+ uninitialized_fill(_M_finish._M_first, _M_finish._M_cur, __value);
+ }
+ __STL_UNWIND(destroy(_M_start, iterator(*__cur, __cur)));
+}
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+template <class _InputIterator>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_InputIterator __first,
+ _InputIterator __last,
+ input_iterator_tag)
+{
+ _M_initialize_map(0);
+ __STL_TRY {
+ for ( ; __first != __last; ++__first)
+ push_back(*__first);
+ }
+ __STL_UNWIND(clear());
+}
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+template <class _ForwardIterator>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_ForwardIterator __first,
+ _ForwardIterator __last,
+ forward_iterator_tag)
+{
+ size_type __n = 0;
+ distance(__first, __last, __n);
+ _M_initialize_map(__n);
+
+ _Map_pointer __cur_node;
+ __STL_TRY {
+ for (__cur_node = _M_start._M_node;
+ __cur_node < _M_finish._M_node;
+ ++__cur_node) {
+ _ForwardIterator __mid = __first;
+ advance(__mid, _S_buffer_size());
+ uninitialized_copy(__first, __mid, *__cur_node);
+ __first = __mid;
+ }
+ uninitialized_copy(__first, __last, _M_finish._M_first);
+ }
+ __STL_UNWIND(destroy(_M_start, iterator(*__cur_node, __cur_node)));
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+// Called only if _M_finish._M_cur == _M_finish._M_last - 1.
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_push_back_aux(const value_type& __t)
+{
+ value_type __t_copy = __t;
+ _M_reserve_map_at_back();
+ *(_M_finish._M_node + 1) = _M_allocate_node();
+ __STL_TRY {
+ construct(_M_finish._M_cur, __t_copy);
+ _M_finish._M_set_node(_M_finish._M_node + 1);
+ _M_finish._M_cur = _M_finish._M_first;
+ }
+ __STL_UNWIND(_M_deallocate_node(*(_M_finish._M_node + 1)));
+}
+
+// Called only if _M_finish._M_cur == _M_finish._M_last - 1.
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_push_back_aux()
+{
+ _M_reserve_map_at_back();
+ *(_M_finish._M_node + 1) = _M_allocate_node();
+ __STL_TRY {
+ construct(_M_finish._M_cur);
+ _M_finish._M_set_node(_M_finish._M_node + 1);
+ _M_finish._M_cur = _M_finish._M_first;
+ }
+ __STL_UNWIND(_M_deallocate_node(*(_M_finish._M_node + 1)));
+}
+
+// Called only if _M_start._M_cur == _M_start._M_first.
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_push_front_aux(const value_type& __t)
+{
+ value_type __t_copy = __t;
+ _M_reserve_map_at_front();
+ *(_M_start._M_node - 1) = _M_allocate_node();
+ __STL_TRY {
+ _M_start._M_set_node(_M_start._M_node - 1);
+ _M_start._M_cur = _M_start._M_last - 1;
+ construct(_M_start._M_cur, __t_copy);
+ }
+ __STL_UNWIND((++_M_start, _M_deallocate_node(*(_M_start._M_node - 1))));
+}
+
+// Called only if _M_start._M_cur == _M_start._M_first.
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_push_front_aux()
+{
+ _M_reserve_map_at_front();
+ *(_M_start._M_node - 1) = _M_allocate_node();
+ __STL_TRY {
+ _M_start._M_set_node(_M_start._M_node - 1);
+ _M_start._M_cur = _M_start._M_last - 1;
+ construct(_M_start._M_cur);
+ }
+ __STL_UNWIND((++_M_start, _M_deallocate_node(*(_M_start._M_node - 1))));
+}
+
+// Called only if _M_finish._M_cur == _M_finish._M_first.
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_pop_back_aux()
+{
+ _M_deallocate_node(_M_finish._M_first);
+ _M_finish._M_set_node(_M_finish._M_node - 1);
+ _M_finish._M_cur = _M_finish._M_last - 1;
+ destroy(_M_finish._M_cur);
+}
+
+// Called only if _M_start._M_cur == _M_start._M_last - 1. Note that
+// if the deque has at least one element (a precondition for this member
+// function), and if _M_start._M_cur == _M_start._M_last, then the deque
+// must have at least two nodes.
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_pop_front_aux()
+{
+ destroy(_M_start._M_cur);
+ _M_deallocate_node(_M_start._M_first);
+ _M_start._M_set_node(_M_start._M_node + 1);
+ _M_start._M_cur = _M_start._M_first;
+}
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+template <class _InputIterator>
+void
+deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos,
+ _InputIterator __first,
+ _InputIterator __last,
+ input_iterator_tag)
+{
+ copy(__first, __last, inserter(*this, __pos));
+}
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+template <class _ForwardIterator>
+void
+deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos,
+ _ForwardIterator __first,
+ _ForwardIterator __last,
+ forward_iterator_tag) {
+ size_type __n = 0;
+ distance(__first, __last, __n);
+ if (__pos._M_cur == _M_start._M_cur) {
+ iterator __new_start = _M_reserve_elements_at_front(__n);
+ __STL_TRY {
+ uninitialized_copy(__first, __last, __new_start);
+ _M_start = __new_start;
+ }
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
+ }
+ else if (__pos._M_cur == _M_finish._M_cur) {
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
+ __STL_TRY {
+ uninitialized_copy(__first, __last, _M_finish);
+ _M_finish = __new_finish;
+ }
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
+ __new_finish._M_node + 1));
+ }
+ else
+ _M_insert_aux(__pos, __first, __last, __n);
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+typename deque<_Tp, _Alloc, __bufsize>::iterator
+deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
+ const value_type& __x)
+{
+ difference_type __index = __pos - _M_start;
+ value_type __x_copy = __x;
+ if (static_cast<size_type>(__index) < size() / 2) {
+ push_front(front());
+ iterator __front1 = _M_start;
+ ++__front1;
+ iterator __front2 = __front1;
+ ++__front2;
+ __pos = _M_start + __index;
+ iterator __pos1 = __pos;
+ ++__pos1;
+ copy(__front2, __pos1, __front1);
+ }
+ else {
+ push_back(back());
+ iterator __back1 = _M_finish;
+ --__back1;
+ iterator __back2 = __back1;
+ --__back2;
+ __pos = _M_start + __index;
+ copy_backward(__pos, __back2, __back1);
+ }
+ *__pos = __x_copy;
+ return __pos;
+}
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+typename deque<_Tp,_Alloc,__bufsize>::iterator
+deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos)
+{
+ difference_type __index = __pos - _M_start;
+ if (static_cast<size_type>(__index) < size() / 2) {
+ push_front(front());
+ iterator __front1 = _M_start;
+ ++__front1;
+ iterator __front2 = __front1;
+ ++__front2;
+ __pos = _M_start + __index;
+ iterator __pos1 = __pos;
+ ++__pos1;
+ copy(__front2, __pos1, __front1);
+ }
+ else {
+ push_back(back());
+ iterator __back1 = _M_finish;
+ --__back1;
+ iterator __back2 = __back1;
+ --__back2;
+ __pos = _M_start + __index;
+ copy_backward(__pos, __back2, __back1);
+ }
+ *__pos = value_type();
+ return __pos;
+}
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
+ size_type __n,
+ const value_type& __x)
+{
+ const difference_type __elems_before = __pos - _M_start;
+ size_type __length = size();
+ value_type __x_copy = __x;
+ if (static_cast<size_type>(__elems_before) < __length / 2) {
+ iterator __new_start = _M_reserve_elements_at_front(__n);
+ iterator __old_start = _M_start;
+ __pos = _M_start + __elems_before;
+ __STL_TRY {
+ if (__elems_before >= difference_type(__n)) {
+ iterator __start_n = _M_start + difference_type(__n);
+ uninitialized_copy(_M_start, __start_n, __new_start);
+ _M_start = __new_start;
+ copy(__start_n, __pos, __old_start);
+ fill(__pos - difference_type(__n), __pos, __x_copy);
+ }
+ else {
+ __uninitialized_copy_fill(_M_start, __pos, __new_start,
+ _M_start, __x_copy);
+ _M_start = __new_start;
+ fill(__old_start, __pos, __x_copy);
+ }
+ }
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
+ }
+ else {
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
+ iterator __old_finish = _M_finish;
+ const difference_type __elems_after =
+ difference_type(__length) - __elems_before;
+ __pos = _M_finish - __elems_after;
+ __STL_TRY {
+ if (__elems_after > difference_type(__n)) {
+ iterator __finish_n = _M_finish - difference_type(__n);
+ uninitialized_copy(__finish_n, _M_finish, _M_finish);
+ _M_finish = __new_finish;
+ copy_backward(__pos, __finish_n, __old_finish);
+ fill(__pos, __pos + difference_type(__n), __x_copy);
+ }
+ else {
+ __uninitialized_fill_copy(_M_finish, __pos + difference_type(__n),
+ __x_copy, __pos, _M_finish);
+ _M_finish = __new_finish;
+ fill(__pos, __old_finish, __x_copy);
+ }
+ }
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
+ __new_finish._M_node + 1));
+ }
+}
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+template <class _ForwardIterator>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
+ _ForwardIterator __first,
+ _ForwardIterator __last,
+ size_type __n)
+{
+ const difference_type __elemsbefore = __pos - _M_start;
+ size_type __length = size();
+ if (static_cast<size_type>(__elemsbefore) < __length / 2) {
+ iterator __new_start = _M_reserve_elements_at_front(__n);
+ iterator __old_start = _M_start;
+ __pos = _M_start + __elemsbefore;
+ __STL_TRY {
+ if (__elemsbefore >= difference_type(__n)) {
+ iterator __start_n = _M_start + difference_type(__n);
+ uninitialized_copy(_M_start, __start_n, __new_start);
+ _M_start = __new_start;
+ copy(__start_n, __pos, __old_start);
+ copy(__first, __last, __pos - difference_type(__n));
+ }
+ else {
+ _ForwardIterator __mid = __first;
+ advance(__mid, difference_type(__n) - __elemsbefore);
+ __uninitialized_copy_copy(_M_start, __pos, __first, __mid,
+ __new_start);
+ _M_start = __new_start;
+ copy(__mid, __last, __old_start);
+ }
+ }
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
+ }
+ else {
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
+ iterator __old_finish = _M_finish;
+ const difference_type __elemsafter =
+ difference_type(__length) - __elemsbefore;
+ __pos = _M_finish - __elemsafter;
+ __STL_TRY {
+ if (__elemsafter > difference_type(__n)) {
+ iterator __finish_n = _M_finish - difference_type(__n);
+ uninitialized_copy(__finish_n, _M_finish, _M_finish);
+ _M_finish = __new_finish;
+ copy_backward(__pos, __finish_n, __old_finish);
+ copy(__first, __last, __pos);
+ }
+ else {
+ _ForwardIterator __mid = __first;
+ advance(__mid, __elemsafter);
+ __uninitialized_copy_copy(__mid, __last, __pos, _M_finish, _M_finish);
+ _M_finish = __new_finish;
+ copy(__first, __mid, __pos);
+ }
+ }
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
+ __new_finish._M_node + 1));
+ }
+}
+
+#else /* __STL_MEMBER_TEMPLATES */
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
+ const value_type* __first,
+ const value_type* __last,
+ size_type __n)
+{
+ const difference_type __elemsbefore = __pos - _M_start;
+ size_type __length = size();
+ if (__elemsbefore < __length / 2) {
+ iterator __new_start = _M_reserve_elements_at_front(__n);
+ iterator __old_start = _M_start;
+ __pos = _M_start + __elemsbefore;
+ __STL_TRY {
+ if (__elemsbefore >= difference_type(__n)) {
+ iterator __start_n = _M_start + difference_type(__n);
+ uninitialized_copy(_M_start, __start_n, __new_start);
+ _M_start = __new_start;
+ copy(__start_n, __pos, __old_start);
+ copy(__first, __last, __pos - difference_type(__n));
+ }
+ else {
+ const value_type* __mid =
+ __first + (difference_type(__n) - __elemsbefore);
+ __uninitialized_copy_copy(_M_start, __pos, __first, __mid,
+ __new_start);
+ _M_start = __new_start;
+ copy(__mid, __last, __old_start);
+ }
+ }
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
+ }
+ else {
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
+ iterator __old_finish = _M_finish;
+ const difference_type __elemsafter =
+ difference_type(__length) - __elemsbefore;
+ __pos = _M_finish - __elemsafter;
+ __STL_TRY {
+ if (__elemsafter > difference_type(__n)) {
+ iterator __finish_n = _M_finish - difference_type(__n);
+ uninitialized_copy(__finish_n, _M_finish, _M_finish);
+ _M_finish = __new_finish;
+ copy_backward(__pos, __finish_n, __old_finish);
+ copy(__first, __last, __pos);
+ }
+ else {
+ const value_type* __mid = __first + __elemsafter;
+ __uninitialized_copy_copy(__mid, __last, __pos, _M_finish, _M_finish);
+ _M_finish = __new_finish;
+ copy(__first, __mid, __pos);
+ }
+ }
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
+ __new_finish._M_node + 1));
+ }
+}
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
+ const_iterator __first,
+ const_iterator __last,
+ size_type __n)
+{
+ const difference_type __elemsbefore = __pos - _M_start;
+ size_type __length = size();
+ if (__elemsbefore < __length / 2) {
+ iterator __new_start = _M_reserve_elements_at_front(__n);
+ iterator __old_start = _M_start;
+ __pos = _M_start + __elemsbefore;
+ __STL_TRY {
+ if (__elemsbefore >= __n) {
+ iterator __start_n = _M_start + __n;
+ uninitialized_copy(_M_start, __start_n, __new_start);
+ _M_start = __new_start;
+ copy(__start_n, __pos, __old_start);
+ copy(__first, __last, __pos - difference_type(__n));
+ }
+ else {
+ const_iterator __mid = __first + (__n - __elemsbefore);
+ __uninitialized_copy_copy(_M_start, __pos, __first, __mid,
+ __new_start);
+ _M_start = __new_start;
+ copy(__mid, __last, __old_start);
+ }
+ }
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
+ }
+ else {
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
+ iterator __old_finish = _M_finish;
+ const difference_type __elemsafter = __length - __elemsbefore;
+ __pos = _M_finish - __elemsafter;
+ __STL_TRY {
+ if (__elemsafter > __n) {
+ iterator __finish_n = _M_finish - difference_type(__n);
+ uninitialized_copy(__finish_n, _M_finish, _M_finish);
+ _M_finish = __new_finish;
+ copy_backward(__pos, __finish_n, __old_finish);
+ copy(__first, __last, __pos);
+ }
+ else {
+ const_iterator __mid = __first + __elemsafter;
+ __uninitialized_copy_copy(__mid, __last, __pos, _M_finish, _M_finish);
+ _M_finish = __new_finish;
+ copy(__first, __mid, __pos);
+ }
+ }
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
+ __new_finish._M_node + 1));
+ }
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_new_elements_at_front(size_type __new_elems)
+{
+ size_type __new_nodes
+ = (__new_elems + _S_buffer_size() - 1) / _S_buffer_size();
+ _M_reserve_map_at_front(__new_nodes);
+ size_type __i;
+ __STL_TRY {
+ for (__i = 1; __i <= __new_nodes; ++__i)
+ *(_M_start._M_node - __i) = _M_allocate_node();
+ }
+# ifdef __STL_USE_EXCEPTIONS
+ catch(...) {
+ for (size_type __j = 1; __j < __i; ++__j)
+ _M_deallocate_node(*(_M_start._M_node - __j));
+ throw;
+ }
+# endif /* __STL_USE_EXCEPTIONS */
+}
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_new_elements_at_back(size_type __new_elems)
+{
+ size_type __new_nodes
+ = (__new_elems + _S_buffer_size() - 1) / _S_buffer_size();
+ _M_reserve_map_at_back(__new_nodes);
+ size_type __i;
+ __STL_TRY {
+ for (__i = 1; __i <= __new_nodes; ++__i)
+ *(_M_finish._M_node + __i) = _M_allocate_node();
+ }
+# ifdef __STL_USE_EXCEPTIONS
+ catch(...) {
+ for (size_type __j = 1; __j < __i; ++__j)
+ _M_deallocate_node(*(_M_finish._M_node + __j));
+ throw;
+ }
+# endif /* __STL_USE_EXCEPTIONS */
+}
+
+template <class _Tp, class _Alloc, size_t __bufsize>
+void
+deque<_Tp,_Alloc,__bufsize>::_M_reallocate_map(size_type __nodes_to_add,
+ bool __add_at_front)
+{
+ size_type __old_num_nodes = _M_finish._M_node - _M_start._M_node + 1;
+ size_type __new_num_nodes = __old_num_nodes + __nodes_to_add;
+
+ _Map_pointer __new_nstart;
+ if (_M_map_size > 2 * __new_num_nodes) {
+ __new_nstart = _M_map + (_M_map_size - __new_num_nodes) / 2
+ + (__add_at_front ? __nodes_to_add : 0);
+ if (__new_nstart < _M_start._M_node)
+ copy(_M_start._M_node, _M_finish._M_node + 1, __new_nstart);
+ else
+ copy_backward(_M_start._M_node, _M_finish._M_node + 1,
+ __new_nstart + __old_num_nodes);
+ }
+ else {
+ size_type __new_map_size =
+ _M_map_size + max(_M_map_size, __nodes_to_add) + 2;
+
+ _Map_pointer __new_map = _M_allocate_map(__new_map_size);
+ __new_nstart = __new_map + (__new_map_size - __new_num_nodes) / 2
+ + (__add_at_front ? __nodes_to_add : 0);
+ copy(_M_start._M_node, _M_finish._M_node + 1, __new_nstart);
+ _M_deallocate_map(_M_map, _M_map_size);
+
+ _M_map = __new_map;
+ _M_map_size = __new_map_size;
+ }
+
+ _M_start._M_set_node(__new_nstart);
+ _M_finish._M_set_node(__new_nstart + __old_num_nodes - 1);
+}
+
+
+// Nonmember functions.
+
+#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+inline bool operator==(const deque<_Tp, _Alloc, __bufsiz>& __x,
+ const deque<_Tp, _Alloc, __bufsiz>& __y)
+{
+ return __x.size() == __y.size() &&
+ equal(__x.begin(), __x.end(), __y.begin());
+}
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+inline bool operator<(const deque<_Tp, _Alloc, __bufsiz>& __x,
+ const deque<_Tp, _Alloc, __bufsiz>& __y)
+{
+ return lexicographical_compare(__x.begin(), __x.end(),
+ __y.begin(), __y.end());
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+inline bool operator!=(const deque<_Tp, _Alloc, __bufsiz>& __x,
+ const deque<_Tp, _Alloc, __bufsiz>& __y)
+{
+ return !(__x == __y);
+}
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+inline bool operator>(const deque<_Tp, _Alloc, __bufsiz>& __x,
+ const deque<_Tp, _Alloc, __bufsiz>& __y)
+{
+ return __y < __x;
+}
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+inline bool operator<=(const deque<_Tp, _Alloc, __bufsiz>& __x,
+ const deque<_Tp, _Alloc, __bufsiz>& __y)
+{
+ return !(__y < __x);
+}
+template <class _Tp, class _Alloc, size_t __bufsiz>
+inline bool operator>=(const deque<_Tp, _Alloc, __bufsiz>& __x,
+ const deque<_Tp, _Alloc, __bufsiz>& __y)
+{
+ return !(__x < __y);
+}
+
+template <class _Tp, class _Alloc, size_t __bufsiz>
+inline void
+swap(deque<_Tp,_Alloc,__bufsiz>& __x, deque<_Tp,_Alloc,__bufsiz>& __y)
+{
+ __x.swap(__y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1174
+#pragma reset woff 1375
+#endif
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_DEQUE_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_function.h b/libstdc++-v3/bits/stl_function.h
new file mode 100644
index 0000000..e7e5340
--- /dev/null
+++ b/libstdc++-v3/bits/stl_function.h
@@ -0,0 +1,732 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996-1998
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_FUNCTION_H
+#define __SGI_STL_INTERNAL_FUNCTION_H
+
+__STL_BEGIN_NAMESPACE
+
+template <class _Arg, class _Result>
+struct unary_function {
+ typedef _Arg argument_type;
+ typedef _Result result_type;
+};
+
+template <class _Arg1, class _Arg2, class _Result>
+struct binary_function {
+ typedef _Arg1 first_argument_type;
+ typedef _Arg2 second_argument_type;
+ typedef _Result result_type;
+};
+
+template <class _Tp>
+struct plus : public binary_function<_Tp,_Tp,_Tp> {
+ _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
+};
+
+template <class _Tp>
+struct minus : public binary_function<_Tp,_Tp,_Tp> {
+ _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
+};
+
+template <class _Tp>
+struct multiplies : public binary_function<_Tp,_Tp,_Tp> {
+ _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
+};
+
+template <class _Tp>
+struct divides : public binary_function<_Tp,_Tp,_Tp> {
+ _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }
+};
+
+// identity_element (not part of the C++ standard).
+
+template <class _Tp> inline _Tp identity_element(plus<_Tp>) {
+ return _Tp(0);
+}
+template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) {
+ return _Tp(1);
+}
+
+template <class _Tp>
+struct modulus : public binary_function<_Tp,_Tp,_Tp>
+{
+ _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }
+};
+
+template <class _Tp>
+struct negate : public unary_function<_Tp,_Tp>
+{
+ _Tp operator()(const _Tp& __x) const { return -__x; }
+};
+
+template <class _Tp>
+struct equal_to : public binary_function<_Tp,_Tp,bool>
+{
+ bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
+};
+
+template <class _Tp>
+struct not_equal_to : public binary_function<_Tp,_Tp,bool>
+{
+ bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }
+};
+
+template <class _Tp>
+struct greater : public binary_function<_Tp,_Tp,bool>
+{
+ bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }
+};
+
+template <class _Tp>
+struct less : public binary_function<_Tp,_Tp,bool>
+{
+ bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
+};
+
+template <class _Tp>
+struct greater_equal : public binary_function<_Tp,_Tp,bool>
+{
+ bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }
+};
+
+template <class _Tp>
+struct less_equal : public binary_function<_Tp,_Tp,bool>
+{
+ bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
+};
+
+template <class _Tp>
+struct logical_and : public binary_function<_Tp,_Tp,bool>
+{
+ bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }
+};
+
+template <class _Tp>
+struct logical_or : public binary_function<_Tp,_Tp,bool>
+{
+ bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }
+};
+
+template <class _Tp>
+struct logical_not : public unary_function<_Tp,bool>
+{
+ bool operator()(const _Tp& __x) const { return !__x; }
+};
+
+template <class _Predicate>
+class unary_negate
+ : public unary_function<typename _Predicate::argument_type, bool> {
+protected:
+ _Predicate _M_pred;
+public:
+ explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}
+ bool operator()(const typename _Predicate::argument_type& __x) const {
+ return !_M_pred(__x);
+ }
+};
+
+template <class _Predicate>
+inline unary_negate<_Predicate>
+not1(const _Predicate& __pred)
+{
+ return unary_negate<_Predicate>(__pred);
+}
+
+template <class _Predicate>
+class binary_negate
+ : public binary_function<typename _Predicate::first_argument_type,
+ typename _Predicate::second_argument_type,
+ bool> {
+protected:
+ _Predicate _M_pred;
+public:
+ explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {}
+ bool operator()(const typename _Predicate::first_argument_type& __x,
+ const typename _Predicate::second_argument_type& __y) const
+ {
+ return !_M_pred(__x, __y);
+ }
+};
+
+template <class _Predicate>
+inline binary_negate<_Predicate>
+not2(const _Predicate& __pred)
+{
+ return binary_negate<_Predicate>(__pred);
+}
+
+template <class _Operation>
+class binder1st
+ : public unary_function<typename _Operation::second_argument_type,
+ typename _Operation::result_type> {
+protected:
+ _Operation op;
+ typename _Operation::first_argument_type value;
+public:
+ binder1st(const _Operation& __x,
+ const typename _Operation::first_argument_type& __y)
+ : op(__x), value(__y) {}
+ typename _Operation::result_type
+ operator()(const typename _Operation::second_argument_type& __x) const {
+ return op(value, __x);
+ }
+};
+
+template <class _Operation, class _Tp>
+inline binder1st<_Operation>
+bind1st(const _Operation& __fn, const _Tp& __x)
+{
+ typedef typename _Operation::first_argument_type _Arg1_type;
+ return binder1st<_Operation>(__fn, _Arg1_type(__x));
+}
+
+template <class _Operation>
+class binder2nd
+ : public unary_function<typename _Operation::first_argument_type,
+ typename _Operation::result_type> {
+protected:
+ _Operation op;
+ typename _Operation::second_argument_type value;
+public:
+ binder2nd(const _Operation& __x,
+ const typename _Operation::second_argument_type& __y)
+ : op(__x), value(__y) {}
+ typename _Operation::result_type
+ operator()(const typename _Operation::first_argument_type& __x) const {
+ return op(__x, value);
+ }
+};
+
+template <class _Operation, class _Tp>
+inline binder2nd<_Operation>
+bind2nd(const _Operation& __fn, const _Tp& __x)
+{
+ typedef typename _Operation::second_argument_type _Arg2_type;
+ return binder2nd<_Operation>(__fn, _Arg2_type(__x));
+}
+
+// unary_compose and binary_compose (extensions, not part of the standard).
+
+template <class _Operation1, class _Operation2>
+class unary_compose
+ : public unary_function<typename _Operation2::argument_type,
+ typename _Operation1::result_type>
+{
+protected:
+ _Operation1 _M_fn1;
+ _Operation2 _M_fn2;
+public:
+ unary_compose(const _Operation1& __x, const _Operation2& __y)
+ : _M_fn1(__x), _M_fn2(__y) {}
+ typename _Operation1::result_type
+ operator()(const typename _Operation2::argument_type& __x) const {
+ return _M_fn1(_M_fn2(__x));
+ }
+};
+
+template <class _Operation1, class _Operation2>
+inline unary_compose<_Operation1,_Operation2>
+compose1(const _Operation1& __fn1, const _Operation2& __fn2)
+{
+ return unary_compose<_Operation1,_Operation2>(__fn1, __fn2);
+}
+
+template <class _Operation1, class _Operation2, class _Operation3>
+class binary_compose
+ : public unary_function<typename _Operation2::argument_type,
+ typename _Operation1::result_type> {
+protected:
+ _Operation1 _M_fn1;
+ _Operation2 _M_fn2;
+ _Operation3 _M_fn3;
+public:
+ binary_compose(const _Operation1& __x, const _Operation2& __y,
+ const _Operation3& __z)
+ : _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { }
+ typename _Operation1::result_type
+ operator()(const typename _Operation2::argument_type& __x) const {
+ return _M_fn1(_M_fn2(__x), _M_fn3(__x));
+ }
+};
+
+template <class _Operation1, class _Operation2, class _Operation3>
+inline binary_compose<_Operation1, _Operation2, _Operation3>
+compose2(const _Operation1& __fn1, const _Operation2& __fn2,
+ const _Operation3& __fn3)
+{
+ return binary_compose<_Operation1,_Operation2,_Operation3>
+ (__fn1, __fn2, __fn3);
+}
+
+template <class _Arg, class _Result>
+class pointer_to_unary_function : public unary_function<_Arg, _Result> {
+protected:
+ _Result (*_M_ptr)(_Arg);
+public:
+ pointer_to_unary_function() {}
+ explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {}
+ _Result operator()(_Arg __x) const { return _M_ptr(__x); }
+};
+
+template <class _Arg, class _Result>
+inline pointer_to_unary_function<_Arg, _Result> ptr_fun(_Result (*__x)(_Arg))
+{
+ return pointer_to_unary_function<_Arg, _Result>(__x);
+}
+
+template <class _Arg1, class _Arg2, class _Result>
+class pointer_to_binary_function :
+ public binary_function<_Arg1,_Arg2,_Result> {
+protected:
+ _Result (*_M_ptr)(_Arg1, _Arg2);
+public:
+ pointer_to_binary_function() {}
+ explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
+ : _M_ptr(__x) {}
+ _Result operator()(_Arg1 __x, _Arg2 __y) const {
+ return _M_ptr(__x, __y);
+ }
+};
+
+template <class _Arg1, class _Arg2, class _Result>
+inline pointer_to_binary_function<_Arg1,_Arg2,_Result>
+ptr_fun(_Result (*__x)(_Arg1, _Arg2)) {
+ return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__x);
+}
+
+// identity is an extensions: it is not part of the standard.
+template <class _Tp>
+struct _Identity : public unary_function<_Tp,_Tp> {
+ _Tp& operator()(_Tp& __x) const { return __x; }
+ const _Tp& operator()(const _Tp& __x) const { return __x; }
+};
+
+template <class _Tp> struct identity : public _Identity<_Tp> {};
+
+// select1st and select2nd are extensions: they are not part of the standard.
+template <class _Pair>
+struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
+ typename _Pair::first_type& operator()(_Pair& __x) const {
+ return __x.first;
+ }
+ const typename _Pair::first_type& operator()(const _Pair& __x) const {
+ return __x.first;
+ }
+};
+
+template <class _Pair>
+struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
+{
+ typename _Pair::second_type& operator()(_Pair& __x) const {
+ return __x.second;
+ }
+ const typename _Pair::second_type& operator()(const _Pair& __x) const {
+ return __x.second;
+ }
+};
+
+template <class _Pair> struct select1st : public _Select1st<_Pair> {};
+template <class _Pair> struct select2nd : public _Select2nd<_Pair> {};
+
+// project1st and project2nd are extensions: they are not part of the standard
+template <class _Arg1, class _Arg2>
+struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {
+ _Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; }
+};
+
+template <class _Arg1, class _Arg2>
+struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {
+ _Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; }
+};
+
+template <class _Arg1, class _Arg2>
+struct project1st : public _Project1st<_Arg1, _Arg2> {};
+
+template <class _Arg1, class _Arg2>
+struct project2nd : public _Project2nd<_Arg1, _Arg2> {};
+
+// constant_void_fun, constant_unary_fun, and constant_binary_fun are
+// extensions: they are not part of the standard. (The same, of course,
+// is true of the helper functions constant0, constant1, and constant2.)
+
+template <class _Result>
+struct _Constant_void_fun {
+ typedef _Result result_type;
+ result_type _M_val;
+
+ _Constant_void_fun(const result_type& __v) : _M_val(__v) {}
+ const result_type& operator()() const { return _M_val; }
+};
+
+template <class _Result, class _Argument>
+struct _Constant_unary_fun {
+ typedef _Argument argument_type;
+ typedef _Result result_type;
+ result_type _M_val;
+
+ _Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
+ const result_type& operator()(const _Argument&) const { return _M_val; }
+};
+
+template <class _Result, class _Arg1, class _Arg2>
+struct _Constant_binary_fun {
+ typedef _Arg1 first_argument_type;
+ typedef _Arg2 second_argument_type;
+ typedef _Result result_type;
+ _Result _M_val;
+
+ _Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
+ const result_type& operator()(const _Arg1&, const _Arg2&) const {
+ return _M_val;
+ }
+};
+
+template <class _Result>
+struct constant_void_fun : public _Constant_void_fun<_Result> {
+ constant_void_fun(const _Result& __v) : _Constant_void_fun<_Result>(_v) {}
+};
+
+
+template <class _Result,
+ class _Argument = _Result>
+struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument>
+{
+ constant_unary_fun(const _Result& __v)
+ : _Constant_unary_fun<_Result, _Argument>(__v) {}
+};
+
+
+template <class _Result,
+ class _Arg1 = _Result,
+ class _Arg2 = _Arg1>
+struct constant_binary_fun
+ : public _Constant_binary_fun<_Result, _Arg1, _Arg2>
+{
+ constant_binary_fun(const _Result& __v)
+ : _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}
+};
+
+template <class _Result>
+inline constant_void_fun<_Result> constant0(const _Result& __val)
+{
+ return constant_void_fun<_Result>(__val);
+}
+
+template <class _Result>
+inline constant_unary_fun<_Result,_Result> constant1(const _Result& __val)
+{
+ return constant_unary_fun<_Result,_Result>(__val);
+}
+
+template <class _Result>
+inline constant_binary_fun<_Result,_Result,_Result>
+constant2(const _Result& __val)
+{
+ return constant_binary_fun<_Result,_Result,_Result>(__val);
+}
+
+// subtractive_rng is an extension: it is not part of the standard.
+// Note: this code assumes that int is 32 bits.
+class subtractive_rng : public unary_function<unsigned int, unsigned int> {
+private:
+ unsigned int _M_table[55];
+ size_t _M_index1;
+ size_t _M_index2;
+public:
+ unsigned int operator()(unsigned int __limit) {
+ _M_index1 = (_M_index1 + 1) % 55;
+ _M_index2 = (_M_index2 + 1) % 55;
+ _M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2];
+ return _M_table[_M_index1] % __limit;
+ }
+
+ void _M_initialize(unsigned int __seed)
+ {
+ unsigned int __k = 1;
+ _M_table[54] = __seed;
+ size_t __i;
+ for (__i = 0; __i < 54; __i++) {
+ size_t __ii = (21 * (__i + 1) % 55) - 1;
+ _M_table[__ii] = __k;
+ __k = __seed - __k;
+ __seed = _M_table[__ii];
+ }
+ for (int __loop = 0; __loop < 4; __loop++) {
+ for (__i = 0; __i < 55; __i++)
+ _M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55];
+ }
+ _M_index1 = 0;
+ _M_index2 = 31;
+ }
+
+ subtractive_rng(unsigned int __seed) { _M_initialize(__seed); }
+ subtractive_rng() { _M_initialize(161803398u); }
+};
+
+
+// Adaptor function objects: pointers to member functions.
+
+// There are a total of 16 = 2^4 function objects in this family.
+// (1) Member functions taking no arguments vs member functions taking
+// one argument.
+// (2) Call through pointer vs call through reference.
+// (3) Member function with void return type vs member function with
+// non-void return type.
+// (4) Const vs non-const member function.
+
+// Note that choice (3) is nothing more than a workaround: according
+// to the draft, compilers should handle void and non-void the same way.
+// This feature is not yet widely implemented, though. You can only use
+// member functions returning void if your compiler supports partial
+// specialization.
+
+// All of this complexity is in the function objects themselves. You can
+// ignore it by using the helper function mem_fun and mem_fun_ref,
+// which create whichever type of adaptor is appropriate.
+// (mem_fun1 and mem_fun1_ref are no longer part of the C++ standard,
+// but they are provided for backward compatibility.)
+
+
+template <class _Ret, class _Tp>
+class mem_fun_t : public unary_function<_Tp*,_Ret> {
+public:
+ explicit mem_fun_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
+ _Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); }
+private:
+ _Ret (_Tp::*_M_f)();
+};
+
+template <class _Ret, class _Tp>
+class const_mem_fun_t : public unary_function<const _Tp*,_Ret> {
+public:
+ explicit const_mem_fun_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
+ _Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); }
+private:
+ _Ret (_Tp::*_M_f)() const;
+};
+
+
+template <class _Ret, class _Tp>
+class mem_fun_ref_t : public unary_function<_Tp,_Ret> {
+public:
+ explicit mem_fun_ref_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
+ _Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); }
+private:
+ _Ret (_Tp::*_M_f)();
+};
+
+template <class _Ret, class _Tp>
+class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> {
+public:
+ explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
+ _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
+private:
+ _Ret (_Tp::*_M_f)() const;
+};
+
+template <class _Ret, class _Tp, class _Arg>
+class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> {
+public:
+ explicit mem_fun1_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
+ _Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); }
+private:
+ _Ret (_Tp::*_M_f)(_Arg);
+};
+
+template <class _Ret, class _Tp, class _Arg>
+class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> {
+public:
+ explicit const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
+ _Ret operator()(const _Tp* __p, _Arg __x) const
+ { return (__p->*_M_f)(__x); }
+private:
+ _Ret (_Tp::*_M_f)(_Arg) const;
+};
+
+template <class _Ret, class _Tp, class _Arg>
+class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
+public:
+ explicit mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
+ _Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
+private:
+ _Ret (_Tp::*_M_f)(_Arg);
+};
+
+template <class _Ret, class _Tp, class _Arg>
+class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
+public:
+ explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
+ _Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
+private:
+ _Ret (_Tp::*_M_f)(_Arg) const;
+};
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _Tp>
+class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> {
+public:
+ explicit mem_fun_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
+ void operator()(_Tp* __p) const { (__p->*_M_f)(); }
+private:
+ void (_Tp::*_M_f)();
+};
+
+template <class _Tp>
+class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> {
+public:
+ explicit const_mem_fun_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
+ void operator()(const _Tp* __p) const { (__p->*_M_f)(); }
+private:
+ void (_Tp::*_M_f)() const;
+};
+
+template <class _Tp>
+class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
+public:
+ explicit mem_fun_ref_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
+ void operator()(_Tp& __r) const { (__r.*_M_f)(); }
+private:
+ void (_Tp::*_M_f)();
+};
+
+template <class _Tp>
+class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
+public:
+ explicit const_mem_fun_ref_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
+ void operator()(const _Tp& __r) const { (__r.*_M_f)(); }
+private:
+ void (_Tp::*_M_f)() const;
+};
+
+template <class _Tp, class _Arg>
+class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> {
+public:
+ explicit mem_fun1_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
+ void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
+private:
+ void (_Tp::*_M_f)(_Arg);
+};
+
+template <class _Tp, class _Arg>
+class const_mem_fun1_t<void, _Tp, _Arg>
+ : public binary_function<const _Tp*,_Arg,void> {
+public:
+ explicit const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
+ void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
+private:
+ void (_Tp::*_M_f)(_Arg) const;
+};
+
+template <class _Tp, class _Arg>
+class mem_fun1_ref_t<void, _Tp, _Arg>
+ : public binary_function<_Tp,_Arg,void> {
+public:
+ explicit mem_fun1_ref_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
+ void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
+private:
+ void (_Tp::*_M_f)(_Arg);
+};
+
+template <class _Tp, class _Arg>
+class const_mem_fun1_ref_t<void, _Tp, _Arg>
+ : public binary_function<_Tp,_Arg,void> {
+public:
+ explicit const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
+ void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
+private:
+ void (_Tp::*_M_f)(_Arg) const;
+};
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+// Mem_fun adaptor helper functions. There are only two:
+// mem_fun and mem_fun_ref. (mem_fun1 and mem_fun1_ref
+// are provided for backward compatibility, but they are no longer
+// part of the C++ standard.)
+
+template <class _Ret, class _Tp>
+inline mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)())
+ { return mem_fun_t<_Ret,_Tp>(__f); }
+
+template <class _Ret, class _Tp>
+inline const_mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)() const)
+ { return const_mem_fun_t<_Ret,_Tp>(__f); }
+
+template <class _Ret, class _Tp>
+inline mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)())
+ { return mem_fun_ref_t<_Ret,_Tp>(__f); }
+
+template <class _Ret, class _Tp>
+inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
+ { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
+
+template <class _Ret, class _Tp, class _Arg>
+inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg))
+ { return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
+
+template <class _Ret, class _Tp, class _Arg>
+inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg) const)
+ { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
+
+template <class _Ret, class _Tp, class _Arg>
+inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
+ { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
+
+template <class _Ret, class _Tp, class _Arg>
+inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>
+mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
+ { return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
+
+template <class _Ret, class _Tp, class _Arg>
+inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg))
+ { return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
+
+template <class _Ret, class _Tp, class _Arg>
+inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg) const)
+ { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
+
+template <class _Ret, class _Tp, class _Arg>
+inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun1_ref(_Ret (_Tp::*__f)(_Arg))
+ { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
+
+template <class _Ret, class _Tp, class _Arg>
+inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>
+mem_fun1_ref(_Ret (_Tp::*__f)(_Arg) const)
+ { return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_FUNCTION_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_heap.h b/libstdc++-v3/bits/stl_heap.h
new file mode 100644
index 0000000..8af130c
--- /dev/null
+++ b/libstdc++-v3/bits/stl_heap.h
@@ -0,0 +1,281 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * Copyright (c) 1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef _CPP_BITS_STL_HEAP_H
+#define _CPP_BITS_STL_HEAP_H 1
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1209
+#endif
+
+// Heap-manipulation functions: push_heap, pop_heap, make_heap, sort_heap.
+
+template <class _RandomAccessIterator, class _Distance, class _Tp>
+void
+__push_heap(_RandomAccessIterator __first,
+ _Distance __holeIndex, _Distance __topIndex, _Tp __value)
+{
+ _Distance __parent = (__holeIndex - 1) / 2;
+ while (__holeIndex > __topIndex && *(__first + __parent) < __value) {
+ *(__first + __holeIndex) = *(__first + __parent);
+ __holeIndex = __parent;
+ __parent = (__holeIndex - 1) / 2;
+ }
+ *(__first + __holeIndex) = __value;
+}
+
+template <class _RandomAccessIterator, class _Distance, class _Tp>
+inline void
+__push_heap_aux(_RandomAccessIterator __first,
+ _RandomAccessIterator __last, _Distance*, _Tp*)
+{
+ __push_heap(__first, _Distance((__last - __first) - 1), _Distance(0),
+ _Tp(*(__last - 1)));
+}
+
+template <class _RandomAccessIterator>
+inline void
+push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+ __push_heap_aux(__first, __last,
+ __DISTANCE_TYPE(__first), __VALUE_TYPE(__first));
+}
+
+template <class _RandomAccessIterator, class _Distance, class _Tp,
+ class _Compare>
+void
+__push_heap(_RandomAccessIterator __first, _Distance __holeIndex,
+ _Distance __topIndex, _Tp __value, _Compare __comp)
+{
+ _Distance __parent = (__holeIndex - 1) / 2;
+ while (__holeIndex > __topIndex && __comp(*(__first + __parent), __value)) {
+ *(__first + __holeIndex) = *(__first + __parent);
+ __holeIndex = __parent;
+ __parent = (__holeIndex - 1) / 2;
+ }
+ *(__first + __holeIndex) = __value;
+}
+
+template <class _RandomAccessIterator, class _Compare,
+ class _Distance, class _Tp>
+inline void
+__push_heap_aux(_RandomAccessIterator __first,
+ _RandomAccessIterator __last, _Compare __comp,
+ _Distance*, _Tp*)
+{
+ __push_heap(__first, _Distance((__last - __first) - 1), _Distance(0),
+ _Tp(*(__last - 1)), __comp);
+}
+
+template <class _RandomAccessIterator, class _Compare>
+inline void
+push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+ _Compare __comp)
+{
+ __push_heap_aux(__first, __last, __comp,
+ __DISTANCE_TYPE(__first), __VALUE_TYPE(__first));
+}
+
+template <class _RandomAccessIterator, class _Distance, class _Tp>
+void
+__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
+ _Distance __len, _Tp __value)
+{
+ _Distance __topIndex = __holeIndex;
+ _Distance __secondChild = 2 * __holeIndex + 2;
+ while (__secondChild < __len) {
+ if (*(__first + __secondChild) < *(__first + (__secondChild - 1)))
+ __secondChild--;
+ *(__first + __holeIndex) = *(__first + __secondChild);
+ __holeIndex = __secondChild;
+ __secondChild = 2 * (__secondChild + 1);
+ }
+ if (__secondChild == __len) {
+ *(__first + __holeIndex) = *(__first + (__secondChild - 1));
+ __holeIndex = __secondChild - 1;
+ }
+ __push_heap(__first, __holeIndex, __topIndex, __value);
+}
+
+template <class _RandomAccessIterator, class _Tp, class _Distance>
+inline void
+__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+ _RandomAccessIterator __result, _Tp __value, _Distance*)
+{
+ *__result = *__first;
+ __adjust_heap(__first, _Distance(0), _Distance(__last - __first), __value);
+}
+
+template <class _RandomAccessIterator, class _Tp>
+inline void
+__pop_heap_aux(_RandomAccessIterator __first, _RandomAccessIterator __last,
+ _Tp*)
+{
+ __pop_heap(__first, __last - 1, __last - 1,
+ _Tp(*(__last - 1)), __DISTANCE_TYPE(__first));
+}
+
+template <class _RandomAccessIterator>
+inline void pop_heap(_RandomAccessIterator __first,
+ _RandomAccessIterator __last)
+{
+ __pop_heap_aux(__first, __last, __VALUE_TYPE(__first));
+}
+
+template <class _RandomAccessIterator, class _Distance,
+ class _Tp, class _Compare>
+void
+__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
+ _Distance __len, _Tp __value, _Compare __comp)
+{
+ _Distance __topIndex = __holeIndex;
+ _Distance __secondChild = 2 * __holeIndex + 2;
+ while (__secondChild < __len) {
+ if (__comp(*(__first + __secondChild), *(__first + (__secondChild - 1))))
+ __secondChild--;
+ *(__first + __holeIndex) = *(__first + __secondChild);
+ __holeIndex = __secondChild;
+ __secondChild = 2 * (__secondChild + 1);
+ }
+ if (__secondChild == __len) {
+ *(__first + __holeIndex) = *(__first + (__secondChild - 1));
+ __holeIndex = __secondChild - 1;
+ }
+ __push_heap(__first, __holeIndex, __topIndex, __value, __comp);
+}
+
+template <class _RandomAccessIterator, class _Tp, class _Compare,
+ class _Distance>
+inline void
+__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+ _RandomAccessIterator __result, _Tp __value, _Compare __comp,
+ _Distance*)
+{
+ *__result = *__first;
+ __adjust_heap(__first, _Distance(0), _Distance(__last - __first),
+ __value, __comp);
+}
+
+template <class _RandomAccessIterator, class _Tp, class _Compare>
+inline void
+__pop_heap_aux(_RandomAccessIterator __first,
+ _RandomAccessIterator __last, _Tp*, _Compare __comp)
+{
+ __pop_heap(__first, __last - 1, __last - 1, _Tp(*(__last - 1)), __comp,
+ __DISTANCE_TYPE(__first));
+}
+
+template <class _RandomAccessIterator, class _Compare>
+inline void
+pop_heap(_RandomAccessIterator __first,
+ _RandomAccessIterator __last, _Compare __comp)
+{
+ __pop_heap_aux(__first, __last, __VALUE_TYPE(__first), __comp);
+}
+
+template <class _RandomAccessIterator, class _Tp, class _Distance>
+void
+__make_heap(_RandomAccessIterator __first,
+ _RandomAccessIterator __last, _Tp*, _Distance*)
+{
+ if (__last - __first < 2) return;
+ _Distance __len = __last - __first;
+ _Distance __parent = (__len - 2)/2;
+
+ while (true) {
+ __adjust_heap(__first, __parent, __len, _Tp(*(__first + __parent)));
+ if (__parent == 0) return;
+ __parent--;
+ }
+}
+
+template <class _RandomAccessIterator>
+inline void
+make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+ __make_heap(__first, __last,
+ __VALUE_TYPE(__first), __DISTANCE_TYPE(__first));
+}
+
+template <class _RandomAccessIterator, class _Compare,
+ class _Tp, class _Distance>
+void
+__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+ _Compare __comp, _Tp*, _Distance*)
+{
+ if (__last - __first < 2) return;
+ _Distance __len = __last - __first;
+ _Distance __parent = (__len - 2)/2;
+
+ while (true) {
+ __adjust_heap(__first, __parent, __len, _Tp(*(__first + __parent)),
+ __comp);
+ if (__parent == 0) return;
+ __parent--;
+ }
+}
+
+template <class _RandomAccessIterator, class _Compare>
+inline void
+make_heap(_RandomAccessIterator __first,
+ _RandomAccessIterator __last, _Compare __comp)
+{
+ __make_heap(__first, __last, __comp,
+ __VALUE_TYPE(__first), __DISTANCE_TYPE(__first));
+}
+
+template <class _RandomAccessIterator>
+void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+{
+ while (__last - __first > 1)
+ pop_heap(__first, __last--);
+}
+
+template <class _RandomAccessIterator, class _Compare>
+void
+sort_heap(_RandomAccessIterator __first,
+ _RandomAccessIterator __last, _Compare __comp)
+{
+ while (__last - __first > 1)
+ pop_heap(__first, __last--, __comp);
+}
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1209
+#endif
+
+__STL_END_NAMESPACE
+
+#endif /* _CPP_BITS_STL_HEAP_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_iterator.h b/libstdc++-v3/bits/stl_iterator.h
new file mode 100644
index 0000000..16b657e
--- /dev/null
+++ b/libstdc++-v3/bits/stl_iterator.h
@@ -0,0 +1,1093 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996-1998
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_ITERATOR_H
+#define __SGI_STL_INTERNAL_ITERATOR_H
+
+__STL_BEGIN_NAMESPACE
+
+
+template <class _Container>
+class back_insert_iterator {
+protected:
+ _Container* container;
+public:
+ typedef _Container container_type;
+ typedef output_iterator_tag iterator_category;
+ typedef void value_type;
+ typedef void difference_type;
+ typedef void pointer;
+ typedef void reference;
+
+ explicit back_insert_iterator(_Container& __x) : container(&__x) {}
+ back_insert_iterator<_Container>&
+ operator=(const typename _Container::value_type& __value) {
+ container->push_back(__value);
+ return *this;
+ }
+ back_insert_iterator<_Container>& operator*() { return *this; }
+ back_insert_iterator<_Container>& operator++() { return *this; }
+ back_insert_iterator<_Container>& operator++(int) { return *this; }
+};
+
+#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _Container>
+inline output_iterator_tag
+iterator_category(const back_insert_iterator<_Container>&)
+{
+ return output_iterator_tag();
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _Container>
+inline back_insert_iterator<_Container> back_inserter(_Container& __x) {
+ return back_insert_iterator<_Container>(__x);
+}
+
+template <class _Container>
+class front_insert_iterator {
+protected:
+ _Container* container;
+public:
+ typedef _Container container_type;
+ typedef output_iterator_tag iterator_category;
+ typedef void value_type;
+ typedef void difference_type;
+ typedef void pointer;
+ typedef void reference;
+
+ explicit front_insert_iterator(_Container& __x) : container(&__x) {}
+ front_insert_iterator<_Container>&
+ operator=(const typename _Container::value_type& __value) {
+ container->push_front(__value);
+ return *this;
+ }
+ front_insert_iterator<_Container>& operator*() { return *this; }
+ front_insert_iterator<_Container>& operator++() { return *this; }
+ front_insert_iterator<_Container>& operator++(int) { return *this; }
+};
+
+#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _Container>
+inline output_iterator_tag
+iterator_category(const front_insert_iterator<_Container>&)
+{
+ return output_iterator_tag();
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _Container>
+inline front_insert_iterator<_Container> front_inserter(_Container& __x) {
+ return front_insert_iterator<_Container>(__x);
+}
+
+template <class _Container>
+class insert_iterator {
+protected:
+ _Container* container;
+ typename _Container::iterator iter;
+public:
+ typedef _Container container_type;
+ typedef output_iterator_tag iterator_category;
+ typedef void value_type;
+ typedef void difference_type;
+ typedef void pointer;
+ typedef void reference;
+
+ insert_iterator(_Container& __x, typename _Container::iterator __i)
+ : container(&__x), iter(__i) {}
+ insert_iterator<_Container>&
+ operator=(const typename _Container::value_type& __value) {
+ iter = container->insert(iter, __value);
+ ++iter;
+ return *this;
+ }
+ insert_iterator<_Container>& operator*() { return *this; }
+ insert_iterator<_Container>& operator++() { return *this; }
+ insert_iterator<_Container>& operator++(int) { return *this; }
+};
+
+#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _Container>
+inline output_iterator_tag
+iterator_category(const insert_iterator<_Container>&)
+{
+ return output_iterator_tag();
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _Container, class _Iterator>
+inline
+insert_iterator<_Container> inserter(_Container& __x, _Iterator __i)
+{
+ typedef typename _Container::iterator __iter;
+ return insert_iterator<_Container>(__x, __iter(__i));
+}
+
+template <class _BidirectionalIterator, class _Tp, class _Reference = _Tp&,
+ class _Distance = ptrdiff_t>
+class reverse_bidirectional_iterator {
+ typedef reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
+ _Reference, _Distance> _Self;
+protected:
+ _BidirectionalIterator current;
+public:
+ typedef bidirectional_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef _Distance difference_type;
+ typedef _Tp* pointer;
+ typedef _Reference reference;
+
+ reverse_bidirectional_iterator() {}
+ explicit reverse_bidirectional_iterator(_BidirectionalIterator __x)
+ : current(__x) {}
+ _BidirectionalIterator base() const { return current; }
+ _Reference operator*() const {
+ _BidirectionalIterator __tmp = current;
+ return *--__tmp;
+ }
+#ifndef __SGI_STL_NO_ARROW_OPERATOR
+ pointer operator->() const { return &(operator*()); }
+#endif /* __SGI_STL_NO_ARROW_OPERATOR */
+ _Self& operator++() {
+ --current;
+ return *this;
+ }
+ _Self operator++(int) {
+ _Self __tmp = *this;
+ --current;
+ return __tmp;
+ }
+ _Self& operator--() {
+ ++current;
+ return *this;
+ }
+ _Self operator--(int) {
+ _Self __tmp = *this;
+ ++current;
+ return __tmp;
+ }
+};
+
+#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _BidirectionalIterator, class _Tp, class _Reference,
+ class _Distance>
+inline bidirectional_iterator_tag
+iterator_category(const reverse_bidirectional_iterator<_BidirectionalIterator,
+ _Tp, _Reference,
+ _Distance>&)
+{
+ return bidirectional_iterator_tag();
+}
+
+template <class _BidirectionalIterator, class _Tp, class _Reference,
+ class _Distance>
+inline _Tp*
+value_type(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
+ _Reference, _Distance>&)
+{
+ return (_Tp*) 0;
+}
+
+template <class _BidirectionalIterator, class _Tp, class _Reference,
+ class _Distance>
+inline _Distance*
+distance_type(const reverse_bidirectional_iterator<_BidirectionalIterator,
+ _Tp,
+ _Reference, _Distance>&)
+{
+ return (_Distance*) 0;
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _BiIter, class _Tp, class _Ref, class _Distance>
+inline bool operator==(
+ const reverse_bidirectional_iterator<_BiIter, _Tp, _Ref, _Distance>& __x,
+ const reverse_bidirectional_iterator<_BiIter, _Tp, _Ref, _Distance>& __y)
+{
+ return __x.base() == __y.base();
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _BiIter, class _Tp, class _Ref, class _Distance>
+inline bool operator!=(
+ const reverse_bidirectional_iterator<_BiIter, _Tp, _Ref, _Distance>& __x,
+ const reverse_bidirectional_iterator<_BiIter, _Tp, _Ref, _Distance>& __y)
+{
+ return !(__x == __y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+// This is the new version of reverse_iterator, as defined in the
+// draft C++ standard. It relies on the iterator_traits template,
+// which in turn relies on partial specialization. The class
+// reverse_bidirectional_iterator is no longer part of the draft
+// standard, but it is retained for backward compatibility.
+
+template <class _Iterator>
+class reverse_iterator
+{
+protected:
+ _Iterator current;
+public:
+ typedef typename iterator_traits<_Iterator>::iterator_category
+ iterator_category;
+ typedef typename iterator_traits<_Iterator>::value_type
+ value_type;
+ typedef typename iterator_traits<_Iterator>::difference_type
+ difference_type;
+ typedef typename iterator_traits<_Iterator>::pointer
+ pointer;
+ typedef typename iterator_traits<_Iterator>::reference
+ reference;
+
+ typedef _Iterator iterator_type;
+ typedef reverse_iterator<_Iterator> _Self;
+
+public:
+ reverse_iterator() {}
+ explicit reverse_iterator(iterator_type __x) : current(__x) {}
+
+ reverse_iterator(const _Self& __x) : current(__x.current) {}
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _Iter>
+ reverse_iterator(const reverse_iterator<_Iter>& __x)
+ : current(__x.base()) {}
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ iterator_type base() const { return current; }
+ reference operator*() const {
+ _Iterator __tmp = current;
+ return *--__tmp;
+ }
+#ifndef __SGI_STL_NO_ARROW_OPERATOR
+ pointer operator->() const { return &(operator*()); }
+#endif /* __SGI_STL_NO_ARROW_OPERATOR */
+
+ _Self& operator++() {
+ --current;
+ return *this;
+ }
+ _Self operator++(int) {
+ _Self __tmp = *this;
+ --current;
+ return __tmp;
+ }
+ _Self& operator--() {
+ ++current;
+ return *this;
+ }
+ _Self operator--(int) {
+ _Self __tmp = *this;
+ ++current;
+ return __tmp;
+ }
+
+ _Self operator+(difference_type __n) const {
+ return _Self(current - __n);
+ }
+ _Self& operator+=(difference_type __n) {
+ current -= __n;
+ return *this;
+ }
+ _Self operator-(difference_type __n) const {
+ return _Self(current + __n);
+ }
+ _Self& operator-=(difference_type __n) {
+ current += __n;
+ return *this;
+ }
+ reference operator[](difference_type __n) const { return *(*this + __n); }
+};
+
+template <class _Iterator>
+inline bool operator==(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y) {
+ return __x.base() == __y.base();
+}
+
+template <class _Iterator>
+inline bool operator<(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y) {
+ return __y.base() < __x.base();
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Iterator>
+inline bool operator!=(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y) {
+ return !(__x == __y);
+}
+
+template <class _Iterator>
+inline bool operator>(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y) {
+ return __y < __x;
+}
+
+template <class _Iterator>
+inline bool operator<=(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y) {
+ return !(__y < __x);
+}
+
+template <class _Iterator>
+inline bool operator>=(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y) {
+ return !(__x < __y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+template <class _Iterator>
+inline typename reverse_iterator<_Iterator>::difference_type
+operator-(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y) {
+ return __y.base() - __x.base();
+}
+
+template <class _Iterator>
+inline reverse_iterator<_Iterator>
+operator+(typename reverse_iterator<_Iterator>::difference_type __n,
+ const reverse_iterator<_Iterator>& __x) {
+ return reverse_iterator<_Iterator>(__x.base() - __n);
+}
+
+#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+// This is the old version of reverse_iterator, as found in the original
+// HP STL. It does not use partial specialization.
+
+template <class _RandomAccessIterator, class _Tp, class _Reference = _Tp&,
+ class _Distance = ptrdiff_t>
+class reverse_iterator {
+ typedef reverse_iterator<_RandomAccessIterator, _Tp, _Reference, _Distance>
+ _Self;
+protected:
+ _RandomAccessIterator current;
+public:
+ typedef random_access_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef _Distance difference_type;
+ typedef _Tp* pointer;
+ typedef _Reference reference;
+
+ reverse_iterator() {}
+ explicit reverse_iterator(_RandomAccessIterator __x) : current(__x) {}
+ _RandomAccessIterator base() const { return current; }
+ _Reference operator*() const { return *(current - 1); }
+#ifndef __SGI_STL_NO_ARROW_OPERATOR
+ pointer operator->() const { return &(operator*()); }
+#endif /* __SGI_STL_NO_ARROW_OPERATOR */
+ _Self& operator++() {
+ --current;
+ return *this;
+ }
+ _Self operator++(int) {
+ _Self __tmp = *this;
+ --current;
+ return __tmp;
+ }
+ _Self& operator--() {
+ ++current;
+ return *this;
+ }
+ _Self operator--(int) {
+ _Self __tmp = *this;
+ ++current;
+ return __tmp;
+ }
+ _Self operator+(_Distance __n) const {
+ return _Self(current - __n);
+ }
+ _Self& operator+=(_Distance __n) {
+ current -= __n;
+ return *this;
+ }
+ _Self operator-(_Distance __n) const {
+ return _Self(current + __n);
+ }
+ _Self& operator-=(_Distance __n) {
+ current += __n;
+ return *this;
+ }
+ _Reference operator[](_Distance __n) const { return *(*this + __n); }
+};
+
+template <class _RandomAccessIterator, class _Tp,
+ class _Reference, class _Distance>
+inline random_access_iterator_tag
+iterator_category(const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>&)
+{
+ return random_access_iterator_tag();
+}
+
+template <class _RandomAccessIterator, class _Tp,
+ class _Reference, class _Distance>
+inline _Tp* value_type(const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>&)
+{
+ return (_Tp*) 0;
+}
+
+template <class _RandomAccessIterator, class _Tp,
+ class _Reference, class _Distance>
+inline _Distance*
+distance_type(const reverse_iterator<_RandomAccessIterator,
+ _Tp, _Reference, _Distance>&)
+{
+ return (_Distance*) 0;
+}
+
+
+template <class _RandomAccessIterator, class _Tp,
+ class _Reference, class _Distance>
+inline bool
+operator==(const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __x,
+ const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __y)
+{
+ return __x.base() == __y.base();
+}
+
+template <class _RandomAccessIterator, class _Tp,
+ class _Reference, class _Distance>
+inline bool
+operator<(const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __x,
+ const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __y)
+{
+ return __y.base() < __x.base();
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _RandomAccessIterator, class _Tp,
+ class _Reference, class _Distance>
+inline bool
+operator!=(const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __x,
+ const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __y) {
+ return !(__x == __y); }
+}
+
+template <class _RandomAccessIterator, class _Tp,
+ class _Reference, class _Distance>
+inline bool
+operator>(const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __x,
+ const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __y) {
+ return __y < __x;
+}
+
+template <class _RandomAccessIterator, class _Tp,
+ class _Reference, class _Distance>
+inline bool
+operator<=(const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __x,
+ const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __y) {
+ return !(__y < __x);
+}
+
+template <class _RandomAccessIterator, class _Tp,
+ class _Reference, class _Distance>
+inline bool
+operator>=(const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __x,
+ const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __y) {
+ return !(__x < __y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+template <class _RandomAccessIterator, class _Tp,
+ class _Reference, class _Distance>
+inline _Distance
+operator-(const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __x,
+ const reverse_iterator<_RandomAccessIterator, _Tp,
+ _Reference, _Distance>& __y)
+{
+ return __y.base() - __x.base();
+}
+
+template <class _RandAccIter, class _Tp, class _Ref, class _Dist>
+inline reverse_iterator<_RandAccIter, _Tp, _Ref, _Dist>
+operator+(_Dist __n,
+ const reverse_iterator<_RandAccIter, _Tp, _Ref, _Dist>& __x)
+{
+ return reverse_iterator<_RandAccIter, _Tp, _Ref, _Dist>(__x.base() - __n);
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+// istream_iterator and ostream_iterator look very different if we're
+// using new, templatized iostreams than if we're using the old cfront
+// version.
+
+#ifdef __STL_USE_NEW_IOSTREAMS
+
+template <class _Tp,
+ class _CharT = char, class _Traits = char_traits<_CharT>,
+ class _Dist = ptrdiff_t>
+class istream_iterator {
+public:
+ typedef _CharT char_type;
+ typedef _Traits traits_type;
+ typedef basic_istream<_CharT, _Traits> istream_type;
+
+ typedef input_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef _Dist difference_type;
+ typedef const _Tp* pointer;
+ typedef const _Tp& reference;
+
+ istream_iterator() : _M_stream(0), _M_ok(false) {}
+ istream_iterator(istream_type& __s) : _M_stream(&__s) { _M_read(); }
+
+ reference operator*() const { return _M_value; }
+ pointer operator->() const { return &(operator*()); }
+
+ istream_iterator& operator++() {
+ _M_read();
+ return *this;
+ }
+ istream_iterator operator++(int) {
+ istream_iterator __tmp = *this;
+ _M_read();
+ return __tmp;
+ }
+
+ bool _M_equal(const istream_iterator& __x) const
+ { return (_M_ok == __x._M_ok) && (!_M_ok || _M_stream == __x._M_stream); }
+
+private:
+ istream_type* _M_stream;
+ _Tp _M_value;
+ bool _M_ok;
+
+ void _M_read() {
+ _M_ok = (_M_stream && *_M_stream) ? true : false;
+ if (_M_ok) {
+ *_M_stream >> _M_value;
+ _M_ok = *_M_stream ? true : false;
+ }
+ }
+};
+
+template <class _Tp, class _CharT, class _Traits, class _Dist>
+inline bool
+operator==(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
+ const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __y) {
+ return __x._M_equal(__y);
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Tp, class _CharT, class _Traits, class _Dist>
+inline bool
+operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
+ const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __y) {
+ return !__x._M_equal(__y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+template <class _Tp,
+ class _CharT = char, class _Traits = char_traits<_CharT> >
+class ostream_iterator {
+public:
+ typedef _CharT char_type;
+ typedef _Traits traits_type;
+ typedef basic_ostream<_CharT, _Traits> ostream_type;
+
+ typedef output_iterator_tag iterator_category;
+ typedef void value_type;
+ typedef void difference_type;
+ typedef void pointer;
+ typedef void reference;
+
+ ostream_iterator(ostream_type& __s) : _M_stream(&__s), _M_string(0) {}
+ ostream_iterator(ostream_type& __s, const _CharT* __c)
+ : _M_stream(&__s), _M_string(__c) {}
+ ostream_iterator<_Tp>& operator=(const _Tp& __value) {
+ *_M_stream << __value;
+ if (_M_string) *_M_stream << _M_string;
+ return *this;
+ }
+ ostream_iterator<_Tp>& operator*() { return *this; }
+ ostream_iterator<_Tp>& operator++() { return *this; }
+ ostream_iterator<_Tp>& operator++(int) { return *this; }
+private:
+ ostream_type* _M_stream;
+ const _CharT* _M_string;
+};
+
+// The default template argument is declared in iosfwd
+
+// We do not read any characters until operator* is called. The first
+// time operator* is called, it calls getc. Subsequent calls to getc
+// return a cached character, and calls to operator++ use snextc. Before
+// operator* or operator++ has been called, _M_is_initialized is false.
+template<class _CharT, class _Traits>
+class istreambuf_iterator
+{
+public:
+ typedef _CharT char_type;
+ typedef _Traits traits_type;
+ typedef typename _Traits::int_type int_type;
+ typedef basic_streambuf<_CharT, _Traits> streambuf_type;
+ typedef basic_istream<_CharT, _Traits> istream_type;
+
+ typedef input_iterator_tag iterator_category;
+ typedef _CharT value_type;
+ typedef typename _Traits::off_type difference_type;
+ typedef const _CharT* pointer;
+ typedef const _CharT& reference;
+
+public:
+ istreambuf_iterator(streambuf_type* __p = 0) { this->_M_init(__p); }
+ istreambuf_iterator(istream_type& __is) { this->_M_init(__is.rdbuf()); }
+
+ char_type operator*() const
+ { return _M_is_initialized ? _M_c : _M_dereference_aux(); }
+
+ istreambuf_iterator& operator++() { this->_M_nextc(); return *this; }
+ istreambuf_iterator operator++(int) {
+ if (!_M_is_initialized)
+ _M_postincr_aux();
+ istreambuf_iterator __tmp = *this;
+ this->_M_nextc();
+ return __tmp;
+ }
+
+ bool equal(const istreambuf_iterator& __i) const {
+ return this->_M_is_initialized && __i._M_is_initialized
+ ? this->_M_eof == __i._M_eof
+ : this->_M_equal_aux(__i);
+ }
+
+private:
+ void _M_init(streambuf_type* __p) {
+ _M_buf = __p;
+ _M_eof = !__p;
+ _M_is_initialized = _M_eof;
+ }
+
+ char_type _M_dereference_aux() const;
+ bool _M_equal_aux(const istreambuf_iterator&) const;
+ void _M_postincr_aux();
+
+ void _M_nextc() {
+ int_type __c = _M_buf->snextc();
+ _M_c = traits_type::to_char_type(__c);
+ _M_eof = traits_type::eq_int_type(__c, traits_type::eof());
+ _M_is_initialized = true;
+ }
+
+ void _M_getc() const {
+ int_type __c = _M_buf->sgetc();
+ _M_c = traits_type::to_char_type(__c);
+ _M_eof = traits_type::eq_int_type(__c, traits_type::eof());
+ _M_is_initialized = true;
+ }
+
+private:
+ streambuf_type* _M_buf;
+ mutable _CharT _M_c;
+ mutable bool _M_eof : 1;
+ mutable bool _M_is_initialized : 1;
+};
+
+template<class _CharT, class _Traits>
+_CharT istreambuf_iterator<_CharT, _Traits>::_M_dereference_aux() const
+{
+ this->_M_getc();
+ return _M_c;
+}
+
+template<class _CharT, class _Traits>
+bool istreambuf_iterator<_CharT, _Traits>
+ ::_M_equal_aux(const istreambuf_iterator& __i) const
+{
+ if (!this->_M_is_initialized)
+ this->_M_getc();
+ if (!__i._M_is_initialized)
+ __i._M_getc();
+
+ return this->_M_eof == __i._M_eof;
+}
+
+template<class _CharT, class _Traits>
+void istreambuf_iterator<_CharT, _Traits>::_M_postincr_aux()
+{
+ this->_M_getc();
+}
+
+template<class _CharT, class _Traits>
+inline bool operator==(const istreambuf_iterator<_CharT, _Traits>& __x,
+ const istreambuf_iterator<_CharT, _Traits>& __y) {
+ return __x.equal(__y);
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template<class _CharT, class _Traits>
+inline bool operator!=(const istreambuf_iterator<_CharT, _Traits>& __x,
+ const istreambuf_iterator<_CharT, _Traits>& __y) {
+ return !__x.equal(__y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+// The default template argument is declared in iosfwd
+template<class _CharT, class _Traits>
+class ostreambuf_iterator
+{
+public:
+ typedef _CharT char_type;
+ typedef _Traits traits_type;
+ typedef typename _Traits::int_type int_type;
+ typedef basic_streambuf<_CharT, _Traits> streambuf_type;
+ typedef basic_ostream<_CharT, _Traits> ostream_type;
+
+ typedef output_iterator_tag iterator_category;
+ typedef void value_type;
+ typedef void difference_type;
+ typedef void pointer;
+ typedef void reference;
+
+public:
+ ostreambuf_iterator(streambuf_type* __buf) : _M_buf(__buf), _M_ok(__buf) {}
+ ostreambuf_iterator(ostream_type& __o)
+ : _M_buf(__o.rdbuf()), _M_ok(__o.rdbuf()) {}
+
+ ostreambuf_iterator& operator=(char_type __c) {
+ _M_ok = _M_ok && !traits_type::eq_int_type(_M_buf->sputc(__c),
+ traits_type::eof());
+ return *this;
+ }
+
+ ostreambuf_iterator& operator*() { return *this; }
+ ostreambuf_iterator& operator++() { return *this; }
+ ostreambuf_iterator& operator++(int) { return *this; }
+
+ bool failed() const { return !_M_ok; }
+
+private:
+ streambuf_type* _M_buf;
+ bool _M_ok;
+};
+
+#else /* __STL_USE_NEW_IOSTREAMS */
+
+template <class _Tp, class _Dist = ptrdiff_t> class istream_iterator;
+
+template <class _Tp, class _Dist>
+inline bool operator==(const istream_iterator<_Tp, _Dist>&,
+ const istream_iterator<_Tp, _Dist>&);
+
+template <class _Tp, class _Dist>
+class istream_iterator {
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _T1, class _D1>
+ friend bool operator==(const istream_iterator<_T1, _D1>&,
+ const istream_iterator<_T1, _D1>&);
+#else /* __STL_MEMBER_TEMPLATES */
+ friend bool __STD_QUALIFIER
+ operator== __STL_NULL_TMPL_ARGS (const istream_iterator&,
+ const istream_iterator&);
+#endif /* __STL_MEMBER_TEMPLATES */
+
+protected:
+ istream* _M_stream;
+ _Tp _M_value;
+ bool _M_end_marker;
+ void _M_read() {
+ _M_end_marker = (*_M_stream) ? true : false;
+ if (_M_end_marker) *_M_stream >> _M_value;
+ _M_end_marker = (*_M_stream) ? true : false;
+ }
+public:
+ typedef input_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef _Dist difference_type;
+ typedef const _Tp* pointer;
+ typedef const _Tp& reference;
+
+ istream_iterator() : _M_stream(&cin), _M_end_marker(false) {}
+ istream_iterator(istream& __s) : _M_stream(&__s) { _M_read(); }
+ reference operator*() const { return _M_value; }
+#ifndef __SGI_STL_NO_ARROW_OPERATOR
+ pointer operator->() const { return &(operator*()); }
+#endif /* __SGI_STL_NO_ARROW_OPERATOR */
+ istream_iterator<_Tp, _Dist>& operator++() {
+ _M_read();
+ return *this;
+ }
+ istream_iterator<_Tp, _Dist> operator++(int) {
+ istream_iterator<_Tp, _Dist> __tmp = *this;
+ _M_read();
+ return __tmp;
+ }
+};
+
+#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _Tp, class _Dist>
+inline input_iterator_tag
+iterator_category(const istream_iterator<_Tp, _Dist>&)
+{
+ return input_iterator_tag();
+}
+
+template <class _Tp, class _Dist>
+inline _Tp*
+value_type(const istream_iterator<_Tp, _Dist>&) { return (_Tp*) 0; }
+
+template <class _Tp, class _Dist>
+inline _Dist*
+distance_type(const istream_iterator<_Tp, _Dist>&) { return (_Dist*)0; }
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _Tp, class _Distance>
+inline bool operator==(const istream_iterator<_Tp, _Distance>& __x,
+ const istream_iterator<_Tp, _Distance>& __y) {
+ return (__x._M_stream == __y._M_stream &&
+ __x._M_end_marker == __y._M_end_marker) ||
+ __x._M_end_marker == false && __y._M_end_marker == false;
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Tp, class _Distance>
+inline bool operator!=(const istream_iterator<_Tp, _Distance>& __x,
+ const istream_iterator<_Tp, _Distance>& __y) {
+ return !(__x == __y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+template <class _Tp>
+class ostream_iterator {
+protected:
+ ostream* _M_stream;
+ const char* _M_string;
+public:
+ typedef output_iterator_tag iterator_category;
+ typedef void value_type;
+ typedef void difference_type;
+ typedef void pointer;
+ typedef void reference;
+
+ ostream_iterator(ostream& __s) : _M_stream(&__s), _M_string(0) {}
+ ostream_iterator(ostream& __s, const char* __c)
+ : _M_stream(&__s), _M_string(__c) {}
+ ostream_iterator<_Tp>& operator=(const _Tp& __value) {
+ *_M_stream << __value;
+ if (_M_string) *_M_stream << _M_string;
+ return *this;
+ }
+ ostream_iterator<_Tp>& operator*() { return *this; }
+ ostream_iterator<_Tp>& operator++() { return *this; }
+ ostream_iterator<_Tp>& operator++(int) { return *this; }
+};
+
+#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _Tp>
+inline output_iterator_tag
+iterator_category(const ostream_iterator<_Tp>&) {
+ return output_iterator_tag();
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+#endif /* __STL_USE_NEW_IOSTREAMS */
+
+// This iterator adapter is 'normal' in the sense that it does not
+// change the semantics of any of the operators of its itererator
+// parameter. Its primary purpose is to convert an iterator that is
+// not a class, e.g. a pointer, into an iterator that is a class.
+// The _Container parameter exists solely so that different containers
+// using this template can instantiate different types, even if the
+// _Iterator parameter is the same.
+template<typename _Iterator, typename _Container>
+class __normal_iterator
+ : public iterator<iterator_traits<_Iterator>::iterator_category,
+ iterator_traits<_Iterator>::value_type,
+ iterator_traits<_Iterator>::difference_type,
+ iterator_traits<_Iterator>::pointer,
+ iterator_traits<_Iterator>::reference>
+{
+public:
+
+ typedef __normal_iterator<_Iterator, _Container> normal_iterator_type;
+
+ inline __normal_iterator() : _M_current() { }
+
+ inline explicit __normal_iterator(const _Iterator& __i)
+ : _M_current(__i) { }
+
+ // Allow iterator to const_iterator conversion
+ template<typename _Iter>
+ inline __normal_iterator(const __normal_iterator<_Iter, _Container>& __i)
+ : _M_current(__i.base()) { }
+
+ // forward iterator requirements
+
+ inline reference
+ operator*() const
+ { return *_M_current; }
+
+ inline pointer
+ operator->() const
+ { return _M_current; }
+
+ inline normal_iterator_type&
+ operator++()
+ { ++_M_current; return *this; }
+
+ inline normal_iterator_type
+ operator++(int)
+ { return __normal_iterator(_M_current++); }
+
+ // bidirectional iterator requirements
+
+ inline normal_iterator_type&
+ operator--()
+ { --_M_current; return *this; }
+
+ inline normal_iterator_type
+ operator--(int)
+ { return __normal_iterator(_M_current--); }
+
+ // random access iterator requirements
+
+ inline reference
+ operator[](const difference_type& __n) const
+ { return _M_current[__n]; }
+
+ inline normal_iterator_type&
+ operator+=(const difference_type& __n)
+ { _M_current += __n; return *this; }
+
+ inline normal_iterator_type
+ operator+(const difference_type& __n) const
+ { return __normal_iterator(_M_current + __n); }
+
+ inline normal_iterator_type&
+ operator-=(const difference_type& __n)
+ { _M_current -= __n; return *this; }
+
+ inline normal_iterator_type
+ operator-(const difference_type& __n) const
+ { return __normal_iterator(_M_current - __n); }
+
+ inline difference_type
+ operator-(const normal_iterator_type& __i) const
+ { return _M_current - __i._M_current; }
+
+ const _Iterator& base() const
+ { return _M_current; }
+
+protected:
+ _Iterator _M_current;
+};
+
+// forward iterator requirements
+
+template<typename _IteratorL, typename _IteratorR, typename _Container>
+bool operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+{ return __lhs.base() == __rhs.base(); }
+
+template<typename _IteratorL, typename _IteratorR, typename _Container>
+bool operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+{ return !(__lhs == __rhs); }
+
+// random access iterator requirements
+
+template<typename _IteratorL, typename _IteratorR, typename _Container>
+bool operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+{ return __lhs.base() < __rhs.base(); }
+
+template<typename _IteratorL, typename _IteratorR, typename _Container>
+bool operator>(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+{ return __rhs < __lhs; }
+
+template<typename _IteratorL, typename _IteratorR, typename _Container>
+bool operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+{ return !(__rhs < __lhs); }
+
+template<typename _IteratorL, typename _IteratorR, typename _Container>
+bool operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+{ return !(__lhs < __rhs); }
+
+template<typename _Iterator, typename _Container>
+inline __normal_iterator<_Iterator, _Container>
+operator+(__normal_iterator<_Iterator, _Container>::difference_type __n,
+ const __normal_iterator<_Iterator, _Container>& __i)
+{ return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_ITERATOR_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_iterator_base.h b/libstdc++-v3/bits/stl_iterator_base.h
new file mode 100644
index 0000000..d26888e
--- /dev/null
+++ b/libstdc++-v3/bits/stl_iterator_base.h
@@ -0,0 +1,358 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996-1998
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_ITERATOR_BASE_H
+#define __SGI_STL_INTERNAL_ITERATOR_BASE_H
+
+// This file contains all of the general iterator-related utilities.
+// The internal file stl_iterator.h contains predefined iterators,
+// such as front_insert_iterator and istream_iterator.
+
+__STL_BEGIN_NAMESPACE
+
+struct input_iterator_tag {};
+struct output_iterator_tag {};
+struct forward_iterator_tag : public input_iterator_tag {};
+struct bidirectional_iterator_tag : public forward_iterator_tag {};
+struct random_access_iterator_tag : public bidirectional_iterator_tag {};
+
+// The base classes input_iterator, output_iterator, forward_iterator,
+// bidirectional_iterator, and random_access_iterator are not part of
+// the C++ standard. (They have been replaced by struct iterator.)
+// They are included for backward compatibility with the HP STL.
+
+template <class _Tp, class _Distance> struct input_iterator {
+ typedef input_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef _Distance difference_type;
+ typedef _Tp* pointer;
+ typedef _Tp& reference;
+};
+
+struct output_iterator {
+ typedef output_iterator_tag iterator_category;
+ typedef void value_type;
+ typedef void difference_type;
+ typedef void pointer;
+ typedef void reference;
+};
+
+template <class _Tp, class _Distance> struct forward_iterator {
+ typedef forward_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef _Distance difference_type;
+ typedef _Tp* pointer;
+ typedef _Tp& reference;
+};
+
+
+template <class _Tp, class _Distance> struct bidirectional_iterator {
+ typedef bidirectional_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef _Distance difference_type;
+ typedef _Tp* pointer;
+ typedef _Tp& reference;
+};
+
+template <class _Tp, class _Distance> struct random_access_iterator {
+ typedef random_access_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef _Distance difference_type;
+ typedef _Tp* pointer;
+ typedef _Tp& reference;
+};
+
+#ifdef __STL_USE_NAMESPACES
+template <class _Category, class _Tp, class _Distance = ptrdiff_t,
+ class _Pointer = _Tp*, class _Reference = _Tp&>
+struct iterator {
+ typedef _Category iterator_category;
+ typedef _Tp value_type;
+ typedef _Distance difference_type;
+ typedef _Pointer pointer;
+ typedef _Reference reference;
+};
+#endif /* __STL_USE_NAMESPACES */
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _Iterator>
+struct iterator_traits {
+ typedef typename _Iterator::iterator_category iterator_category;
+ typedef typename _Iterator::value_type value_type;
+ typedef typename _Iterator::difference_type difference_type;
+ typedef typename _Iterator::pointer pointer;
+ typedef typename _Iterator::reference reference;
+};
+
+template <class _Tp>
+struct iterator_traits<_Tp*> {
+ typedef random_access_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef ptrdiff_t difference_type;
+ typedef _Tp* pointer;
+ typedef _Tp& reference;
+};
+
+template <class _Tp>
+struct iterator_traits<const _Tp*> {
+ typedef random_access_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef ptrdiff_t difference_type;
+ typedef const _Tp* pointer;
+ typedef const _Tp& reference;
+};
+
+// The overloaded functions iterator_category, distance_type, and
+// value_type are not part of the C++ standard. (They have been
+// replaced by struct iterator_traits.) They are included for
+// backward compatibility with the HP STL.
+
+// We introduce internal names for these functions.
+
+template <class _Iter>
+inline typename iterator_traits<_Iter>::iterator_category
+__iterator_category(const _Iter&)
+{
+ typedef typename iterator_traits<_Iter>::iterator_category _Category;
+ return _Category();
+}
+
+template <class _Iter>
+inline typename iterator_traits<_Iter>::difference_type*
+__distance_type(const _Iter&)
+{
+ return static_cast<typename iterator_traits<_Iter>::difference_type*>(0);
+}
+
+template <class _Iter>
+inline typename iterator_traits<_Iter>::value_type*
+__value_type(const _Iter&)
+{
+ return static_cast<typename iterator_traits<_Iter>::value_type*>(0);
+}
+
+template <class _Iter>
+inline typename iterator_traits<_Iter>::iterator_category
+iterator_category(const _Iter& __i) { return __iterator_category(__i); }
+
+
+template <class _Iter>
+inline typename iterator_traits<_Iter>::difference_type*
+distance_type(const _Iter& __i) { return __distance_type(__i); }
+
+template <class _Iter>
+inline typename iterator_traits<_Iter>::value_type*
+value_type(const _Iter& __i) { return __value_type(__i); }
+
+#define __ITERATOR_CATEGORY(__i) __iterator_category(__i)
+#define __DISTANCE_TYPE(__i) __distance_type(__i)
+#define __VALUE_TYPE(__i) __value_type(__i)
+
+#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _Tp, class _Distance>
+inline input_iterator_tag
+iterator_category(const input_iterator<_Tp, _Distance>&)
+ { return input_iterator_tag(); }
+
+inline output_iterator_tag iterator_category(const output_iterator&)
+ { return output_iterator_tag(); }
+
+template <class _Tp, class _Distance>
+inline forward_iterator_tag
+iterator_category(const forward_iterator<_Tp, _Distance>&)
+ { return forward_iterator_tag(); }
+
+template <class _Tp, class _Distance>
+inline bidirectional_iterator_tag
+iterator_category(const bidirectional_iterator<_Tp, _Distance>&)
+ { return bidirectional_iterator_tag(); }
+
+template <class _Tp, class _Distance>
+inline random_access_iterator_tag
+iterator_category(const random_access_iterator<_Tp, _Distance>&)
+ { return random_access_iterator_tag(); }
+
+template <class _Tp>
+inline random_access_iterator_tag iterator_category(const _Tp*)
+ { return random_access_iterator_tag(); }
+
+template <class _Tp, class _Distance>
+inline _Tp* value_type(const input_iterator<_Tp, _Distance>&)
+ { return (_Tp*)(0); }
+
+template <class _Tp, class _Distance>
+inline _Tp* value_type(const forward_iterator<_Tp, _Distance>&)
+ { return (_Tp*)(0); }
+
+template <class _Tp, class _Distance>
+inline _Tp* value_type(const bidirectional_iterator<_Tp, _Distance>&)
+ { return (_Tp*)(0); }
+
+template <class _Tp, class _Distance>
+inline _Tp* value_type(const random_access_iterator<_Tp, _Distance>&)
+ { return (_Tp*)(0); }
+
+template <class _Tp>
+inline _Tp* value_type(const _Tp*) { return (_Tp*)(0); }
+
+template <class _Tp, class _Distance>
+inline _Distance* distance_type(const input_iterator<_Tp, _Distance>&)
+{
+ return (_Distance*)(0);
+}
+
+template <class _Tp, class _Distance>
+inline _Distance* distance_type(const forward_iterator<_Tp, _Distance>&)
+{
+ return (_Distance*)(0);
+}
+
+template <class _Tp, class _Distance>
+inline _Distance*
+distance_type(const bidirectional_iterator<_Tp, _Distance>&)
+{
+ return (_Distance*)(0);
+}
+
+template <class _Tp, class _Distance>
+inline _Distance*
+distance_type(const random_access_iterator<_Tp, _Distance>&)
+{
+ return (_Distance*)(0);
+}
+
+template <class _Tp>
+inline ptrdiff_t* distance_type(const _Tp*) { return (ptrdiff_t*)(0); }
+
+// Without partial specialization we can't use iterator_traits, so
+// we must keep the old iterator query functions around.
+
+#define __ITERATOR_CATEGORY(__i) iterator_category(__i)
+#define __DISTANCE_TYPE(__i) distance_type(__i)
+#define __VALUE_TYPE(__i) value_type(__i)
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _InputIterator, class _Distance>
+inline void __distance(_InputIterator __first, _InputIterator __last,
+ _Distance& __n, input_iterator_tag)
+{
+ while (__first != __last) { ++__first; ++__n; }
+}
+
+template <class _RandomAccessIterator, class _Distance>
+inline void __distance(_RandomAccessIterator __first,
+ _RandomAccessIterator __last,
+ _Distance& __n, random_access_iterator_tag)
+{
+ __n += __last - __first;
+}
+
+template <class _InputIterator, class _Distance>
+inline void distance(_InputIterator __first,
+ _InputIterator __last, _Distance& __n)
+{
+ __distance(__first, __last, __n, iterator_category(__first));
+}
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _InputIterator>
+inline typename iterator_traits<_InputIterator>::difference_type
+__distance(_InputIterator __first, _InputIterator __last, input_iterator_tag)
+{
+ typename iterator_traits<_InputIterator>::difference_type __n = 0;
+ while (__first != __last) {
+ ++__first; ++__n;
+ }
+ return __n;
+}
+
+template <class _RandomAccessIterator>
+inline typename iterator_traits<_RandomAccessIterator>::difference_type
+__distance(_RandomAccessIterator __first, _RandomAccessIterator __last,
+ random_access_iterator_tag) {
+ return __last - __first;
+}
+
+template <class _InputIterator>
+inline typename iterator_traits<_InputIterator>::difference_type
+distance(_InputIterator __first, _InputIterator __last) {
+ typedef typename iterator_traits<_InputIterator>::iterator_category
+ _Category;
+ return __distance(__first, __last, _Category());
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+template <class _InputIter, class _Distance>
+inline void __advance(_InputIter& __i, _Distance __n, input_iterator_tag) {
+ while (__n--) ++__i;
+}
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1183
+#endif
+
+template <class _BidirectionalIterator, class _Distance>
+inline void __advance(_BidirectionalIterator& __i, _Distance __n,
+ bidirectional_iterator_tag) {
+ if (__n >= 0)
+ while (__n--) ++__i;
+ else
+ while (__n++) --__i;
+}
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1183
+#endif
+
+template <class _RandomAccessIterator, class _Distance>
+inline void __advance(_RandomAccessIterator& __i, _Distance __n,
+ random_access_iterator_tag) {
+ __i += __n;
+}
+
+template <class _InputIterator, class _Distance>
+inline void advance(_InputIterator& __i, _Distance __n) {
+ __advance(__i, __n, iterator_category(__i));
+}
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_ITERATOR_BASE_H */
+
+
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_list.h b/libstdc++-v3/bits/stl_list.h
new file mode 100644
index 0000000..b5b88ed
--- /dev/null
+++ b/libstdc++-v3/bits/stl_list.h
@@ -0,0 +1,867 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_LIST_H
+#define __SGI_STL_INTERNAL_LIST_H
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1174
+#pragma set woff 1375
+#endif
+
+template <class _Tp>
+struct _List_node {
+ typedef void* _Void_pointer;
+ _Void_pointer _M_next;
+ _Void_pointer _M_prev;
+ _Tp _M_data;
+};
+
+template<class _Tp, class _Ref, class _Ptr>
+struct _List_iterator {
+ typedef _List_iterator<_Tp,_Tp&,_Tp*> iterator;
+ typedef _List_iterator<_Tp,const _Tp&,const _Tp*> const_iterator;
+ typedef _List_iterator<_Tp,_Ref,_Ptr> _Self;
+
+ typedef bidirectional_iterator_tag iterator_category;
+ typedef _Tp value_type;
+ typedef _Ptr pointer;
+ typedef _Ref reference;
+ typedef _List_node<_Tp> _Node;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+
+ _Node* _M_node;
+
+ _List_iterator(_Node* __x) : _M_node(__x) {}
+ _List_iterator() {}
+ _List_iterator(const iterator& __x) : _M_node(__x._M_node) {}
+
+ bool operator==(const _Self& __x) const { return _M_node == __x._M_node; }
+ bool operator!=(const _Self& __x) const { return _M_node != __x._M_node; }
+ reference operator*() const { return (*_M_node)._M_data; }
+
+#ifndef __SGI_STL_NO_ARROW_OPERATOR
+ pointer operator->() const { return &(operator*()); }
+#endif /* __SGI_STL_NO_ARROW_OPERATOR */
+
+ _Self& operator++() {
+ _M_node = (_Node*)(_M_node->_M_next);
+ return *this;
+ }
+ _Self operator++(int) {
+ _Self __tmp = *this;
+ ++*this;
+ return __tmp;
+ }
+ _Self& operator--() {
+ _M_node = (_Node*)(_M_node->_M_prev);
+ return *this;
+ }
+ _Self operator--(int) {
+ _Self __tmp = *this;
+ --*this;
+ return __tmp;
+ }
+};
+
+#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _Tp, class _Ref, class _Ptr>
+inline bidirectional_iterator_tag
+iterator_category(const _List_iterator<_Tp, _Ref, _Ptr>&)
+{
+ return bidirectional_iterator_tag();
+}
+
+template <class _Tp, class _Ref, class _Ptr>
+inline _Tp*
+value_type(const _List_iterator<_Tp, _Ref, _Ptr>&)
+{
+ return 0;
+}
+
+template <class _Tp, class _Ref, class _Ptr>
+inline ptrdiff_t*
+distance_type(const _List_iterator<_Tp, _Ref, _Ptr>&)
+{
+ return 0;
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+
+// Base class that encapsulates details of allocators. Three cases:
+// an ordinary standard-conforming allocator, a standard-conforming
+// allocator with no non-static data, and an SGI-style allocator.
+// This complexity is necessary only because we're worrying about backward
+// compatibility and because we want to avoid wasting storage on an
+// allocator instance if it isn't necessary.
+
+#ifdef __STL_USE_STD_ALLOCATORS
+
+// Base for general standard-conforming allocators.
+template <class _Tp, class _Allocator, bool _IsStatic>
+class _List_alloc_base {
+public:
+ typedef typename _Alloc_traits<_Tp, _Allocator>::allocator_type
+ allocator_type;
+ allocator_type get_allocator() const { return _Node_allocator; }
+
+ _List_alloc_base(const allocator_type& __a) : _Node_allocator(__a) {}
+
+protected:
+ _List_node<_Tp>* _M_get_node()
+ { return _Node_allocator.allocate(1); }
+ void _M_put_node(_List_node<_Tp>* __p)
+ { _Node_allocator.deallocate(__p, 1); }
+
+protected:
+ typename _Alloc_traits<_List_node<_Tp>, _Allocator>::allocator_type
+ _Node_allocator;
+ _List_node<_Tp>* _M_node;
+};
+
+// Specialization for instanceless allocators.
+
+template <class _Tp, class _Allocator>
+class _List_alloc_base<_Tp, _Allocator, true> {
+public:
+ typedef typename _Alloc_traits<_Tp, _Allocator>::allocator_type
+ allocator_type;
+ allocator_type get_allocator() const { return allocator_type(); }
+
+ _List_alloc_base(const allocator_type&) {}
+
+protected:
+ typedef typename _Alloc_traits<_List_node<_Tp>, _Allocator>::_Alloc_type
+ _Alloc_type;
+ _List_node<_Tp>* _M_get_node() { return _Alloc_type::allocate(1); }
+ void _M_put_node(_List_node<_Tp>* __p) { _Alloc_type::deallocate(__p, 1); }
+
+protected:
+ _List_node<_Tp>* _M_node;
+};
+
+template <class _Tp, class _Alloc>
+class _List_base
+ : public _List_alloc_base<_Tp, _Alloc,
+ _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
+{
+public:
+ typedef _List_alloc_base<_Tp, _Alloc,
+ _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
+ _Base;
+ typedef typename _Base::allocator_type allocator_type;
+
+ _List_base(const allocator_type& __a) : _Base(__a) {
+ _M_node = _M_get_node();
+ _M_node->_M_next = _M_node;
+ _M_node->_M_prev = _M_node;
+ }
+ ~_List_base() {
+ clear();
+ _M_put_node(_M_node);
+ }
+
+ void clear();
+};
+
+#else /* __STL_USE_STD_ALLOCATORS */
+
+template <class _Tp, class _Alloc>
+class _List_base
+{
+public:
+ typedef _Alloc allocator_type;
+ allocator_type get_allocator() const { return allocator_type(); }
+
+ _List_base(const allocator_type&) {
+ _M_node = _M_get_node();
+ _M_node->_M_next = _M_node;
+ _M_node->_M_prev = _M_node;
+ }
+ ~_List_base() {
+ clear();
+ _M_put_node(_M_node);
+ }
+
+ void clear();
+
+protected:
+ typedef simple_alloc<_List_node<_Tp>, _Alloc> _Alloc_type;
+ _List_node<_Tp>* _M_get_node() { return _Alloc_type::allocate(1); }
+ void _M_put_node(_List_node<_Tp>* __p) { _Alloc_type::deallocate(__p, 1); }
+
+protected:
+ _List_node<_Tp>* _M_node;
+};
+
+#endif /* __STL_USE_STD_ALLOCATORS */
+
+template <class _Tp, class _Alloc>
+void
+_List_base<_Tp,_Alloc>::clear()
+{
+ _List_node<_Tp>* __cur = (_List_node<_Tp>*) _M_node->_M_next;
+ while (__cur != _M_node) {
+ _List_node<_Tp>* __tmp = __cur;
+ __cur = (_List_node<_Tp>*) __cur->_M_next;
+ destroy(&__tmp->_M_data);
+ _M_put_node(__tmp);
+ }
+ _M_node->_M_next = _M_node;
+ _M_node->_M_prev = _M_node;
+}
+
+template <class _Tp, class _Alloc = allocator<_Tp> >
+class list : protected _List_base<_Tp, _Alloc> {
+ typedef _List_base<_Tp, _Alloc> _Base;
+protected:
+ typedef void* _Void_pointer;
+
+public:
+ typedef _Tp value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef _List_node<_Tp> _Node;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+
+ typedef typename _Base::allocator_type allocator_type;
+ allocator_type get_allocator() const { return _Base::get_allocator(); }
+
+public:
+ typedef _List_iterator<_Tp,_Tp&,_Tp*> iterator;
+ typedef _List_iterator<_Tp,const _Tp&,const _Tp*> const_iterator;
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+ typedef reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef reverse_iterator<iterator> reverse_iterator;
+#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+ typedef reverse_bidirectional_iterator<const_iterator,value_type,
+ const_reference,difference_type>
+ const_reverse_iterator;
+ typedef reverse_bidirectional_iterator<iterator,value_type,reference,
+ difference_type>
+ reverse_iterator;
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+protected:
+#ifdef __STL_HAS_NAMESPACES
+ using _Base::_M_node;
+ using _Base::_M_put_node;
+ using _Base::_M_get_node;
+#endif /* __STL_HAS_NAMESPACES */
+
+protected:
+ _Node* _M_create_node(const _Tp& __x)
+ {
+ _Node* __p = _M_get_node();
+ __STL_TRY {
+ construct(&__p->_M_data, __x);
+ }
+ __STL_UNWIND(_M_put_node(__p));
+ return __p;
+ }
+
+ _Node* _M_create_node()
+ {
+ _Node* __p = _M_get_node();
+ __STL_TRY {
+ construct(&__p->_M_data);
+ }
+ __STL_UNWIND(_M_put_node(__p));
+ return __p;
+ }
+
+public:
+ explicit list(const allocator_type& __a = allocator_type()) : _Base(__a) {}
+
+ iterator begin() { return (_Node*)(_M_node->_M_next); }
+ const_iterator begin() const { return (_Node*)(_M_node->_M_next); }
+
+ iterator end() { return _M_node; }
+ const_iterator end() const { return _M_node; }
+
+ 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()); }
+
+ bool empty() const { return _M_node->_M_next == _M_node; }
+ size_type size() const {
+ size_type __result = 0;
+ distance(begin(), end(), __result);
+ return __result;
+ }
+ size_type max_size() const { return size_type(-1); }
+
+ reference front() { return *begin(); }
+ const_reference front() const { return *begin(); }
+ reference back() { return *(--end()); }
+ const_reference back() const { return *(--end()); }
+
+ void swap(list<_Tp, _Alloc>& __x) { __STD::swap(_M_node, __x._M_node); }
+
+ iterator insert(iterator __position, const _Tp& __x) {
+ _Node* __tmp = _M_create_node(__x);
+ __tmp->_M_next = __position._M_node;
+ __tmp->_M_prev = __position._M_node->_M_prev;
+ ((_Node*) (__position._M_node->_M_prev))->_M_next = __tmp;
+ __position._M_node->_M_prev = __tmp;
+ return __tmp;
+ }
+ iterator insert(iterator __position) { return insert(__position, _Tp()); }
+#ifdef __STL_MEMBER_TEMPLATES
+ // Check whether it's an integral type. If so, it's not an iterator.
+
+ template<class _Integer>
+ void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
+ __true_type) {
+ _M_fill_insert(__pos, (size_type) __n, (_Tp) __x);
+ }
+
+ template <class _InputIterator>
+ void _M_insert_dispatch(iterator __pos,
+ _InputIterator __first, _InputIterator __last,
+ __false_type);
+
+ template <class _InputIterator>
+ void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
+ typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
+ _M_insert_dispatch(__pos, __first, __last, _Integral());
+ }
+
+#else /* __STL_MEMBER_TEMPLATES */
+ void insert(iterator __position, const _Tp* __first, const _Tp* __last);
+ void insert(iterator __position,
+ const_iterator __first, const_iterator __last);
+#endif /* __STL_MEMBER_TEMPLATES */
+ void insert(iterator __pos, size_type __n, const _Tp& __x)
+ { _M_fill_insert(__pos, __n, __x); }
+ void _M_fill_insert(iterator __pos, size_type __n, const _Tp& __x);
+
+ void push_front(const _Tp& __x) { insert(begin(), __x); }
+ void push_front() {insert(begin());}
+ void push_back(const _Tp& __x) { insert(end(), __x); }
+ void push_back() {insert(end());}
+
+ iterator erase(iterator __position) {
+ _Node* __next_node = (_Node*) (__position._M_node->_M_next);
+ _Node* __prev_node = (_Node*) (__position._M_node->_M_prev);
+ __prev_node->_M_next = __next_node;
+ __next_node->_M_prev = __prev_node;
+ destroy(&__position._M_node->_M_data);
+ _M_put_node(__position._M_node);
+ return iterator(__next_node);
+ }
+ iterator erase(iterator __first, iterator __last);
+ void clear() { _Base::clear(); }
+
+ void resize(size_type __new_size, const _Tp& __x);
+ void resize(size_type __new_size) { resize(__new_size, _Tp()); }
+
+ void pop_front() { erase(begin()); }
+ void pop_back() {
+ iterator __tmp = end();
+ erase(--__tmp);
+ }
+ list(size_type __n, const _Tp& __value,
+ const allocator_type& __a = allocator_type())
+ : _Base(__a)
+ { insert(begin(), __n, __value); }
+ explicit list(size_type __n)
+ : _Base(allocator_type())
+ { insert(begin(), __n, _Tp()); }
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+ // We don't need any dispatching tricks here, because insert does all of
+ // that anyway.
+ template <class _InputIterator>
+ list(_InputIterator __first, _InputIterator __last,
+ const allocator_type& __a = allocator_type())
+ : _Base(__a)
+ { insert(begin(), __first, __last); }
+
+#else /* __STL_MEMBER_TEMPLATES */
+
+ list(const _Tp* __first, const _Tp* __last,
+ const allocator_type& __a = allocator_type())
+ : _Base(__a)
+ { insert(begin(), __first, __last); }
+ list(const_iterator __first, const_iterator __last,
+ const allocator_type& __a = allocator_type())
+ : _Base(__a)
+ { insert(begin(), __first, __last); }
+
+#endif /* __STL_MEMBER_TEMPLATES */
+ list(const list<_Tp, _Alloc>& __x) : _Base(__x.get_allocator())
+ { insert(begin(), __x.begin(), __x.end()); }
+
+ ~list() { }
+
+ list<_Tp, _Alloc>& operator=(const list<_Tp, _Alloc>& __x);
+
+public:
+ // assign(), a generalized assignment member function. Two
+ // versions: one that takes a count, and one that takes a range.
+ // The range version is a member template, so we dispatch on whether
+ // or not the type is an integer.
+
+ void assign(size_type __n, const _Tp& __val) { _M_fill_assign(__n, __val); }
+
+ void _M_fill_assign(size_type __n, const _Tp& __val);
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+ template <class _InputIterator>
+ void assign(_InputIterator __first, _InputIterator __last) {
+ typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
+ _M_assign_dispatch(__first, __last, _Integral());
+ }
+
+ template <class _Integer>
+ void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
+ { _M_fill_assign((size_type) __n, (_Tp) __val); }
+
+ template <class _InputIterator>
+ void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
+ __false_type);
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+protected:
+ void transfer(iterator __position, iterator __first, iterator __last) {
+ if (__position != __last) {
+ // Remove [first, last) from its old position.
+ ((_Node*) (__last._M_node->_M_prev))->_M_next = __position._M_node;
+ ((_Node*) (__first._M_node->_M_prev))->_M_next = __last._M_node;
+ ((_Node*) (__position._M_node->_M_prev))->_M_next = __first._M_node;
+
+ // Splice [first, last) into its new position.
+ _Node* __tmp = (_Node*) (__position._M_node->_M_prev);
+ __position._M_node->_M_prev = __last._M_node->_M_prev;
+ __last._M_node->_M_prev = __first._M_node->_M_prev;
+ __first._M_node->_M_prev = __tmp;
+ }
+ }
+
+public:
+ void splice(iterator __position, list& __x) {
+ if (!__x.empty())
+ transfer(__position, __x.begin(), __x.end());
+ }
+ void splice(iterator __position, list&, iterator __i) {
+ iterator __j = __i;
+ ++__j;
+ if (__position == __i || __position == __j) return;
+ transfer(__position, __i, __j);
+ }
+ void splice(iterator __position, list&, iterator __first, iterator __last) {
+ if (__first != __last)
+ transfer(__position, __first, __last);
+ }
+ void remove(const _Tp& __value);
+ void unique();
+ void merge(list& __x);
+ void reverse();
+ void sort();
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _Predicate> void remove_if(_Predicate);
+ template <class _BinaryPredicate> void unique(_BinaryPredicate);
+ template <class _StrictWeakOrdering> void merge(list&, _StrictWeakOrdering);
+ template <class _StrictWeakOrdering> void sort(_StrictWeakOrdering);
+#endif /* __STL_MEMBER_TEMPLATES */
+};
+
+template <class _Tp, class _Alloc>
+inline bool
+operator==(const list<_Tp,_Alloc>& __x, const list<_Tp,_Alloc>& __y)
+{
+ typedef typename list<_Tp,_Alloc>::const_iterator const_iterator;
+ const_iterator __end1 = __x.end();
+ const_iterator __end2 = __y.end();
+
+ const_iterator __i1 = __x.begin();
+ const_iterator __i2 = __y.begin();
+ while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) {
+ ++__i1;
+ ++__i2;
+ }
+ return __i1 == __end1 && __i2 == __end2;
+}
+
+template <class _Tp, class _Alloc>
+inline bool operator<(const list<_Tp,_Alloc>& __x,
+ const list<_Tp,_Alloc>& __y)
+{
+ return lexicographical_compare(__x.begin(), __x.end(),
+ __y.begin(), __y.end());
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Tp, class _Alloc>
+inline bool operator!=(const list<_Tp,_Alloc>& __x,
+ const list<_Tp,_Alloc>& __y) {
+ return !(__x == __y);
+}
+
+template <class _Tp, class _Alloc>
+inline bool operator>(const list<_Tp,_Alloc>& __x,
+ const list<_Tp,_Alloc>& __y) {
+ return __y < __x;
+}
+
+template <class _Tp, class _Alloc>
+inline bool operator<=(const list<_Tp,_Alloc>& __x,
+ const list<_Tp,_Alloc>& __y) {
+ return !(__y < __x);
+}
+
+template <class _Tp, class _Alloc>
+inline bool operator>=(const list<_Tp,_Alloc>& __x,
+ const list<_Tp,_Alloc>& __y) {
+ return !(__x < __y);
+}
+
+template <class _Tp, class _Alloc>
+inline void
+swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
+{
+ __x.swap(__y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+template <class _Tp, class _Alloc> template <class _InputIter>
+void
+list<_Tp, _Alloc>::_M_insert_dispatch(iterator __position,
+ _InputIter __first, _InputIter __last,
+ __false_type)
+{
+ for ( ; __first != __last; ++__first)
+ insert(__position, *__first);
+}
+
+#else /* __STL_MEMBER_TEMPLATES */
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::insert(iterator __position,
+ const _Tp* __first, const _Tp* __last)
+{
+ for ( ; __first != __last; ++__first)
+ insert(__position, *__first);
+}
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::insert(iterator __position,
+ const_iterator __first, const_iterator __last)
+{
+ for ( ; __first != __last; ++__first)
+ insert(__position, *__first);
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+template <class _Tp, class _Alloc>
+void
+list<_Tp, _Alloc>::_M_fill_insert(iterator __position,
+ size_type __n, const _Tp& __x)
+{
+ for ( ; __n > 0; --__n)
+ insert(__position, __x);
+}
+
+template <class _Tp, class _Alloc>
+list<_Tp,_Alloc>::iterator list<_Tp, _Alloc>::erase(iterator __first,
+ iterator __last)
+{
+ while (__first != __last)
+ erase(__first++);
+ return __last;
+}
+
+template <class _Tp, class _Alloc>
+void list<_Tp, _Alloc>::resize(size_type __new_size, const _Tp& __x)
+{
+ iterator __i = begin();
+ size_type __len = 0;
+ for ( ; __i != end() && __len < __new_size; ++__i, ++__len)
+ ;
+ if (__len == __new_size)
+ erase(__i, end());
+ else // __i == end()
+ insert(end(), __new_size - __len, __x);
+}
+
+template <class _Tp, class _Alloc>
+list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(const list<_Tp, _Alloc>& __x)
+{
+ if (this != &__x) {
+ iterator __first1 = begin();
+ iterator __last1 = end();
+ const_iterator __first2 = __x.begin();
+ const_iterator __last2 = __x.end();
+ while (__first1 != __last1 && __first2 != __last2)
+ *__first1++ = *__first2++;
+ if (__first2 == __last2)
+ erase(__first1, __last1);
+ else
+ insert(__last1, __first2, __last2);
+ }
+ return *this;
+}
+
+template <class _Tp, class _Alloc>
+void list<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
+ iterator __i = begin();
+ for ( ; __i != end() && __n > 0; ++__i, --__n)
+ *__i = __val;
+ if (__n > 0)
+ insert(end(), __n, __val);
+ else
+ erase(__i, end());
+}
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+template <class _Tp, class _Alloc> template <class _InputIter>
+void
+list<_Tp, _Alloc>::_M_assign_dispatch(_InputIter __first2, _InputIter __last2,
+ __false_type)
+{
+ iterator __first1 = begin();
+ iterator __last1 = end();
+ for ( ; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
+ *__first1 = *__first2;
+ if (__first2 == __last2)
+ erase(__first1, __last1);
+ else
+ insert(__last1, __first2, __last2);
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+template <class _Tp, class _Alloc>
+void list<_Tp, _Alloc>::remove(const _Tp& __value)
+{
+ iterator __first = begin();
+ iterator __last = end();
+ while (__first != __last) {
+ iterator __next = __first;
+ ++__next;
+ if (*__first == __value) erase(__first);
+ __first = __next;
+ }
+}
+
+template <class _Tp, class _Alloc>
+void list<_Tp, _Alloc>::unique()
+{
+ iterator __first = begin();
+ iterator __last = end();
+ if (__first == __last) return;
+ iterator __next = __first;
+ while (++__next != __last) {
+ if (*__first == *__next)
+ erase(__next);
+ else
+ __first = __next;
+ __next = __first;
+ }
+}
+
+template <class _Tp, class _Alloc>
+void list<_Tp, _Alloc>::merge(list<_Tp, _Alloc>& __x)
+{
+ iterator __first1 = begin();
+ iterator __last1 = end();
+ iterator __first2 = __x.begin();
+ iterator __last2 = __x.end();
+ while (__first1 != __last1 && __first2 != __last2)
+ if (*__first2 < *__first1) {
+ iterator __next = __first2;
+ transfer(__first1, __first2, ++__next);
+ __first2 = __next;
+ }
+ else
+ ++__first1;
+ if (__first2 != __last2) transfer(__last1, __first2, __last2);
+}
+
+template <class _Tp, class _Alloc>
+void list<_Tp, _Alloc>::reverse()
+{
+ // Do nothing if the list has length 0 or 1.
+ if (_M_node->_M_next != _M_node &&
+ ((_Node*) (_M_node->_M_next))->_M_next != _M_node) {
+ iterator __first = begin();
+ ++__first;
+ while (__first != end()) {
+ iterator __old = __first;
+ ++__first;
+ transfer(begin(), __old, __first);
+ }
+ }
+}
+
+template <class _Tp, class _Alloc>
+void list<_Tp, _Alloc>::sort()
+{
+ // Do nothing if the list has length 0 or 1.
+ if (_M_node->_M_next != _M_node &&
+ ((_Node*) (_M_node->_M_next))->_M_next != _M_node) {
+ list<_Tp, _Alloc> __carry;
+ list<_Tp, _Alloc> __counter[64];
+ int __fill = 0;
+ while (!empty()) {
+ __carry.splice(__carry.begin(), *this, begin());
+ int __i = 0;
+ while(__i < __fill && !__counter[__i].empty()) {
+ __counter[__i].merge(__carry);
+ __carry.swap(__counter[__i++]);
+ }
+ __carry.swap(__counter[__i]);
+ if (__i == __fill) ++__fill;
+ }
+
+ for (int __i = 1; __i < __fill; ++__i)
+ __counter[__i].merge(__counter[__i-1]);
+ swap(__counter[__fill-1]);
+ }
+}
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+template <class _Tp, class _Alloc> template <class _Predicate>
+void list<_Tp, _Alloc>::remove_if(_Predicate __pred)
+{
+ iterator __first = begin();
+ iterator __last = end();
+ while (__first != __last) {
+ iterator __next = __first;
+ ++__next;
+ if (__pred(*__first)) erase(__first);
+ __first = __next;
+ }
+}
+
+template <class _Tp, class _Alloc> template <class _BinaryPredicate>
+void list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred)
+{
+ iterator __first = begin();
+ iterator __last = end();
+ if (__first == __last) return;
+ iterator __next = __first;
+ while (++__next != __last) {
+ if (__binary_pred(*__first, *__next))
+ erase(__next);
+ else
+ __first = __next;
+ __next = __first;
+ }
+}
+
+template <class _Tp, class _Alloc> template <class _StrictWeakOrdering>
+void list<_Tp, _Alloc>::merge(list<_Tp, _Alloc>& __x,
+ _StrictWeakOrdering __comp)
+{
+ iterator __first1 = begin();
+ iterator __last1 = end();
+ iterator __first2 = __x.begin();
+ iterator __last2 = __x.end();
+ while (__first1 != __last1 && __first2 != __last2)
+ if (__comp(*__first2, *__first1)) {
+ iterator __next = __first2;
+ transfer(__first1, __first2, ++__next);
+ __first2 = __next;
+ }
+ else
+ ++__first1;
+ if (__first2 != __last2) transfer(__last1, __first2, __last2);
+}
+
+template <class _Tp, class _Alloc> template <class _StrictWeakOrdering>
+void list<_Tp, _Alloc>::sort(_StrictWeakOrdering __comp)
+{
+ // Do nothing if the list has length 0 or 1.
+ if (_M_node->_M_next != _M_node &&
+ ((_Node*) (_M_node->_M_next))->_M_next != _M_node) {
+ list<_Tp, _Alloc> __carry;
+ list<_Tp, _Alloc> __counter[64];
+ int __fill = 0;
+ while (!empty()) {
+ __carry.splice(__carry.begin(), *this, begin());
+ int __i = 0;
+ while(__i < __fill && !__counter[__i].empty()) {
+ __counter[__i].merge(__carry, __comp);
+ __carry.swap(__counter[__i++]);
+ }
+ __carry.swap(__counter[__i]);
+ if (__i == __fill) ++__fill;
+ }
+
+ for (int __i = 1; __i < __fill; ++__i)
+ __counter[__i].merge(__counter[__i-1], __comp);
+ swap(__counter[__fill-1]);
+ }
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1174
+#pragma reset woff 1375
+#endif
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_LIST_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_map.h b/libstdc++-v3/bits/stl_map.h
new file mode 100644
index 0000000..1a3b630
--- /dev/null
+++ b/libstdc++-v3/bits/stl_map.h
@@ -0,0 +1,273 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef _CPP_BITS_STL_MAP_H
+#define _CPP_BITS_STL_MAP_H 1
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1174
+#pragma set woff 1375
+#endif
+
+template <class _Key, class _Tp, class _Compare = less<_Key>,
+ class _Alloc = allocator<pair<const _Key, _Tp> > >
+class map {
+public:
+
+// typedefs:
+
+ typedef _Key key_type;
+ typedef _Tp data_type;
+ typedef _Tp mapped_type;
+ typedef pair<const _Key, _Tp> value_type;
+ typedef _Compare key_compare;
+
+ class value_compare
+ : public binary_function<value_type, value_type, bool> {
+ friend class map<_Key,_Tp,_Compare,_Alloc>;
+ protected :
+ _Compare comp;
+ value_compare(_Compare __c) : comp(__c) {}
+ public:
+ bool operator()(const value_type& __x, const value_type& __y) const {
+ return comp(__x.first, __y.first);
+ }
+ };
+
+private:
+ typedef _Rb_tree<key_type, value_type,
+ _Select1st<value_type>, key_compare, _Alloc> _Rep_type;
+ _Rep_type _M_t; // red-black tree representing map
+public:
+ typedef typename _Rep_type::pointer pointer;
+ typedef typename _Rep_type::const_pointer const_pointer;
+ typedef typename _Rep_type::reference reference;
+ typedef typename _Rep_type::const_reference const_reference;
+ typedef typename _Rep_type::iterator iterator;
+ typedef typename _Rep_type::const_iterator const_iterator;
+ typedef typename _Rep_type::reverse_iterator reverse_iterator;
+ typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
+ typedef typename _Rep_type::size_type size_type;
+ typedef typename _Rep_type::difference_type difference_type;
+ typedef typename _Rep_type::allocator_type allocator_type;
+
+ // allocation/deallocation
+
+ map() : _M_t(_Compare(), allocator_type()) {}
+ explicit map(const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) {}
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ map(_InputIterator __first, _InputIterator __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_unique(__first, __last); }
+
+ template <class _InputIterator>
+ map(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
+#else
+ map(const value_type* __first, const value_type* __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_unique(__first, __last); }
+
+ map(const value_type* __first,
+ const value_type* __last, const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
+
+ map(const_iterator __first, const_iterator __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_unique(__first, __last); }
+
+ map(const_iterator __first, const_iterator __last, const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ map(const map<_Key,_Tp,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
+ map<_Key,_Tp,_Compare,_Alloc>&
+ operator=(const map<_Key, _Tp, _Compare, _Alloc>& __x)
+ {
+ _M_t = __x._M_t;
+ return *this;
+ }
+
+ // accessors:
+
+ key_compare key_comp() const { return _M_t.key_comp(); }
+ value_compare value_comp() const { return value_compare(_M_t.key_comp()); }
+ allocator_type get_allocator() const { return _M_t.get_allocator(); }
+
+ iterator begin() { return _M_t.begin(); }
+ const_iterator begin() const { return _M_t.begin(); }
+ iterator end() { return _M_t.end(); }
+ const_iterator end() const { return _M_t.end(); }
+ reverse_iterator rbegin() { return _M_t.rbegin(); }
+ const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
+ reverse_iterator rend() { return _M_t.rend(); }
+ const_reverse_iterator rend() const { return _M_t.rend(); }
+ bool empty() const { return _M_t.empty(); }
+ size_type size() const { return _M_t.size(); }
+ size_type max_size() const { return _M_t.max_size(); }
+ _Tp& operator[](const key_type& __k) {
+ iterator __i = lower_bound(__k);
+ // __i->first is greater than or equivalent to __k.
+ if (__i == end() || key_comp()(__k, (*__i).first))
+ __i = insert(__i, value_type(__k, _Tp()));
+ return (*__i).second;
+ }
+ void swap(map<_Key,_Tp,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
+
+ // insert/erase
+
+ pair<iterator,bool> insert(const value_type& __x)
+ { return _M_t.insert_unique(__x); }
+ iterator insert(iterator position, const value_type& __x)
+ { return _M_t.insert_unique(position, __x); }
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ void insert(_InputIterator __first, _InputIterator __last) {
+ _M_t.insert_unique(__first, __last);
+ }
+#else
+ void insert(const value_type* __first, const value_type* __last) {
+ _M_t.insert_unique(__first, __last);
+ }
+ void insert(const_iterator __first, const_iterator __last) {
+ _M_t.insert_unique(__first, __last);
+ }
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ void erase(iterator __position) { _M_t.erase(__position); }
+ size_type erase(const key_type& __x) { return _M_t.erase(__x); }
+ void erase(iterator __first, iterator __last)
+ { _M_t.erase(__first, __last); }
+ void clear() { _M_t.clear(); }
+
+ // map operations:
+
+ iterator find(const key_type& __x) { return _M_t.find(__x); }
+ const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
+ size_type count(const key_type& __x) const { return _M_t.count(__x); }
+ iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); }
+ const_iterator lower_bound(const key_type& __x) const {
+ return _M_t.lower_bound(__x);
+ }
+ iterator upper_bound(const key_type& __x) {return _M_t.upper_bound(__x); }
+ const_iterator upper_bound(const key_type& __x) const {
+ return _M_t.upper_bound(__x);
+ }
+
+ pair<iterator,iterator> equal_range(const key_type& __x) {
+ return _M_t.equal_range(__x);
+ }
+ pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
+ return _M_t.equal_range(__x);
+ }
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _K1, class _T1, class _C1, class _A1>
+ friend bool operator== (const map<_K1, _T1, _C1, _A1>&,
+ const map<_K1, _T1, _C1, _A1>&);
+ template <class _K1, class _T1, class _C1, class _A1>
+ friend bool operator< (const map<_K1, _T1, _C1, _A1>&,
+ const map<_K1, _T1, _C1, _A1>&);
+#else /* __STL_MEMBER_TEMPLATES */
+ friend bool __STD_QUALIFIER
+ operator== __STL_NULL_TMPL_ARGS (const map&, const map&);
+ friend bool __STD_QUALIFIER
+ operator< __STL_NULL_TMPL_ARGS (const map&, const map&);
+#endif /* __STL_MEMBER_TEMPLATES */
+};
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator==(const map<_Key,_Tp,_Compare,_Alloc>& __x,
+ const map<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return __x._M_t == __y._M_t;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator<(const map<_Key,_Tp,_Compare,_Alloc>& __x,
+ const map<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return __x._M_t < __y._M_t;
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator!=(const map<_Key,_Tp,_Compare,_Alloc>& __x,
+ const map<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return !(__x == __y);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator>(const map<_Key,_Tp,_Compare,_Alloc>& __x,
+ const map<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return __y < __x;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator<=(const map<_Key,_Tp,_Compare,_Alloc>& __x,
+ const map<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return !(__y < __x);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator>=(const map<_Key,_Tp,_Compare,_Alloc>& __x,
+ const map<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return !(__x < __y);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline void swap(map<_Key,_Tp,_Compare,_Alloc>& __x,
+ map<_Key,_Tp,_Compare,_Alloc>& __y) {
+ __x.swap(__y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1174
+#pragma reset woff 1375
+#endif
+
+__STL_END_NAMESPACE
+
+#endif /* _CPP_BITS_STL_MAP_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_multimap.h b/libstdc++-v3/bits/stl_multimap.h
new file mode 100644
index 0000000..c8a861b
--- /dev/null
+++ b/libstdc++-v3/bits/stl_multimap.h
@@ -0,0 +1,275 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_MULTIMAP_H
+#define __SGI_STL_INTERNAL_MULTIMAP_H
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1174
+#pragma set woff 1375
+#endif
+
+// Forward declaration of operators < and ==, needed for friend declaration.
+
+template <class _Key, class _Tp,
+ class _Compare = less<_Key>,
+ class _Alloc = allocator<pair<const _Key, _Tp> > >
+class multimap;
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator==(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
+ const multimap<_Key,_Tp,_Compare,_Alloc>& __y);
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator<(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
+ const multimap<_Key,_Tp,_Compare,_Alloc>& __y);
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+class multimap {
+public:
+
+// typedefs:
+
+ typedef _Key key_type;
+ typedef _Tp data_type;
+ typedef _Tp mapped_type;
+ typedef pair<const _Key, _Tp> value_type;
+ typedef _Compare key_compare;
+
+ class value_compare : public binary_function<value_type, value_type, bool> {
+ friend class multimap<_Key,_Tp,_Compare,_Alloc>;
+ protected:
+ _Compare comp;
+ value_compare(_Compare __c) : comp(__c) {}
+ public:
+ bool operator()(const value_type& __x, const value_type& __y) const {
+ return comp(__x.first, __y.first);
+ }
+ };
+
+private:
+ typedef _Rb_tree<key_type, value_type,
+ _Select1st<value_type>, key_compare, _Alloc> _Rep_type;
+ _Rep_type _M_t; // red-black tree representing multimap
+public:
+ typedef typename _Rep_type::pointer pointer;
+ typedef typename _Rep_type::const_pointer const_pointer;
+ typedef typename _Rep_type::reference reference;
+ typedef typename _Rep_type::const_reference const_reference;
+ typedef typename _Rep_type::iterator iterator;
+ typedef typename _Rep_type::const_iterator const_iterator;
+ typedef typename _Rep_type::reverse_iterator reverse_iterator;
+ typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
+ typedef typename _Rep_type::size_type size_type;
+ typedef typename _Rep_type::difference_type difference_type;
+ typedef typename _Rep_type::allocator_type allocator_type;
+
+// allocation/deallocation
+
+ multimap() : _M_t(_Compare(), allocator_type()) { }
+ explicit multimap(const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { }
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ multimap(_InputIterator __first, _InputIterator __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_equal(__first, __last); }
+
+ template <class _InputIterator>
+ multimap(_InputIterator __first, _InputIterator __last,
+ const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
+#else
+ multimap(const value_type* __first, const value_type* __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_equal(__first, __last); }
+ multimap(const value_type* __first, const value_type* __last,
+ const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
+
+ multimap(const_iterator __first, const_iterator __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_equal(__first, __last); }
+ multimap(const_iterator __first, const_iterator __last,
+ const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ multimap(const multimap<_Key,_Tp,_Compare,_Alloc>& __x) : _M_t(__x._M_t) { }
+ multimap<_Key,_Tp,_Compare,_Alloc>&
+ operator=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x) {
+ _M_t = __x._M_t;
+ return *this;
+ }
+
+ // accessors:
+
+ key_compare key_comp() const { return _M_t.key_comp(); }
+ value_compare value_comp() const { return value_compare(_M_t.key_comp()); }
+ allocator_type get_allocator() const { return _M_t.get_allocator(); }
+
+ iterator begin() { return _M_t.begin(); }
+ const_iterator begin() const { return _M_t.begin(); }
+ iterator end() { return _M_t.end(); }
+ const_iterator end() const { return _M_t.end(); }
+ reverse_iterator rbegin() { return _M_t.rbegin(); }
+ const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
+ reverse_iterator rend() { return _M_t.rend(); }
+ const_reverse_iterator rend() const { return _M_t.rend(); }
+ bool empty() const { return _M_t.empty(); }
+ size_type size() const { return _M_t.size(); }
+ size_type max_size() const { return _M_t.max_size(); }
+ void swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
+
+ // insert/erase
+
+ iterator insert(const value_type& __x) { return _M_t.insert_equal(__x); }
+ iterator insert(iterator __position, const value_type& __x) {
+ return _M_t.insert_equal(__position, __x);
+ }
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ void insert(_InputIterator __first, _InputIterator __last) {
+ _M_t.insert_equal(__first, __last);
+ }
+#else
+ void insert(const value_type* __first, const value_type* __last) {
+ _M_t.insert_equal(__first, __last);
+ }
+ void insert(const_iterator __first, const_iterator __last) {
+ _M_t.insert_equal(__first, __last);
+ }
+#endif /* __STL_MEMBER_TEMPLATES */
+ void erase(iterator __position) { _M_t.erase(__position); }
+ size_type erase(const key_type& __x) { return _M_t.erase(__x); }
+ void erase(iterator __first, iterator __last)
+ { _M_t.erase(__first, __last); }
+ void clear() { _M_t.clear(); }
+
+ // multimap operations:
+
+ iterator find(const key_type& __x) { return _M_t.find(__x); }
+ const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
+ size_type count(const key_type& __x) const { return _M_t.count(__x); }
+ iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); }
+ const_iterator lower_bound(const key_type& __x) const {
+ return _M_t.lower_bound(__x);
+ }
+ iterator upper_bound(const key_type& __x) {return _M_t.upper_bound(__x); }
+ const_iterator upper_bound(const key_type& __x) const {
+ return _M_t.upper_bound(__x);
+ }
+ pair<iterator,iterator> equal_range(const key_type& __x) {
+ return _M_t.equal_range(__x);
+ }
+ pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
+ return _M_t.equal_range(__x);
+ }
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _K1, class _T1, class _C1, class _A1>
+ friend bool operator== (const multimap<_K1, _T1, _C1, _A1>&,
+ const multimap<_K1, _T1, _C1, _A1>&);
+ template <class _K1, class _T1, class _C1, class _A1>
+ friend bool operator< (const multimap<_K1, _T1, _C1, _A1>&,
+ const multimap<_K1, _T1, _C1, _A1>&);
+#else /* __STL_MEMBER_TEMPLATES */
+ friend bool __STD_QUALIFIER
+ operator== __STL_NULL_TMPL_ARGS (const multimap&, const multimap&);
+ friend bool __STD_QUALIFIER
+ operator< __STL_NULL_TMPL_ARGS (const multimap&, const multimap&);
+#endif /* __STL_MEMBER_TEMPLATES */
+};
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator==(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
+ const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return __x._M_t == __y._M_t;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator<(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
+ const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return __x._M_t < __y._M_t;
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator!=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
+ const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return !(__x == __y);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator>(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
+ const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return __y < __x;
+}
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator<=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
+ const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return !(__y < __x);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline bool operator>=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
+ const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
+ return !(__x < __y);
+}
+
+template <class _Key, class _Tp, class _Compare, class _Alloc>
+inline void swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x,
+ multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
+ __x.swap(__y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1174
+#pragma reset woff 1375
+#endif
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_MULTIMAP_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_multiset.h b/libstdc++-v3/bits/stl_multiset.h
new file mode 100644
index 0000000..eda4dab
--- /dev/null
+++ b/libstdc++-v3/bits/stl_multiset.h
@@ -0,0 +1,266 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_MULTISET_H
+#define __SGI_STL_INTERNAL_MULTISET_H
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1174
+#pragma set woff 1375
+#endif
+
+// Forward declaration of operators < and ==, needed for friend declaration.
+
+template <class _Key, class _Compare = less<_Key>,
+ class _Alloc = allocator<_Key> >
+class multiset;
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator==(const multiset<_Key,_Compare,_Alloc>& __x,
+ const multiset<_Key,_Compare,_Alloc>& __y);
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x,
+ const multiset<_Key,_Compare,_Alloc>& __y);
+
+template <class _Key, class _Compare, class _Alloc>
+class multiset {
+public:
+ // typedefs:
+
+ typedef _Key key_type;
+ typedef _Key value_type;
+ typedef _Compare key_compare;
+ typedef _Compare value_compare;
+private:
+ typedef _Rb_tree<key_type, value_type,
+ _Identity<value_type>, key_compare, _Alloc> _Rep_type;
+ _Rep_type _M_t; // red-black tree representing multiset
+public:
+ typedef typename _Rep_type::const_pointer pointer;
+ typedef typename _Rep_type::const_pointer const_pointer;
+ typedef typename _Rep_type::const_reference reference;
+ typedef typename _Rep_type::const_reference const_reference;
+ typedef typename _Rep_type::const_iterator iterator;
+ typedef typename _Rep_type::const_iterator const_iterator;
+ typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
+ typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
+ typedef typename _Rep_type::size_type size_type;
+ typedef typename _Rep_type::difference_type difference_type;
+ typedef typename _Rep_type::allocator_type allocator_type;
+
+ // allocation/deallocation
+
+ multiset() : _M_t(_Compare(), allocator_type()) {}
+ explicit multiset(const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) {}
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+ template <class _InputIterator>
+ multiset(_InputIterator __first, _InputIterator __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_equal(__first, __last); }
+
+ template <class _InputIterator>
+ multiset(_InputIterator __first, _InputIterator __last,
+ const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
+
+#else
+
+ multiset(const value_type* __first, const value_type* __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_equal(__first, __last); }
+
+ multiset(const value_type* __first, const value_type* __last,
+ const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
+
+ multiset(const_iterator __first, const_iterator __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_equal(__first, __last); }
+
+ multiset(const_iterator __first, const_iterator __last,
+ const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ multiset(const multiset<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
+ multiset<_Key,_Compare,_Alloc>&
+ operator=(const multiset<_Key,_Compare,_Alloc>& __x) {
+ _M_t = __x._M_t;
+ return *this;
+ }
+
+ // accessors:
+
+ key_compare key_comp() const { return _M_t.key_comp(); }
+ value_compare value_comp() const { return _M_t.key_comp(); }
+ allocator_type get_allocator() const { return _M_t.get_allocator(); }
+
+ iterator begin() const { return _M_t.begin(); }
+ iterator end() const { return _M_t.end(); }
+ reverse_iterator rbegin() const { return _M_t.rbegin(); }
+ reverse_iterator rend() const { return _M_t.rend(); }
+ bool empty() const { return _M_t.empty(); }
+ size_type size() const { return _M_t.size(); }
+ size_type max_size() const { return _M_t.max_size(); }
+ void swap(multiset<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
+
+ // insert/erase
+ iterator insert(const value_type& __x) {
+ return _M_t.insert_equal(__x);
+ }
+ iterator insert(iterator __position, const value_type& __x) {
+ typedef typename _Rep_type::iterator _Rep_iterator;
+ return _M_t.insert_equal((_Rep_iterator&)__position, __x);
+ }
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ void insert(_InputIterator __first, _InputIterator __last) {
+ _M_t.insert_equal(__first, __last);
+ }
+#else
+ void insert(const value_type* __first, const value_type* __last) {
+ _M_t.insert_equal(__first, __last);
+ }
+ void insert(const_iterator __first, const_iterator __last) {
+ _M_t.insert_equal(__first, __last);
+ }
+#endif /* __STL_MEMBER_TEMPLATES */
+ void erase(iterator __position) {
+ typedef typename _Rep_type::iterator _Rep_iterator;
+ _M_t.erase((_Rep_iterator&)__position);
+ }
+ size_type erase(const key_type& __x) {
+ return _M_t.erase(__x);
+ }
+ void erase(iterator __first, iterator __last) {
+ typedef typename _Rep_type::iterator _Rep_iterator;
+ _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
+ }
+ void clear() { _M_t.clear(); }
+
+ // multiset operations:
+
+ iterator find(const key_type& __x) const { return _M_t.find(__x); }
+ size_type count(const key_type& __x) const { return _M_t.count(__x); }
+ iterator lower_bound(const key_type& __x) const {
+ return _M_t.lower_bound(__x);
+ }
+ iterator upper_bound(const key_type& __x) const {
+ return _M_t.upper_bound(__x);
+ }
+ pair<iterator,iterator> equal_range(const key_type& __x) const {
+ return _M_t.equal_range(__x);
+ }
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _K1, class _C1, class _A1>
+ friend bool operator== (const multiset<_K1,_C1,_A1>&,
+ const multiset<_K1,_C1,_A1>&);
+ template <class _K1, class _C1, class _A1>
+ friend bool operator< (const multiset<_K1,_C1,_A1>&,
+ const multiset<_K1,_C1,_A1>&);
+#else /* __STL_MEMBER_TEMPLATES */
+ friend bool __STD_QUALIFIER
+ operator== __STL_NULL_TMPL_ARGS (const multiset&, const multiset&);
+ friend bool __STD_QUALIFIER
+ operator< __STL_NULL_TMPL_ARGS (const multiset&, const multiset&);
+#endif /* __STL_MEMBER_TEMPLATES */
+};
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator==(const multiset<_Key,_Compare,_Alloc>& __x,
+ const multiset<_Key,_Compare,_Alloc>& __y) {
+ return __x._M_t == __y._M_t;
+}
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x,
+ const multiset<_Key,_Compare,_Alloc>& __y) {
+ return __x._M_t < __y._M_t;
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator!=(const multiset<_Key,_Compare,_Alloc>& __x,
+ const multiset<_Key,_Compare,_Alloc>& __y) {
+ return !(__x == __y);
+}
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator>(const multiset<_Key,_Compare,_Alloc>& __x,
+ const multiset<_Key,_Compare,_Alloc>& __y) {
+ return __y < __x;
+}
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator<=(const multiset<_Key,_Compare,_Alloc>& __x,
+ const multiset<_Key,_Compare,_Alloc>& __y) {
+ return !(__y < __x);
+}
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator>=(const multiset<_Key,_Compare,_Alloc>& __x,
+ const multiset<_Key,_Compare,_Alloc>& __y) {
+ return !(__x < __y);
+}
+
+template <class _Key, class _Compare, class _Alloc>
+inline void swap(multiset<_Key,_Compare,_Alloc>& __x,
+ multiset<_Key,_Compare,_Alloc>& __y) {
+ __x.swap(__y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1174
+#pragma reset woff 1375
+#endif
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_MULTISET_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_numeric.h b/libstdc++-v3/bits/stl_numeric.h
new file mode 100644
index 0000000..7070e2d
--- /dev/null
+++ b/libstdc++-v3/bits/stl_numeric.h
@@ -0,0 +1,239 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+
+#ifndef _CPP_BITS_STL_NUMERIC_H
+#define _CPP_BITS_STL_NUMERIC_H 1
+
+__STL_BEGIN_NAMESPACE
+
+template <class _InputIterator, class _Tp>
+_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
+{
+ for ( ; __first != __last; ++__first)
+ __init = __init + *__first;
+ return __init;
+}
+
+template <class _InputIterator, class _Tp, class _BinaryOperation>
+_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
+ _BinaryOperation __binary_op)
+{
+ for ( ; __first != __last; ++__first)
+ __init = __binary_op(__init, *__first);
+ return __init;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _Tp>
+_Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
+ _InputIterator2 __first2, _Tp __init)
+{
+ for ( ; __first1 != __last1; ++__first1, ++__first2)
+ __init = __init + (*__first1 * *__first2);
+ return __init;
+}
+
+template <class _InputIterator1, class _InputIterator2, class _Tp,
+ class _BinaryOperation1, class _BinaryOperation2>
+_Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
+ _InputIterator2 __first2, _Tp __init,
+ _BinaryOperation1 __binary_op1,
+ _BinaryOperation2 __binary_op2)
+{
+ for ( ; __first1 != __last1; ++__first1, ++__first2)
+ __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
+ return __init;
+}
+
+template <class _InputIterator, class _OutputIterator, class _Tp>
+_OutputIterator
+__partial_sum(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result, _Tp*)
+{
+ _Tp __value = *__first;
+ while (++__first != __last) {
+ __value = __value + *__first;
+ *++__result = __value;
+ }
+ return ++__result;
+}
+
+template <class _InputIterator, class _OutputIterator>
+_OutputIterator
+partial_sum(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result)
+{
+ if (__first == __last) return __result;
+ *__result = *__first;
+ return __partial_sum(__first, __last, __result, __VALUE_TYPE(__first));
+}
+
+template <class _InputIterator, class _OutputIterator, class _Tp,
+ class _BinaryOperation>
+_OutputIterator
+__partial_sum(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result, _Tp*, _BinaryOperation __binary_op)
+{
+ _Tp __value = *__first;
+ while (++__first != __last) {
+ __value = __binary_op(__value, *__first);
+ *++__result = __value;
+ }
+ return ++__result;
+}
+
+template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
+_OutputIterator
+partial_sum(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result, _BinaryOperation __binary_op)
+{
+ if (__first == __last) return __result;
+ *__result = *__first;
+ return __partial_sum(__first, __last, __result, __VALUE_TYPE(__first),
+ __binary_op);
+}
+
+template <class _InputIterator, class _OutputIterator, class _Tp>
+_OutputIterator
+__adjacent_difference(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result, _Tp*)
+{
+ _Tp __value = *__first;
+ while (++__first != __last) {
+ _Tp __tmp = *__first;
+ *++__result = __tmp - __value;
+ __value = __tmp;
+ }
+ return ++__result;
+}
+
+template <class _InputIterator, class _OutputIterator>
+_OutputIterator
+adjacent_difference(_InputIterator __first,
+ _InputIterator __last, _OutputIterator __result)
+{
+ if (__first == __last) return __result;
+ *__result = *__first;
+ return __adjacent_difference(__first, __last, __result,
+ __VALUE_TYPE(__first));
+}
+
+template <class _InputIterator, class _OutputIterator, class _Tp,
+ class _BinaryOperation>
+_OutputIterator
+__adjacent_difference(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result, _Tp*,
+ _BinaryOperation __binary_op) {
+ _Tp __value = *__first;
+ while (++__first != __last) {
+ _Tp __tmp = *__first;
+ *++__result = __binary_op(__tmp, __value);
+ __value = __tmp;
+ }
+ return ++__result;
+}
+
+template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
+_OutputIterator
+adjacent_difference(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result, _BinaryOperation __binary_op)
+{
+ if (__first == __last) return __result;
+ *__result = *__first;
+ return __adjacent_difference(__first, __last, __result,
+ __VALUE_TYPE(__first),
+ __binary_op);
+}
+
+// Returns __x ** __n, where __n >= 0. _Note that "multiplication"
+// is required to be associative, but not necessarily commutative.
+
+
+template <class _Tp, class _Integer, class _MonoidOperation>
+_Tp __power(_Tp __x, _Integer __n, _MonoidOperation __monoid_op)
+{
+ if (__n == 0)
+ return identity_element(__monoid_op);
+ else {
+ while ((__n & 1) == 0) {
+ __n >>= 1;
+ __x = __monoid_op(__x, __x);
+ }
+
+ _Tp __result = __x;
+ __n >>= 1;
+ while (__n != 0) {
+ __x = __monoid_op(__x, __x);
+ if ((__n & 1) != 0)
+ __result = __monoid_op(__result, __x);
+ __n >>= 1;
+ }
+ return __result;
+ }
+}
+
+template <class _Tp, class _Integer>
+inline _Tp __power(_Tp __x, _Integer __n)
+{
+ return __power(__x, __n, multiplies<_Tp>());
+}
+
+// Alias for the internal name __power. Note that power is an extension,
+// not part of the C++ standard.
+
+template <class _Tp, class _Integer, class _MonoidOperation>
+inline _Tp power(_Tp __x, _Integer __n, _MonoidOperation __monoid_op)
+{
+ return __power(__x, __n, __monoid_op);
+}
+
+template <class _Tp, class _Integer>
+inline _Tp power(_Tp __x, _Integer __n)
+{
+ return __power(__x, __n);
+}
+
+// iota is not part of the C++ standard. It is an extension.
+
+template <class _ForwardIterator, class _Tp>
+void
+iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
+{
+ while (__first != __last)
+ *__first++ = __value++;
+}
+
+__STL_END_NAMESPACE
+
+#endif /* _CPP_BITS_STL_NUMERIC_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_pair.h b/libstdc++-v3/bits/stl_pair.h
new file mode 100644
index 0000000..a6155a6
--- /dev/null
+++ b/libstdc++-v3/bits/stl_pair.h
@@ -0,0 +1,101 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_PAIR_H
+#define __SGI_STL_INTERNAL_PAIR_H
+
+__STL_BEGIN_NAMESPACE
+
+template <class _T1, class _T2>
+struct pair {
+ typedef _T1 first_type;
+ typedef _T2 second_type;
+
+ _T1 first;
+ _T2 second;
+ pair() : first(_T1()), second(_T2()) {}
+ pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _U1, class _U2>
+ pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
+#endif
+};
+
+template <class _T1, class _T2>
+inline bool operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
+{
+ return __x.first == __y.first && __x.second == __y.second;
+}
+
+template <class _T1, class _T2>
+inline bool operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
+{
+ return __x.first < __y.first ||
+ (!(__y.first < __x.first) && __x.second < __y.second);
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _T1, class _T2>
+inline bool operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
+ return !(__x == __y);
+}
+
+template <class _T1, class _T2>
+inline bool operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
+ return __y < __x;
+}
+
+template <class _T1, class _T2>
+inline bool operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
+ return !(__y < __x);
+}
+
+template <class _T1, class _T2>
+inline bool operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
+ return !(__x < __y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+template <class _T1, class _T2>
+inline pair<_T1, _T2> make_pair(const _T1& __x, const _T2& __y)
+{
+ return pair<_T1, _T2>(__x, __y);
+}
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_PAIR_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_pthread_alloc.h b/libstdc++-v3/bits/stl_pthread_alloc.h
new file mode 100644
index 0000000..c1488b1
--- /dev/null
+++ b/libstdc++-v3/bits/stl_pthread_alloc.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 1996-1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_BITS_STL_PTHREAD_ALLOC_H
+#define _CPP_BITS_STL_PTHREAD_ALLOC_H 1
+
+#include <bits/pthread_allocimpl.h>
+
+#ifdef __STL_USE_NAMESPACES
+
+using __STD::_Pthread_alloc_template;
+using __STD::pthread_alloc;
+
+#endif /* __STL_USE_NAMESPACES */
+
+
+#endif /* _CPP_BITS_STL_PTHREAD_ALLOC_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_queue.h b/libstdc++-v3/bits/stl_queue.h
new file mode 100644
index 0000000..610ba3e
--- /dev/null
+++ b/libstdc++-v3/bits/stl_queue.h
@@ -0,0 +1,221 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_QUEUE_H
+#define __SGI_STL_INTERNAL_QUEUE_H
+
+__STL_BEGIN_NAMESPACE
+
+// Forward declarations of operators < and ==, needed for friend declaration.
+
+template <class _Tp,
+ class _Sequence = deque<_Tp> >
+class queue;
+
+template <class _Tp, class _Seq>
+inline bool operator==(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&);
+
+template <class _Tp, class _Seq>
+inline bool operator<(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&);
+
+
+template <class _Tp, class _Sequence>
+class queue {
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _Tp1, class _Seq1>
+ friend bool operator== (const queue<_Tp1, _Seq1>&,
+ const queue<_Tp1, _Seq1>&);
+ template <class _Tp1, class _Seq1>
+ friend bool operator< (const queue<_Tp1, _Seq1>&,
+ const queue<_Tp1, _Seq1>&);
+#else /* __STL_MEMBER_TEMPLATES */
+ friend bool __STD_QUALIFIER
+ operator== __STL_NULL_TMPL_ARGS (const queue&, const queue&);
+ friend bool __STD_QUALIFIER
+ operator< __STL_NULL_TMPL_ARGS (const queue&, const queue&);
+#endif /* __STL_MEMBER_TEMPLATES */
+
+public:
+ typedef typename _Sequence::value_type value_type;
+ typedef typename _Sequence::size_type size_type;
+ typedef _Sequence container_type;
+
+ typedef typename _Sequence::reference reference;
+ typedef typename _Sequence::const_reference const_reference;
+protected:
+ _Sequence c;
+public:
+ queue() : c() {}
+ explicit queue(const _Sequence& __c) : c(__c) {}
+
+ bool empty() const { return c.empty(); }
+ size_type size() const { return c.size(); }
+ reference front() { return c.front(); }
+ const_reference front() const { return c.front(); }
+ reference back() { return c.back(); }
+ const_reference back() const { return c.back(); }
+ void push(const value_type& __x) { c.push_back(__x); }
+ void pop() { c.pop_front(); }
+};
+
+template <class _Tp, class _Sequence>
+bool
+operator==(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
+{
+ return __x.c == __y.c;
+}
+
+template <class _Tp, class _Sequence>
+bool
+operator<(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
+{
+ return __x.c < __y.c;
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Tp, class _Sequence>
+bool
+operator!=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
+{
+ return !(__x == __y);
+}
+
+template <class _Tp, class _Sequence>
+bool
+operator>(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
+{
+ return __y < __x;
+}
+
+template <class _Tp, class _Sequence>
+bool
+operator<=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
+{
+ return !(__y < __x);
+}
+
+template <class _Tp, class _Sequence>
+bool
+operator>=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
+{
+ return !(__x < __y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+template <class _Tp,
+ class _Sequence = vector<_Tp>,
+ class _Compare = less<typename _Sequence::value_type> >
+class priority_queue {
+public:
+ typedef typename _Sequence::value_type value_type;
+ typedef typename _Sequence::size_type size_type;
+ typedef _Sequence container_type;
+
+ typedef typename _Sequence::reference reference;
+ typedef typename _Sequence::const_reference const_reference;
+protected:
+ _Sequence c;
+ _Compare comp;
+public:
+ priority_queue() : c() {}
+ explicit priority_queue(const _Compare& __x) : c(), comp(__x) {}
+ priority_queue(const _Compare& __x, const _Sequence& __s)
+ : c(__s), comp(__x)
+ { make_heap(c.begin(), c.end(), comp); }
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ priority_queue(_InputIterator __first, _InputIterator __last)
+ : c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
+
+ template <class _InputIterator>
+ priority_queue(_InputIterator __first,
+ _InputIterator __last, const _Compare& __x)
+ : c(__first, __last), comp(__x)
+ { make_heap(c.begin(), c.end(), comp); }
+
+ template <class _InputIterator>
+ priority_queue(_InputIterator __first, _InputIterator __last,
+ const _Compare& __x, const _Sequence& __s)
+ : c(__s), comp(__x)
+ {
+ c.insert(c.end(), __first, __last);
+ make_heap(c.begin(), c.end(), comp);
+ }
+
+#else /* __STL_MEMBER_TEMPLATES */
+ priority_queue(const value_type* __first, const value_type* __last)
+ : c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
+
+ priority_queue(const value_type* __first, const value_type* __last,
+ const _Compare& __x)
+ : c(__first, __last), comp(__x)
+ { make_heap(c.begin(), c.end(), comp); }
+
+ priority_queue(const value_type* __first, const value_type* __last,
+ const _Compare& __x, const _Sequence& __c)
+ : c(__c), comp(__x)
+ {
+ c.insert(c.end(), __first, __last);
+ make_heap(c.begin(), c.end(), comp);
+ }
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ bool empty() const { return c.empty(); }
+ size_type size() const { return c.size(); }
+ const_reference top() const { return c.front(); }
+ void push(const value_type& __x) {
+ __STL_TRY {
+ c.push_back(__x);
+ push_heap(c.begin(), c.end(), comp);
+ }
+ __STL_UNWIND(c.clear());
+ }
+ void pop() {
+ __STL_TRY {
+ pop_heap(c.begin(), c.end(), comp);
+ c.pop_back();
+ }
+ __STL_UNWIND(c.clear());
+ }
+};
+
+// no equality is provided
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_QUEUE_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_range_errors.h b/libstdc++-v3/bits/stl_range_errors.h
new file mode 100644
index 0000000..c5ddfe6
--- /dev/null
+++ b/libstdc++-v3/bits/stl_range_errors.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 1999
+ * Silicon Graphics
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ */
+
+#ifndef __STL_RANGE_ERRORS_H
+#define __STL_RANGE_ERRORS_H
+
+// A few places in the STL throw range errors, using standard exception
+// classes defined in <stdexcept>. This header file provides functions
+// to throw those exception objects.
+
+// __STL_DONT_THROW_RANGE_ERRORS is a hook so that users can disable
+// this exception throwing.
+
+#include <bits/stl_config.h>
+
+#if defined(__STL_CAN_THROW_RANGE_ERRORS) && \
+ defined(__STL_USE_EXCEPTIONS) && \
+ !defined(__STL_DONT_THROW_RANGE_ERRORS)
+# define __STL_THROW_RANGE_ERRORS
+#endif
+
+// For the SGI 7.3 compiler, declare these functions here and define them
+// elsewhere.
+#if defined(__STL_THROW_RANGE_ERRORS) && \
+ defined(__sgi) && !defined(__GNUC__) && \
+ _COMPILER_VERSION >= 730 && defined(_STANDARD_C_PLUS_PLUS) \
+ || defined(__GNUC__) && defined(__STL_THROW_RANGE_ERRORS)
+
+__STL_BEGIN_NAMESPACE
+void __stl_throw_range_error(const char* __msg);
+void __stl_throw_length_error(const char* __msg);
+__STL_END_NAMESPACE
+
+// For other compilers where we're throwing range errors, include the
+// stdexcept header and throw the appropriate exceptions directly.
+#elif defined(__STL_THROW_RANGE_ERRORS)
+
+#include <bits/std_stdexcept.h>
+
+__STL_BEGIN_NAMESPACE
+inline void __stl_throw_range_error(const char* __msg)
+ { throw range_error(__msg); }
+inline void __stl_throw_length_error(const char* __msg)
+ { throw length_error(__msg); }
+__STL_END_NAMESPACE
+
+// Otherwise, define inline functions that do nothing.
+#else
+
+__STL_BEGIN_NAMESPACE
+inline void __stl_throw_range_error(const char*) {}
+inline void __stl_throw_length_error(const char*) {}
+__STL_END_NAMESPACE
+
+#endif
+
+#endif /* __STL_RANGE_ERRORS_H */
+
+// Local Variables:
+// mode:C++
+// End:
+
+
diff --git a/libstdc++-v3/bits/stl_raw_storage_iter.h b/libstdc++-v3/bits/stl_raw_storage_iter.h
new file mode 100644
index 0000000..007acd0
--- /dev/null
+++ b/libstdc++-v3/bits/stl_raw_storage_iter.h
@@ -0,0 +1,81 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef _CPP_BITS_STL_RAW_STORAGE_ITERATOR_H
+#define _CPP_BITS_STL_RAW_STORAGE_ITERATOR_H 1
+
+__STL_BEGIN_NAMESPACE
+
+template <class _ForwardIterator, class _Tp>
+class raw_storage_iterator {
+protected:
+ _ForwardIterator _M_iter;
+public:
+ typedef output_iterator_tag iterator_category;
+ typedef void value_type;
+ typedef void difference_type;
+ typedef void pointer;
+ typedef void reference;
+
+ explicit raw_storage_iterator(_ForwardIterator __x) : _M_iter(__x) {}
+ raw_storage_iterator& operator*() { return *this; }
+ raw_storage_iterator& operator=(const _Tp& __element) {
+ construct(&*_M_iter, __element);
+ return *this;
+ }
+ raw_storage_iterator<_ForwardIterator, _Tp>& operator++() {
+ ++_M_iter;
+ return *this;
+ }
+ raw_storage_iterator<_ForwardIterator, _Tp> operator++(int) {
+ raw_storage_iterator<_ForwardIterator, _Tp> __tmp = *this;
+ ++_M_iter;
+ return __tmp;
+ }
+};
+
+#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _ForwardIterator, class _Tp>
+inline output_iterator_tag
+iterator_category(const raw_storage_iterator<_ForwardIterator, _Tp>&)
+{
+ return output_iterator_tag();
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+__STL_END_NAMESPACE
+
+#endif /* _CPP_BITS_STL_RAW_STORAGE_ITERATOR_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_relops.h b/libstdc++-v3/bits/stl_relops.h
new file mode 100644
index 0000000..f0cabdf
--- /dev/null
+++ b/libstdc++-v3/bits/stl_relops.h
@@ -0,0 +1,62 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef _CPP_BITS_STL_RELOPS_H
+#define _CPP_BITS_STL_RELOPS_H 1
+
+__STL_BEGIN_RELOPS_NAMESPACE
+
+template <class _Tp>
+inline bool operator!=(const _Tp& __x, const _Tp& __y) {
+ return !(__x == __y);
+}
+
+template <class _Tp>
+inline bool operator>(const _Tp& __x, const _Tp& __y) {
+ return __y < __x;
+}
+
+template <class _Tp>
+inline bool operator<=(const _Tp& __x, const _Tp& __y) {
+ return !(__y < __x);
+}
+
+template <class _Tp>
+inline bool operator>=(const _Tp& __x, const _Tp& __y) {
+ return !(__x < __y);
+}
+
+__STL_END_RELOPS_NAMESPACE
+
+#endif /* _CPP_BITS_STL_RELOPS_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_set.h b/libstdc++-v3/bits/stl_set.h
new file mode 100644
index 0000000..b5d3643
--- /dev/null
+++ b/libstdc++-v3/bits/stl_set.h
@@ -0,0 +1,259 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_SET_H
+#define __SGI_STL_INTERNAL_SET_H
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1174
+#pragma set woff 1375
+#endif
+
+// Forward declarations of operators < and ==, needed for friend declaration.
+
+template <class _Key, class _Compare = less<_Key>,
+ class _Alloc = allocator<_Key> >
+class set;
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator==(const set<_Key,_Compare,_Alloc>& __x,
+ const set<_Key,_Compare,_Alloc>& __y);
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator<(const set<_Key,_Compare,_Alloc>& __x,
+ const set<_Key,_Compare,_Alloc>& __y);
+
+
+template <class _Key, class _Compare, class _Alloc>
+class set {
+public:
+ // typedefs:
+
+ typedef _Key key_type;
+ typedef _Key value_type;
+ typedef _Compare key_compare;
+ typedef _Compare value_compare;
+private:
+ typedef _Rb_tree<key_type, value_type,
+ _Identity<value_type>, key_compare, _Alloc> _Rep_type;
+ _Rep_type _M_t; // red-black tree representing set
+public:
+ typedef typename _Rep_type::const_pointer pointer;
+ typedef typename _Rep_type::const_pointer const_pointer;
+ typedef typename _Rep_type::const_reference reference;
+ typedef typename _Rep_type::const_reference const_reference;
+ typedef typename _Rep_type::const_iterator iterator;
+ typedef typename _Rep_type::const_iterator const_iterator;
+ typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
+ typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
+ typedef typename _Rep_type::size_type size_type;
+ typedef typename _Rep_type::difference_type difference_type;
+ typedef typename _Rep_type::allocator_type allocator_type;
+
+ // allocation/deallocation
+
+ set() : _M_t(_Compare(), allocator_type()) {}
+ explicit set(const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) {}
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ set(_InputIterator __first, _InputIterator __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_unique(__first, __last); }
+
+ template <class _InputIterator>
+ set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
+#else
+ set(const value_type* __first, const value_type* __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_unique(__first, __last); }
+
+ set(const value_type* __first,
+ const value_type* __last, const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
+
+ set(const_iterator __first, const_iterator __last)
+ : _M_t(_Compare(), allocator_type())
+ { _M_t.insert_unique(__first, __last); }
+
+ set(const_iterator __first, const_iterator __last, const _Compare& __comp,
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
+ set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
+ {
+ _M_t = __x._M_t;
+ return *this;
+ }
+
+ // accessors:
+
+ key_compare key_comp() const { return _M_t.key_comp(); }
+ value_compare value_comp() const { return _M_t.key_comp(); }
+ allocator_type get_allocator() const { return _M_t.get_allocator(); }
+
+ iterator begin() const { return _M_t.begin(); }
+ iterator end() const { return _M_t.end(); }
+ reverse_iterator rbegin() const { return _M_t.rbegin(); }
+ reverse_iterator rend() const { return _M_t.rend(); }
+ bool empty() const { return _M_t.empty(); }
+ size_type size() const { return _M_t.size(); }
+ size_type max_size() const { return _M_t.max_size(); }
+ void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
+
+ // insert/erase
+ pair<iterator,bool> insert(const value_type& __x) {
+ pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x);
+ return pair<iterator, bool>(__p.first, __p.second);
+ }
+ iterator insert(iterator __position, const value_type& __x) {
+ typedef typename _Rep_type::iterator _Rep_iterator;
+ return _M_t.insert_unique((_Rep_iterator&)__position, __x);
+ }
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ void insert(_InputIterator __first, _InputIterator __last) {
+ _M_t.insert_unique(__first, __last);
+ }
+#else
+ void insert(const_iterator __first, const_iterator __last) {
+ _M_t.insert_unique(__first, __last);
+ }
+ void insert(const value_type* __first, const value_type* __last) {
+ _M_t.insert_unique(__first, __last);
+ }
+#endif /* __STL_MEMBER_TEMPLATES */
+ void erase(iterator __position) {
+ typedef typename _Rep_type::iterator _Rep_iterator;
+ _M_t.erase((_Rep_iterator&)__position);
+ }
+ size_type erase(const key_type& __x) {
+ return _M_t.erase(__x);
+ }
+ void erase(iterator __first, iterator __last) {
+ typedef typename _Rep_type::iterator _Rep_iterator;
+ _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
+ }
+ void clear() { _M_t.clear(); }
+
+ // set operations:
+
+ iterator find(const key_type& __x) const { return _M_t.find(__x); }
+ size_type count(const key_type& __x) const { return _M_t.count(__x); }
+ iterator lower_bound(const key_type& __x) const {
+ return _M_t.lower_bound(__x);
+ }
+ iterator upper_bound(const key_type& __x) const {
+ return _M_t.upper_bound(__x);
+ }
+ pair<iterator,iterator> equal_range(const key_type& __x) const {
+ return _M_t.equal_range(__x);
+ }
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _K1, class _C1, class _A1>
+ friend bool operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
+ template <class _K1, class _C1, class _A1>
+ friend bool operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
+#else /* __STL_MEMBER_TEMPLATES */
+ friend bool __STD_QUALIFIER
+ operator== __STL_NULL_TMPL_ARGS (const set&, const set&);
+ friend bool __STD_QUALIFIER
+ operator< __STL_NULL_TMPL_ARGS (const set&, const set&);
+#endif /* __STL_MEMBER_TEMPLATES */
+};
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator==(const set<_Key,_Compare,_Alloc>& __x,
+ const set<_Key,_Compare,_Alloc>& __y) {
+ return __x._M_t == __y._M_t;
+}
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator<(const set<_Key,_Compare,_Alloc>& __x,
+ const set<_Key,_Compare,_Alloc>& __y) {
+ return __x._M_t < __y._M_t;
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator!=(const set<_Key,_Compare,_Alloc>& __x,
+ const set<_Key,_Compare,_Alloc>& __y) {
+ return !(__x == __y);
+}
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator>(const set<_Key,_Compare,_Alloc>& __x,
+ const set<_Key,_Compare,_Alloc>& __y) {
+ return __y < __x;
+}
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator<=(const set<_Key,_Compare,_Alloc>& __x,
+ const set<_Key,_Compare,_Alloc>& __y) {
+ return !(__y < __x);
+}
+
+template <class _Key, class _Compare, class _Alloc>
+inline bool operator>=(const set<_Key,_Compare,_Alloc>& __x,
+ const set<_Key,_Compare,_Alloc>& __y) {
+ return !(__x < __y);
+}
+
+template <class _Key, class _Compare, class _Alloc>
+inline void swap(set<_Key,_Compare,_Alloc>& __x,
+ set<_Key,_Compare,_Alloc>& __y) {
+ __x.swap(__y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1174
+#pragma reset woff 1375
+#endif
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_SET_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_stack.h b/libstdc++-v3/bits/stl_stack.h
new file mode 100644
index 0000000..bb9d851
--- /dev/null
+++ b/libstdc++-v3/bits/stl_stack.h
@@ -0,0 +1,133 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_STACK_H
+#define __SGI_STL_INTERNAL_STACK_H
+
+__STL_BEGIN_NAMESPACE
+
+// Forward declarations of operators == and <, needed for friend declaration.
+
+template <class _Tp,
+ class _Sequence = deque<_Tp> >
+class stack;
+
+template <class _Tp, class _Seq>
+bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
+
+template <class _Tp, class _Seq>
+bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
+
+
+template <class _Tp, class _Sequence>
+class stack {
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _Tp1, class _Seq1>
+ friend bool operator== (const stack<_Tp1, _Seq1>&,
+ const stack<_Tp1, _Seq1>&);
+ template <class _Tp1, class _Seq1>
+ friend bool operator< (const stack<_Tp1, _Seq1>&,
+ const stack<_Tp1, _Seq1>&);
+#else /* __STL_MEMBER_TEMPLATES */
+ friend bool __STD_QUALIFIER
+ operator== __STL_NULL_TMPL_ARGS (const stack&, const stack&);
+ friend bool __STD_QUALIFIER
+ operator< __STL_NULL_TMPL_ARGS (const stack&, const stack&);
+#endif /* __STL_MEMBER_TEMPLATES */
+
+public:
+ typedef typename _Sequence::value_type value_type;
+ typedef typename _Sequence::size_type size_type;
+ typedef _Sequence container_type;
+
+ typedef typename _Sequence::reference reference;
+ typedef typename _Sequence::const_reference const_reference;
+protected:
+ _Sequence c;
+public:
+ stack() : c() {}
+ explicit stack(const _Sequence& __s) : c(__s) {}
+
+ bool empty() const { return c.empty(); }
+ size_type size() const { return c.size(); }
+ reference top() { return c.back(); }
+ const_reference top() const { return c.back(); }
+ void push(const value_type& __x) { c.push_back(__x); }
+ void pop() { c.pop_back(); }
+};
+
+template <class _Tp, class _Seq>
+bool operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
+{
+ return __x.c == __y.c;
+}
+
+template <class _Tp, class _Seq>
+bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
+{
+ return __x.c < __y.c;
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Tp, class _Seq>
+bool operator!=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
+{
+ return !(__x == __y);
+}
+
+template <class _Tp, class _Seq>
+bool operator>(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
+{
+ return __y < __x;
+}
+
+template <class _Tp, class _Seq>
+bool operator<=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
+{
+ return !(__y < __x);
+}
+
+template <class _Tp, class _Seq>
+bool operator>=(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y)
+{
+ return !(__x < __y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_STACK_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_string_fwd.h b/libstdc++-v3/bits/stl_string_fwd.h
new file mode 100644
index 0000000..5097e61
--- /dev/null
+++ b/libstdc++-v3/bits/stl_string_fwd.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef __SGI_STL_STRING_FWD_H
+#define __SGI_STL_STRING_FWD_H
+
+#include <bits/stl_config.h>
+//#include <bits/std_cstddef.h>
+#include <bits/stl_alloc.h>
+
+__STL_BEGIN_NAMESPACE
+
+template <class _CharT> struct char_traits;
+template <class _CharT,
+ class _Traits = char_traits<_CharT>,
+ class _Alloc = allocator<_CharT> >
+class basic_string;
+
+typedef basic_string<char> string;
+#ifdef _GLIBCPP_USE_WCHAR_T
+typedef basic_string<wchar_t> wstring;
+#endif
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_STRING_FWD_H */
+
+// Local Variables:
+// mode:C++
+// End:
+
+
+
+
+
+
+
diff --git a/libstdc++-v3/bits/stl_tempbuf.h b/libstdc++-v3/bits/stl_tempbuf.h
new file mode 100644
index 0000000..cdc0dd2
--- /dev/null
+++ b/libstdc++-v3/bits/stl_tempbuf.h
@@ -0,0 +1,161 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_TEMPBUF_H
+#define __SGI_STL_INTERNAL_TEMPBUF_H
+
+__STL_BEGIN_NAMESPACE
+
+template <class _Tp>
+pair<_Tp*, ptrdiff_t>
+__get_temporary_buffer(ptrdiff_t __len, _Tp*)
+{
+ if (__len > ptrdiff_t(INT_MAX / sizeof(_Tp)))
+ __len = INT_MAX / sizeof(_Tp);
+
+ while (__len > 0) {
+ _Tp* __tmp = (_Tp*) malloc((size_t)__len * sizeof(_Tp));
+ if (__tmp != 0)
+ return pair<_Tp*, ptrdiff_t>(__tmp, __len);
+ __len /= 2;
+ }
+
+ return pair<_Tp*, ptrdiff_t>((_Tp*)0, 0);
+}
+
+#ifdef __STL_EXPLICIT_FUNCTION_TMPL_ARGS
+
+template <class _Tp>
+inline pair<_Tp*, ptrdiff_t> get_temporary_buffer(ptrdiff_t __len) {
+ return __get_temporary_buffer(__len, (_Tp*) 0);
+}
+
+#endif /* __STL_EXPLICIT_FUNCTION_TMPL_ARGS */
+
+// This overload is not required by the standard; it is an extension.
+// It is supported for backward compatibility with the HP STL, and
+// because not all compilers support the language feature (explicit
+// function template arguments) that is required for the standard
+// version of get_temporary_buffer.
+template <class _Tp>
+inline pair<_Tp*, ptrdiff_t> get_temporary_buffer(ptrdiff_t __len, _Tp*) {
+ return __get_temporary_buffer(__len, (_Tp*) 0);
+}
+
+template <class _Tp>
+void return_temporary_buffer(_Tp* __p) {
+ free(__p);
+}
+
+template <class _ForwardIterator, class _Tp>
+class _Temporary_buffer {
+private:
+ ptrdiff_t _M_original_len;
+ ptrdiff_t _M_len;
+ _Tp* _M_buffer;
+
+ void _M_allocate_buffer() {
+ _M_original_len = _M_len;
+ _M_buffer = 0;
+
+ if (_M_len > (ptrdiff_t)(INT_MAX / sizeof(_Tp)))
+ _M_len = INT_MAX / sizeof(_Tp);
+
+ while (_M_len > 0) {
+ _M_buffer = (_Tp*) malloc(_M_len * sizeof(_Tp));
+ if (_M_buffer)
+ break;
+ _M_len /= 2;
+ }
+ }
+
+ void _M_initialize_buffer(const _Tp&, __true_type) {}
+ void _M_initialize_buffer(const _Tp& val, __false_type) {
+ uninitialized_fill_n(_M_buffer, _M_len, val);
+ }
+
+public:
+ ptrdiff_t size() const { return _M_len; }
+ ptrdiff_t requested_size() const { return _M_original_len; }
+ _Tp* begin() { return _M_buffer; }
+ _Tp* end() { return _M_buffer + _M_len; }
+
+ _Temporary_buffer(_ForwardIterator __first, _ForwardIterator __last) {
+ // Workaround for a __type_traits bug in the pre-7.3 compiler.
+# if defined(__sgi) && !defined(__GNUC__) && _COMPILER_VERSION < 730
+ typedef typename __type_traits<_Tp>::is_POD_type _Trivial;
+# else
+ typedef typename __type_traits<_Tp>::has_trivial_default_constructor
+ _Trivial;
+# endif
+
+ __STL_TRY {
+ _M_len = 0;
+ distance(__first, __last, _M_len);
+ _M_allocate_buffer();
+ if (_M_len > 0)
+ _M_initialize_buffer(*__first, _Trivial());
+ }
+ __STL_UNWIND(free(_M_buffer); _M_buffer = 0; _M_len = 0);
+ }
+
+ ~_Temporary_buffer() {
+ destroy(_M_buffer, _M_buffer + _M_len);
+ free(_M_buffer);
+ }
+
+private:
+ // Disable copy constructor and assignment operator.
+ _Temporary_buffer(const _Temporary_buffer&) {}
+ void operator=(const _Temporary_buffer&) {}
+};
+
+// Class temporary_buffer is not part of the standard. It is an extension.
+
+template <class _ForwardIterator,
+ class _Tp
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+ = typename iterator_traits<_ForwardIterator>::value_type
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+ >
+struct temporary_buffer : public _Temporary_buffer<_ForwardIterator, _Tp>
+{
+ temporary_buffer(_ForwardIterator __first, _ForwardIterator __last)
+ : _Temporary_buffer<_ForwardIterator, _Tp>(__first, __last) {}
+ ~temporary_buffer() {}
+};
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_TEMPBUF_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_threads.h b/libstdc++-v3/bits/stl_threads.h
new file mode 100644
index 0000000..8b6d08e
--- /dev/null
+++ b/libstdc++-v3/bits/stl_threads.h
@@ -0,0 +1,369 @@
+/*
+ * Copyright (c) 1997-1999
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+// WARNING: This is an internal header file, included by other C++
+// standard library headers. You should not attempt to use this header
+// file directly.
+// Stl_config.h should be included before this file.
+
+#ifndef __SGI_STL_INTERNAL_THREADS_H
+#define __SGI_STL_INTERNAL_THREADS_H
+
+// Supported threading models are native SGI, pthreads, uithreads
+// (similar to pthreads, but based on an earlier draft of the Posix
+// threads standard), and Win32 threads. Uithread support by Jochen
+// Schlick, 1999.
+
+#if defined(__STL_SGI_THREADS)
+#include <mutex.h>
+#include <time.h>
+#elif defined(__STL_PTHREADS)
+#include <pthread.h>
+#elif defined(__STL_UITHREADS)
+#include <thread.h>
+#include <synch.h>
+#elif defined(__STL_WIN32THREADS)
+#include <windows.h>
+#endif
+
+__STL_BEGIN_NAMESPACE
+
+
+// Class _Refcount_Base provides a type, _RC_t, a data member,
+// _M_ref_count, and member functions _M_incr and _M_decr, which perform
+// atomic preincrement/predecrement. The constructor initializes
+// _M_ref_count.
+
+// Hack for SGI o32 compilers.
+#if defined(__STL_SGI_THREADS) && !defined(__add_and_fetch) && \
+ (__mips < 3 || !(defined (_ABIN32) || defined(_ABI64)))
+# define __add_and_fetch(__l,__v) add_then_test((unsigned long*)__l,__v)
+# define __test_and_set(__l,__v) test_and_set(__l,__v)
+#endif /* o32 */
+
+struct _Refcount_Base
+{
+ // The type _RC_t
+# ifdef __STL_WIN32THREADS
+ typedef long _RC_t;
+# else
+ typedef size_t _RC_t;
+#endif
+
+ // The data member _M_ref_count
+ volatile _RC_t _M_ref_count;
+
+ // Constructor
+# ifdef __STL_PTHREADS
+ pthread_mutex_t _M_ref_count_lock;
+ _Refcount_Base(_RC_t __n) : _M_ref_count(__n)
+ { pthread_mutex_init(&_M_ref_count_lock, 0); }
+# elif defined(__STL_UITHREADS)
+ mutex_t _M_ref_count_lock;
+ _Refcount_Base(_RC_t __n) : _M_ref_count(__n)
+ { mutex_init(&_M_ref_count_lock, USYNC_THREAD, 0); }
+# else
+ _Refcount_Base(_RC_t __n) : _M_ref_count(__n) {}
+# endif
+
+ // _M_incr and _M_decr
+# ifdef __STL_SGI_THREADS
+ void _M_incr() { __add_and_fetch(&_M_ref_count, 1); }
+ _RC_t _M_decr() { return __add_and_fetch(&_M_ref_count, (size_t) -1); }
+# elif defined (__STL_WIN32THREADS)
+ void _M_incr() { InterlockedIncrement((_RC_t*)&_M_ref_count); }
+ _RC_t _M_decr() { return InterlockedDecrement((_RC_t*)&_M_ref_count); }
+# elif defined(__STL_PTHREADS)
+ void _M_incr() {
+ pthread_mutex_lock(&_M_ref_count_lock);
+ ++_M_ref_count;
+ pthread_mutex_unlock(&_M_ref_count_lock);
+ }
+ _RC_t _M_decr() {
+ pthread_mutex_lock(&_M_ref_count_lock);
+ volatile _RC_t __tmp = --_M_ref_count;
+ pthread_mutex_unlock(&_M_ref_count_lock);
+ return __tmp;
+ }
+# elif defined(__STL_UITHREADS)
+ void _M_incr() {
+ mutex_lock(&_M_ref_count_lock);
+ ++_M_ref_count;
+ mutex_unlock(&_M_ref_count_lock);
+ }
+ _RC_t _M_decr() {
+ mutex_lock(&_M_ref_count_lock);
+ /*volatile*/ _RC_t __tmp = --_M_ref_count;
+ mutex_unlock(&_M_ref_count_lock);
+ return __tmp;
+ }
+# else /* No threads */
+ void _M_incr() { ++_M_ref_count; }
+ _RC_t _M_decr() { return --_M_ref_count; }
+# endif
+};
+
+// Atomic swap on unsigned long
+// This is guaranteed to behave as though it were atomic only if all
+// possibly concurrent updates use _Atomic_swap.
+// In some cases the operation is emulated with a lock.
+# ifdef __STL_SGI_THREADS
+ inline unsigned long _Atomic_swap(unsigned long * __p, unsigned long __q) {
+# if __mips < 3 || !(defined (_ABIN32) || defined(_ABI64))
+ return test_and_set(__p, __q);
+# else
+ return __test_and_set(__p, (unsigned long)__q);
+# endif
+ }
+# elif defined(__STL_WIN32THREADS)
+ inline unsigned long _Atomic_swap(unsigned long * __p, unsigned long __q) {
+ return (unsigned long) InterlockedExchange((LPLONG)__p, (LONG)__q);
+ }
+# elif defined(__STL_PTHREADS)
+ // We use a template here only to get a unique initialized instance.
+ template<int __dummy>
+ struct _Swap_lock_struct {
+ static pthread_mutex_t _S_swap_lock;
+ };
+
+ template<int __dummy>
+ pthread_mutex_t
+ _Swap_lock_struct<__dummy>::_S_swap_lock = PTHREAD_MUTEX_INITIALIZER;
+
+ // This should be portable, but performance is expected
+ // to be quite awful. This really needs platform specific
+ // code.
+ inline unsigned long _Atomic_swap(unsigned long * __p, unsigned long __q) {
+ pthread_mutex_lock(&_Swap_lock_struct<0>::_S_swap_lock);
+ unsigned long __result = *__p;
+ *__p = __q;
+ pthread_mutex_unlock(&_Swap_lock_struct<0>::_S_swap_lock);
+ return __result;
+ }
+# elif defined(__STL_UITHREADS)
+ // We use a template here only to get a unique initialized instance.
+ template<int __dummy>
+ struct _Swap_lock_struct {
+ static mutex_t _S_swap_lock;
+ };
+
+ template<int __dummy>
+ mutex_t
+ _Swap_lock_struct<__dummy>::_S_swap_lock = DEFAULTMUTEX;
+
+ // This should be portable, but performance is expected
+ // to be quite awful. This really needs platform specific
+ // code.
+ inline unsigned long _Atomic_swap(unsigned long * __p, unsigned long __q) {
+ mutex_lock(&_Swap_lock_struct<0>::_S_swap_lock);
+ unsigned long __result = *__p;
+ *__p = __q;
+ mutex_unlock(&_Swap_lock_struct<0>::_S_swap_lock);
+ return __result;
+ }
+# elif defined (__STL_SOLARIS_THREADS)
+ // any better solutions ?
+ // We use a template here only to get a unique initialized instance.
+ template<int __dummy>
+ struct _Swap_lock_struct {
+ static mutex_t _S_swap_lock;
+ };
+
+# if ( __STL_STATIC_TEMPLATE_DATA > 0 )
+ template<int __dummy>
+ mutex_t
+ _Swap_lock_struct<__dummy>::_S_swap_lock = DEFAULTMUTEX;
+# else
+ __DECLARE_INSTANCE(mutex_t, _Swap_lock_struct<__dummy>::_S_swap_lock,
+ =DEFAULTMUTEX);
+# endif /* ( __STL_STATIC_TEMPLATE_DATA > 0 ) */
+
+ // This should be portable, but performance is expected
+ // to be quite awful. This really needs platform specific
+ // code.
+ inline unsigned long _Atomic_swap(unsigned long * __p, unsigned long __q) {
+ mutex_lock(&_Swap_lock_struct<0>::_S_swap_lock);
+ unsigned long __result = *__p;
+ *__p = __q;
+ mutex_unlock(&_Swap_lock_struct<0>::_S_swap_lock);
+ return __result;
+ }
+# else
+ static inline unsigned long _Atomic_swap(unsigned long * __p, unsigned long __q) {
+ unsigned long __result = *__p;
+ *__p = __q;
+ return __result;
+ }
+# endif
+
+// Locking class. Note that this class *does not have a constructor*.
+// It must be initialized either statically, with __STL_MUTEX_INITIALIZER,
+// or dynamically, by explicitly calling the _M_initialize member function.
+// (This is similar to the ways that a pthreads mutex can be initialized.)
+// There are explicit member functions for acquiring and releasing the lock.
+
+// There is no constructor because static initialization is essential for
+// some uses, and only a class aggregate (see section 8.5.1 of the C++
+// standard) can be initialized that way. That means we must have no
+// constructors, no base classes, no virtual functions, and no private or
+// protected members.
+
+struct _STL_mutex_lock
+{
+#if defined(__STL_SGI_THREADS) || defined(__STL_WIN32THREADS)
+ // It should be relatively easy to get this to work on any modern Unix.
+ volatile unsigned long _M_lock;
+ void _M_initialize() { _M_lock = 0; }
+ static void _S_nsec_sleep(int __log_nsec) {
+# ifdef __STL_SGI_THREADS
+ struct timespec __ts;
+ /* Max sleep is 2**27nsec ~ 60msec */
+ __ts.tv_sec = 0;
+ __ts.tv_nsec = 1 << __log_nsec;
+ nanosleep(&__ts, 0);
+# elif defined(__STL_WIN32THREADS)
+ if (__log_nsec <= 20) {
+ Sleep(0);
+ } else {
+ Sleep(1 << (__log_nsec - 20));
+ }
+# else
+# error unimplemented
+# endif
+ }
+ void _M_acquire_lock() {
+ const unsigned __low_spin_max = 30; // spins if we suspect uniprocessor
+ const unsigned __high_spin_max = 1000; // spins for multiprocessor
+ static unsigned __spin_max = __low_spin_max;
+ unsigned __my_spin_max;
+ static unsigned __last_spins = 0;
+ unsigned __my_last_spins;
+ volatile unsigned __junk;
+ int __i;
+ volatile unsigned long* __lock = &this->_M_lock;
+
+ if (!_Atomic_swap((unsigned long*)__lock, 1)) {
+ return;
+ }
+ __my_spin_max = __spin_max;
+ __my_last_spins = __last_spins;
+ __junk = 17; // Value doesn't matter.
+ for (__i = 0; __i < __my_spin_max; __i++) {
+ if (__i < __my_last_spins/2 || *__lock) {
+ __junk *= __junk; __junk *= __junk;
+ __junk *= __junk; __junk *= __junk;
+ continue;
+ }
+ if (!_Atomic_swap((unsigned long*)__lock, 1)) {
+ // got it!
+ // Spinning worked. Thus we're probably not being scheduled
+ // against the other process with which we were contending.
+ // Thus it makes sense to spin longer the next time.
+ __last_spins = __i;
+ __spin_max = __high_spin_max;
+ return;
+ }
+ }
+ // We are probably being scheduled against the other process. Sleep.
+ __spin_max = __low_spin_max;
+ for (__i = 0 ;; ++__i) {
+ int __log_nsec = __i + 6;
+
+ if (__log_nsec > 27) __log_nsec = 27;
+ if (!_Atomic_swap((unsigned long *)__lock, 1)) {
+ return;
+ }
+ _S_nsec_sleep(__log_nsec);
+ }
+ }
+ void _M_release_lock() {
+ volatile unsigned long* __lock = &_M_lock;
+# if defined(__STL_SGI_THREADS) && defined(__GNUC__) && __mips >= 3
+ asm("sync");
+ *__lock = 0;
+# elif defined(__STL_SGI_THREADS) && __mips >= 3 \
+ && (defined (_ABIN32) || defined(_ABI64))
+ __lock_release(__lock);
+# else
+ *__lock = 0;
+ // This is not sufficient on many multiprocessors, since
+ // writes to protected variables and the lock may be reordered.
+# endif
+ }
+
+// We no longer use win32 critical sections.
+// They appear to be slower in the contention-free case,
+// and they appear difficult to initialize without introducing a race.
+
+#elif defined(__STL_PTHREADS)
+ pthread_mutex_t _M_lock;
+ void _M_initialize() { pthread_mutex_init(&_M_lock, NULL); }
+ void _M_acquire_lock() { pthread_mutex_lock(&_M_lock); }
+ void _M_release_lock() { pthread_mutex_unlock(&_M_lock); }
+#elif defined(__STL_UITHREADS)
+ mutex_t _M_lock;
+ void _M_initialize() { mutex_init(&_M_lock, USYNC_THREAD, 0); }
+ void _M_acquire_lock() { mutex_lock(&_M_lock); }
+ void _M_release_lock() { mutex_unlock(&_M_lock); }
+#else /* No threads */
+ void _M_initialize() {}
+ void _M_acquire_lock() {}
+ void _M_release_lock() {}
+#endif
+};
+
+#ifdef __STL_PTHREADS
+// Pthreads locks must be statically initialized to something other than
+// the default value of zero.
+# define __STL_MUTEX_INITIALIZER = { PTHREAD_MUTEX_INITIALIZER }
+#elif defined(__STL_UITHREADS)
+// UIthreads locks must be statically initialized to something other than
+// the default value of zero.
+# define __STL_MUTEX_INITIALIZER = { DEFAULTMUTEX }
+#elif defined(__STL_SGI_THREADS) || defined(__STL_WIN32THREADS)
+# define __STL_MUTEX_INITIALIZER = { 0 }
+#else
+# define __STL_MUTEX_INITIALIZER
+#endif
+
+
+// A locking class that uses _STL_mutex_lock. The constructor takes a
+// reference to an _STL_mutex_lock, and acquires a lock. The
+// destructor releases the lock. It's not clear that this is exactly
+// the right functionality. It will probably change in the future.
+
+struct _STL_auto_lock
+{
+ _STL_mutex_lock& _M_lock;
+
+ _STL_auto_lock(_STL_mutex_lock& __lock) : _M_lock(__lock)
+ { _M_lock._M_acquire_lock(); }
+ ~_STL_auto_lock() { _M_lock._M_release_lock(); }
+
+private:
+ void operator=(const _STL_auto_lock&);
+ _STL_auto_lock(const _STL_auto_lock&);
+};
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_THREADS_H */
+
+// Local Variables:
+// mode:C++
+// End:
+
+
+
+
+
diff --git a/libstdc++-v3/bits/stl_tree.h b/libstdc++-v3/bits/stl_tree.h
new file mode 100644
index 0000000..dd1fa40
--- /dev/null
+++ b/libstdc++-v3/bits/stl_tree.h
@@ -0,0 +1,1368 @@
+/*
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_TREE_H
+#define __SGI_STL_INTERNAL_TREE_H
+
+/*
+
+Red-black tree class, designed for use in implementing STL
+associative containers (set, multiset, map, and multimap). The
+insertion and deletion algorithms are based on those in Cormen,
+Leiserson, and Rivest, Introduction to Algorithms (MIT Press, 1990),
+except that
+
+(1) the header cell is maintained with links not only to the root
+but also to the leftmost node of the tree, to enable constant time
+begin(), and to the rightmost node of the tree, to enable linear time
+performance when used with the generic set algorithms (set_union,
+etc.);
+
+(2) when a node being deleted has two children its successor node is
+relinked into its place, rather than copied, so that the only
+iterators invalidated are those referring to the deleted node.
+
+*/
+
+#include <bits/stl_algobase.h>
+#include <bits/stl_alloc.h>
+#include <bits/stl_construct.h>
+#include <bits/stl_function.h>
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1375
+#endif
+
+typedef bool _Rb_tree_Color_type;
+const _Rb_tree_Color_type _S_rb_tree_red = false;
+const _Rb_tree_Color_type _S_rb_tree_black = true;
+
+struct _Rb_tree_node_base
+{
+ typedef _Rb_tree_Color_type _Color_type;
+ typedef _Rb_tree_node_base* _Base_ptr;
+
+ _Color_type _M_color;
+ _Base_ptr _M_parent;
+ _Base_ptr _M_left;
+ _Base_ptr _M_right;
+
+ static _Base_ptr _S_minimum(_Base_ptr __x)
+ {
+ while (__x->_M_left != 0) __x = __x->_M_left;
+ return __x;
+ }
+
+ static _Base_ptr _S_maximum(_Base_ptr __x)
+ {
+ while (__x->_M_right != 0) __x = __x->_M_right;
+ return __x;
+ }
+};
+
+template <class _Value>
+struct _Rb_tree_node : public _Rb_tree_node_base
+{
+ typedef _Rb_tree_node<_Value>* _Link_type;
+ _Value _M_value_field;
+};
+
+
+struct _Rb_tree_base_iterator
+{
+ typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
+ typedef bidirectional_iterator_tag iterator_category;
+ typedef ptrdiff_t difference_type;
+ _Base_ptr _M_node;
+
+ void _M_increment()
+ {
+ if (_M_node->_M_right != 0) {
+ _M_node = _M_node->_M_right;
+ while (_M_node->_M_left != 0)
+ _M_node = _M_node->_M_left;
+ }
+ else {
+ _Base_ptr __y = _M_node->_M_parent;
+ while (_M_node == __y->_M_right) {
+ _M_node = __y;
+ __y = __y->_M_parent;
+ }
+ if (_M_node->_M_right != __y)
+ _M_node = __y;
+ }
+ }
+
+ void _M_decrement()
+ {
+ if (_M_node->_M_color == _S_rb_tree_red &&
+ _M_node->_M_parent->_M_parent == _M_node)
+ _M_node = _M_node->_M_right;
+ else if (_M_node->_M_left != 0) {
+ _Base_ptr __y = _M_node->_M_left;
+ while (__y->_M_right != 0)
+ __y = __y->_M_right;
+ _M_node = __y;
+ }
+ else {
+ _Base_ptr __y = _M_node->_M_parent;
+ while (_M_node == __y->_M_left) {
+ _M_node = __y;
+ __y = __y->_M_parent;
+ }
+ _M_node = __y;
+ }
+ }
+};
+
+template <class _Value, class _Ref, class _Ptr>
+struct _Rb_tree_iterator : public _Rb_tree_base_iterator
+{
+ typedef _Value value_type;
+ typedef _Ref reference;
+ typedef _Ptr pointer;
+ typedef _Rb_tree_iterator<_Value, _Value&, _Value*>
+ iterator;
+ typedef _Rb_tree_iterator<_Value, const _Value&, const _Value*>
+ const_iterator;
+ typedef _Rb_tree_iterator<_Value, _Ref, _Ptr>
+ _Self;
+ typedef _Rb_tree_node<_Value>* _Link_type;
+
+ _Rb_tree_iterator() {}
+ _Rb_tree_iterator(_Link_type __x) { _M_node = __x; }
+ _Rb_tree_iterator(const iterator& __it) { _M_node = __it._M_node; }
+
+ reference operator*() const { return _Link_type(_M_node)->_M_value_field; }
+#ifndef __SGI_STL_NO_ARROW_OPERATOR
+ pointer operator->() const { return &(operator*()); }
+#endif /* __SGI_STL_NO_ARROW_OPERATOR */
+
+ _Self& operator++() { _M_increment(); return *this; }
+ _Self operator++(int) {
+ _Self __tmp = *this;
+ _M_increment();
+ return __tmp;
+ }
+
+ _Self& operator--() { _M_decrement(); return *this; }
+ _Self operator--(int) {
+ _Self __tmp = *this;
+ _M_decrement();
+ return __tmp;
+ }
+};
+
+inline bool operator==(const _Rb_tree_base_iterator& __x,
+ const _Rb_tree_base_iterator& __y) {
+ return __x._M_node == __y._M_node;
+}
+
+inline bool operator!=(const _Rb_tree_base_iterator& __x,
+ const _Rb_tree_base_iterator& __y) {
+ return __x._M_node != __y._M_node;
+}
+
+#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+inline bidirectional_iterator_tag
+iterator_category(const _Rb_tree_base_iterator&) {
+ return bidirectional_iterator_tag();
+}
+
+inline _Rb_tree_base_iterator::difference_type*
+distance_type(const _Rb_tree_base_iterator&) {
+ return (_Rb_tree_base_iterator::difference_type*) 0;
+}
+
+template <class _Value, class _Ref, class _Ptr>
+inline _Value* value_type(const _Rb_tree_iterator<_Value, _Ref, _Ptr>&) {
+ return (_Value*) 0;
+}
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+inline void
+_Rb_tree_rotate_left(_Rb_tree_node_base* __x, _Rb_tree_node_base*& __root)
+{
+ _Rb_tree_node_base* __y = __x->_M_right;
+ __x->_M_right = __y->_M_left;
+ if (__y->_M_left !=0)
+ __y->_M_left->_M_parent = __x;
+ __y->_M_parent = __x->_M_parent;
+
+ if (__x == __root)
+ __root = __y;
+ else if (__x == __x->_M_parent->_M_left)
+ __x->_M_parent->_M_left = __y;
+ else
+ __x->_M_parent->_M_right = __y;
+ __y->_M_left = __x;
+ __x->_M_parent = __y;
+}
+
+inline void
+_Rb_tree_rotate_right(_Rb_tree_node_base* __x, _Rb_tree_node_base*& __root)
+{
+ _Rb_tree_node_base* __y = __x->_M_left;
+ __x->_M_left = __y->_M_right;
+ if (__y->_M_right != 0)
+ __y->_M_right->_M_parent = __x;
+ __y->_M_parent = __x->_M_parent;
+
+ if (__x == __root)
+ __root = __y;
+ else if (__x == __x->_M_parent->_M_right)
+ __x->_M_parent->_M_right = __y;
+ else
+ __x->_M_parent->_M_left = __y;
+ __y->_M_right = __x;
+ __x->_M_parent = __y;
+}
+
+inline void
+_Rb_tree_rebalance(_Rb_tree_node_base* __x, _Rb_tree_node_base*& __root)
+{
+ __x->_M_color = _S_rb_tree_red;
+ while (__x != __root && __x->_M_parent->_M_color == _S_rb_tree_red) {
+ if (__x->_M_parent == __x->_M_parent->_M_parent->_M_left) {
+ _Rb_tree_node_base* __y = __x->_M_parent->_M_parent->_M_right;
+ if (__y && __y->_M_color == _S_rb_tree_red) {
+ __x->_M_parent->_M_color = _S_rb_tree_black;
+ __y->_M_color = _S_rb_tree_black;
+ __x->_M_parent->_M_parent->_M_color = _S_rb_tree_red;
+ __x = __x->_M_parent->_M_parent;
+ }
+ else {
+ if (__x == __x->_M_parent->_M_right) {
+ __x = __x->_M_parent;
+ _Rb_tree_rotate_left(__x, __root);
+ }
+ __x->_M_parent->_M_color = _S_rb_tree_black;
+ __x->_M_parent->_M_parent->_M_color = _S_rb_tree_red;
+ _Rb_tree_rotate_right(__x->_M_parent->_M_parent, __root);
+ }
+ }
+ else {
+ _Rb_tree_node_base* __y = __x->_M_parent->_M_parent->_M_left;
+ if (__y && __y->_M_color == _S_rb_tree_red) {
+ __x->_M_parent->_M_color = _S_rb_tree_black;
+ __y->_M_color = _S_rb_tree_black;
+ __x->_M_parent->_M_parent->_M_color = _S_rb_tree_red;
+ __x = __x->_M_parent->_M_parent;
+ }
+ else {
+ if (__x == __x->_M_parent->_M_left) {
+ __x = __x->_M_parent;
+ _Rb_tree_rotate_right(__x, __root);
+ }
+ __x->_M_parent->_M_color = _S_rb_tree_black;
+ __x->_M_parent->_M_parent->_M_color = _S_rb_tree_red;
+ _Rb_tree_rotate_left(__x->_M_parent->_M_parent, __root);
+ }
+ }
+ }
+ __root->_M_color = _S_rb_tree_black;
+}
+
+inline _Rb_tree_node_base*
+_Rb_tree_rebalance_for_erase(_Rb_tree_node_base* __z,
+ _Rb_tree_node_base*& __root,
+ _Rb_tree_node_base*& __leftmost,
+ _Rb_tree_node_base*& __rightmost)
+{
+ _Rb_tree_node_base* __y = __z;
+ _Rb_tree_node_base* __x = 0;
+ _Rb_tree_node_base* __x_parent = 0;
+ if (__y->_M_left == 0) // __z has at most one non-null child. y == z.
+ __x = __y->_M_right; // __x might be null.
+ else
+ if (__y->_M_right == 0) // __z has exactly one non-null child. y == z.
+ __x = __y->_M_left; // __x is not null.
+ else { // __z has two non-null children. Set __y to
+ __y = __y->_M_right; // __z's successor. __x might be null.
+ while (__y->_M_left != 0)
+ __y = __y->_M_left;
+ __x = __y->_M_right;
+ }
+ if (__y != __z) { // relink y in place of z. y is z's successor
+ __z->_M_left->_M_parent = __y;
+ __y->_M_left = __z->_M_left;
+ if (__y != __z->_M_right) {
+ __x_parent = __y->_M_parent;
+ if (__x) __x->_M_parent = __y->_M_parent;
+ __y->_M_parent->_M_left = __x; // __y must be a child of _M_left
+ __y->_M_right = __z->_M_right;
+ __z->_M_right->_M_parent = __y;
+ }
+ else
+ __x_parent = __y;
+ if (__root == __z)
+ __root = __y;
+ else if (__z->_M_parent->_M_left == __z)
+ __z->_M_parent->_M_left = __y;
+ else
+ __z->_M_parent->_M_right = __y;
+ __y->_M_parent = __z->_M_parent;
+ __STD::swap(__y->_M_color, __z->_M_color);
+ __y = __z;
+ // __y now points to node to be actually deleted
+ }
+ else { // __y == __z
+ __x_parent = __y->_M_parent;
+ if (__x) __x->_M_parent = __y->_M_parent;
+ if (__root == __z)
+ __root = __x;
+ else
+ if (__z->_M_parent->_M_left == __z)
+ __z->_M_parent->_M_left = __x;
+ else
+ __z->_M_parent->_M_right = __x;
+ if (__leftmost == __z)
+ if (__z->_M_right == 0) // __z->_M_left must be null also
+ __leftmost = __z->_M_parent;
+ // makes __leftmost == _M_header if __z == __root
+ else
+ __leftmost = _Rb_tree_node_base::_S_minimum(__x);
+ if (__rightmost == __z)
+ if (__z->_M_left == 0) // __z->_M_right must be null also
+ __rightmost = __z->_M_parent;
+ // makes __rightmost == _M_header if __z == __root
+ else // __x == __z->_M_left
+ __rightmost = _Rb_tree_node_base::_S_maximum(__x);
+ }
+ if (__y->_M_color != _S_rb_tree_red) {
+ while (__x != __root && (__x == 0 || __x->_M_color == _S_rb_tree_black))
+ if (__x == __x_parent->_M_left) {
+ _Rb_tree_node_base* __w = __x_parent->_M_right;
+ if (__w->_M_color == _S_rb_tree_red) {
+ __w->_M_color = _S_rb_tree_black;
+ __x_parent->_M_color = _S_rb_tree_red;
+ _Rb_tree_rotate_left(__x_parent, __root);
+ __w = __x_parent->_M_right;
+ }
+ if ((__w->_M_left == 0 ||
+ __w->_M_left->_M_color == _S_rb_tree_black) &&
+ (__w->_M_right == 0 ||
+ __w->_M_right->_M_color == _S_rb_tree_black)) {
+ __w->_M_color = _S_rb_tree_red;
+ __x = __x_parent;
+ __x_parent = __x_parent->_M_parent;
+ } else {
+ if (__w->_M_right == 0 ||
+ __w->_M_right->_M_color == _S_rb_tree_black) {
+ if (__w->_M_left) __w->_M_left->_M_color = _S_rb_tree_black;
+ __w->_M_color = _S_rb_tree_red;
+ _Rb_tree_rotate_right(__w, __root);
+ __w = __x_parent->_M_right;
+ }
+ __w->_M_color = __x_parent->_M_color;
+ __x_parent->_M_color = _S_rb_tree_black;
+ if (__w->_M_right) __w->_M_right->_M_color = _S_rb_tree_black;
+ _Rb_tree_rotate_left(__x_parent, __root);
+ break;
+ }
+ } else { // same as above, with _M_right <-> _M_left.
+ _Rb_tree_node_base* __w = __x_parent->_M_left;
+ if (__w->_M_color == _S_rb_tree_red) {
+ __w->_M_color = _S_rb_tree_black;
+ __x_parent->_M_color = _S_rb_tree_red;
+ _Rb_tree_rotate_right(__x_parent, __root);
+ __w = __x_parent->_M_left;
+ }
+ if ((__w->_M_right == 0 ||
+ __w->_M_right->_M_color == _S_rb_tree_black) &&
+ (__w->_M_left == 0 ||
+ __w->_M_left->_M_color == _S_rb_tree_black)) {
+ __w->_M_color = _S_rb_tree_red;
+ __x = __x_parent;
+ __x_parent = __x_parent->_M_parent;
+ } else {
+ if (__w->_M_left == 0 ||
+ __w->_M_left->_M_color == _S_rb_tree_black) {
+ if (__w->_M_right) __w->_M_right->_M_color = _S_rb_tree_black;
+ __w->_M_color = _S_rb_tree_red;
+ _Rb_tree_rotate_left(__w, __root);
+ __w = __x_parent->_M_left;
+ }
+ __w->_M_color = __x_parent->_M_color;
+ __x_parent->_M_color = _S_rb_tree_black;
+ if (__w->_M_left) __w->_M_left->_M_color = _S_rb_tree_black;
+ _Rb_tree_rotate_right(__x_parent, __root);
+ break;
+ }
+ }
+ if (__x) __x->_M_color = _S_rb_tree_black;
+ }
+ return __y;
+}
+
+// Base class to encapsulate the differences between old SGI-style
+// allocators and standard-conforming allocators. In order to avoid
+// having an empty base class, we arbitrarily move one of rb_tree's
+// data members into the base class.
+
+#ifdef __STL_USE_STD_ALLOCATORS
+
+// _Base for general standard-conforming allocators.
+template <class _Tp, class _Alloc, bool _S_instanceless>
+class _Rb_tree_alloc_base {
+public:
+ typedef typename _Alloc_traits<_Tp, _Alloc>::allocator_type allocator_type;
+ allocator_type get_allocator() const { return _M_node_allocator; }
+
+ _Rb_tree_alloc_base(const allocator_type& __a)
+ : _M_node_allocator(__a), _M_header(0) {}
+
+protected:
+ typename _Alloc_traits<_Rb_tree_node<_Tp>, _Alloc>::allocator_type
+ _M_node_allocator;
+ _Rb_tree_node<_Tp>* _M_header;
+
+ _Rb_tree_node<_Tp>* _M_get_node()
+ { return _M_node_allocator.allocate(1); }
+ void _M_put_node(_Rb_tree_node<_Tp>* __p)
+ { _M_node_allocator.deallocate(__p, 1); }
+};
+
+// Specialization for instanceless allocators.
+template <class _Tp, class _Alloc>
+class _Rb_tree_alloc_base<_Tp, _Alloc, true> {
+public:
+ typedef typename _Alloc_traits<_Tp, _Alloc>::allocator_type allocator_type;
+ allocator_type get_allocator() const { return allocator_type(); }
+
+ _Rb_tree_alloc_base(const allocator_type&) : _M_header(0) {}
+
+protected:
+ _Rb_tree_node<_Tp>* _M_header;
+
+ typedef typename _Alloc_traits<_Rb_tree_node<_Tp>, _Alloc>::_Alloc_type
+ _Alloc_type;
+
+ _Rb_tree_node<_Tp>* _M_get_node()
+ { return _Alloc_type::allocate(1); }
+ void _M_put_node(_Rb_tree_node<_Tp>* __p)
+ { _Alloc_type::deallocate(__p, 1); }
+};
+
+template <class _Tp, class _Alloc>
+struct _Rb_tree_base
+ : public _Rb_tree_alloc_base<_Tp, _Alloc,
+ _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
+{
+ typedef _Rb_tree_alloc_base<_Tp, _Alloc,
+ _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
+ _Base;
+ typedef typename _Base::allocator_type allocator_type;
+
+ _Rb_tree_base(const allocator_type& __a)
+ : _Base(__a) { _M_header = _M_get_node(); }
+ ~_Rb_tree_base() { _M_put_node(_M_header); }
+
+};
+
+#else /* __STL_USE_STD_ALLOCATORS */
+
+template <class _Tp, class _Alloc>
+struct _Rb_tree_base
+{
+ typedef _Alloc allocator_type;
+ allocator_type get_allocator() const { return allocator_type(); }
+
+ _Rb_tree_base(const allocator_type&)
+ : _M_header(0) { _M_header = _M_get_node(); }
+ ~_Rb_tree_base() { _M_put_node(_M_header); }
+
+protected:
+ _Rb_tree_node<_Tp>* _M_header;
+
+ typedef simple_alloc<_Rb_tree_node<_Tp>, _Alloc> _Alloc_type;
+
+ _Rb_tree_node<_Tp>* _M_get_node()
+ { return _Alloc_type::allocate(1); }
+ void _M_put_node(_Rb_tree_node<_Tp>* __p)
+ { _Alloc_type::deallocate(__p, 1); }
+};
+
+#endif /* __STL_USE_STD_ALLOCATORS */
+
+template <class _Key, class _Value, class _KeyOfValue, class _Compare,
+ class _Alloc = allocator<_Value> >
+class _Rb_tree : protected _Rb_tree_base<_Value, _Alloc> {
+ typedef _Rb_tree_base<_Value, _Alloc> _Base;
+protected:
+ typedef _Rb_tree_node_base* _Base_ptr;
+ typedef _Rb_tree_node<_Value> _Rb_tree_node;
+ typedef _Rb_tree_Color_type _Color_type;
+public:
+ typedef _Key key_type;
+ typedef _Value value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef _Rb_tree_node* _Link_type;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+
+ typedef typename _Base::allocator_type allocator_type;
+ allocator_type get_allocator() const { return _Base::get_allocator(); }
+
+protected:
+#ifdef __STL_USE_NAMESPACES
+ using _Base::_M_get_node;
+ using _Base::_M_put_node;
+ using _Base::_M_header;
+#endif /* __STL_USE_NAMESPACES */
+
+protected:
+
+ _Link_type _M_create_node(const value_type& __x)
+ {
+ _Link_type __tmp = _M_get_node();
+ __STL_TRY {
+ construct(&__tmp->_M_value_field, __x);
+ }
+ __STL_UNWIND(_M_put_node(__tmp));
+ return __tmp;
+ }
+
+ _Link_type _M_clone_node(_Link_type __x)
+ {
+ _Link_type __tmp = _M_create_node(__x->_M_value_field);
+ __tmp->_M_color = __x->_M_color;
+ __tmp->_M_left = 0;
+ __tmp->_M_right = 0;
+ return __tmp;
+ }
+
+ void destroy_node(_Link_type __p)
+ {
+ destroy(&__p->_M_value_field);
+ _M_put_node(__p);
+ }
+
+protected:
+ size_type _M_node_count; // keeps track of size of tree
+ _Compare _M_key_compare;
+
+ _Link_type& _M_root() const
+ { return (_Link_type&) _M_header->_M_parent; }
+ _Link_type& _M_leftmost() const
+ { return (_Link_type&) _M_header->_M_left; }
+ _Link_type& _M_rightmost() const
+ { return (_Link_type&) _M_header->_M_right; }
+
+ static _Link_type& _S_left(_Link_type __x)
+ { return (_Link_type&)(__x->_M_left); }
+ static _Link_type& _S_right(_Link_type __x)
+ { return (_Link_type&)(__x->_M_right); }
+ static _Link_type& _S_parent(_Link_type __x)
+ { return (_Link_type&)(__x->_M_parent); }
+ static reference _S_value(_Link_type __x)
+ { return __x->_M_value_field; }
+ static const _Key& _S_key(_Link_type __x)
+ { return _KeyOfValue()(_S_value(__x)); }
+ static _Color_type& _S_color(_Link_type __x)
+ { return (_Color_type&)(__x->_M_color); }
+
+ static _Link_type& _S_left(_Base_ptr __x)
+ { return (_Link_type&)(__x->_M_left); }
+ static _Link_type& _S_right(_Base_ptr __x)
+ { return (_Link_type&)(__x->_M_right); }
+ static _Link_type& _S_parent(_Base_ptr __x)
+ { return (_Link_type&)(__x->_M_parent); }
+ static reference _S_value(_Base_ptr __x)
+ { return ((_Link_type)__x)->_M_value_field; }
+ static const _Key& _S_key(_Base_ptr __x)
+ { return _KeyOfValue()(_S_value(_Link_type(__x)));}
+ static _Color_type& _S_color(_Base_ptr __x)
+ { return (_Color_type&)(_Link_type(__x)->_M_color); }
+
+ static _Link_type _S_minimum(_Link_type __x)
+ { return (_Link_type) _Rb_tree_node_base::_S_minimum(__x); }
+
+ static _Link_type _S_maximum(_Link_type __x)
+ { return (_Link_type) _Rb_tree_node_base::_S_maximum(__x); }
+
+public:
+ typedef _Rb_tree_iterator<value_type, reference, pointer> iterator;
+ typedef _Rb_tree_iterator<value_type, const_reference, const_pointer>
+ const_iterator;
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+ typedef reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef reverse_iterator<iterator> reverse_iterator;
+#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+ typedef reverse_bidirectional_iterator<iterator, value_type, reference,
+ difference_type>
+ reverse_iterator;
+ typedef reverse_bidirectional_iterator<const_iterator, value_type,
+ const_reference, difference_type>
+ const_reverse_iterator;
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+private:
+ iterator _M_insert(_Base_ptr __x, _Base_ptr __y, const value_type& __v);
+ _Link_type _M_copy(_Link_type __x, _Link_type __p);
+ void _M_erase(_Link_type __x);
+
+public:
+ // allocation/deallocation
+ _Rb_tree()
+ : _Base(allocator_type()), _M_node_count(0), _M_key_compare()
+ { _M_empty_initialize(); }
+
+ _Rb_tree(const _Compare& __comp)
+ : _Base(allocator_type()), _M_node_count(0), _M_key_compare(__comp)
+ { _M_empty_initialize(); }
+
+ _Rb_tree(const _Compare& __comp, const allocator_type& __a)
+ : _Base(__a), _M_node_count(0), _M_key_compare(__comp)
+ { _M_empty_initialize(); }
+
+ _Rb_tree(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x)
+ : _Base(__x.get_allocator()),
+ _M_node_count(0), _M_key_compare(__x._M_key_compare)
+ {
+ if (__x._M_root() == 0)
+ _M_empty_initialize();
+ else {
+ _S_color(_M_header) = _S_rb_tree_red;
+ _M_root() = _M_copy(__x._M_root(), _M_header);
+ _M_leftmost() = _S_minimum(_M_root());
+ _M_rightmost() = _S_maximum(_M_root());
+ }
+ _M_node_count = __x._M_node_count;
+ }
+ ~_Rb_tree() { clear(); }
+ _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>&
+ operator=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x);
+
+private:
+ void _M_empty_initialize() {
+ _S_color(_M_header) = _S_rb_tree_red; // used to distinguish header from
+ // __root, in iterator.operator++
+ _M_root() = 0;
+ _M_leftmost() = _M_header;
+ _M_rightmost() = _M_header;
+ }
+
+public:
+ // accessors:
+ _Compare key_comp() const { return _M_key_compare; }
+ iterator begin() { return _M_leftmost(); }
+ const_iterator begin() const { return _M_leftmost(); }
+ iterator end() { return _M_header; }
+ const_iterator end() const { return _M_header; }
+ 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());
+ }
+ bool empty() const { return _M_node_count == 0; }
+ size_type size() const { return _M_node_count; }
+ size_type max_size() const { return size_type(-1); }
+
+ void swap(_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __t) {
+ __STD::swap(_M_header, __t._M_header);
+ __STD::swap(_M_node_count, __t._M_node_count);
+ __STD::swap(_M_key_compare, __t._M_key_compare);
+ }
+
+public:
+ // insert/erase
+ pair<iterator,bool> insert_unique(const value_type& __x);
+ iterator insert_equal(const value_type& __x);
+
+ iterator insert_unique(iterator __position, const value_type& __x);
+ iterator insert_equal(iterator __position, const value_type& __x);
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ void insert_unique(_InputIterator __first, _InputIterator __last);
+ template <class _InputIterator>
+ void insert_equal(_InputIterator __first, _InputIterator __last);
+#else /* __STL_MEMBER_TEMPLATES */
+ void insert_unique(const_iterator __first, const_iterator __last);
+ void insert_unique(const value_type* __first, const value_type* __last);
+ void insert_equal(const_iterator __first, const_iterator __last);
+ void insert_equal(const value_type* __first, const value_type* __last);
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ void erase(iterator __position);
+ size_type erase(const key_type& __x);
+ void erase(iterator __first, iterator __last);
+ void erase(const key_type* __first, const key_type* __last);
+ void clear() {
+ if (_M_node_count != 0) {
+ _M_erase(_M_root());
+ _M_leftmost() = _M_header;
+ _M_root() = 0;
+ _M_rightmost() = _M_header;
+ _M_node_count = 0;
+ }
+ }
+
+public:
+ // set operations:
+ iterator find(const key_type& __x);
+ const_iterator find(const key_type& __x) const;
+ size_type count(const key_type& __x) const;
+ iterator lower_bound(const key_type& __x);
+ const_iterator lower_bound(const key_type& __x) const;
+ iterator upper_bound(const key_type& __x);
+ const_iterator upper_bound(const key_type& __x) const;
+ pair<iterator,iterator> equal_range(const key_type& __x);
+ pair<const_iterator, const_iterator> equal_range(const key_type& __x) const;
+
+public:
+ // Debugging.
+ bool __rb_verify() const;
+};
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+inline bool
+operator==(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
+ const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y)
+{
+ return __x.size() == __y.size() &&
+ equal(__x.begin(), __x.end(), __y.begin());
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+inline bool
+operator<(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
+ const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y)
+{
+ return lexicographical_compare(__x.begin(), __x.end(),
+ __y.begin(), __y.end());
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+inline bool
+operator!=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
+ const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
+ return !(__x == __y);
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+inline bool
+operator>(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
+ const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
+ return __y < __x;
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+inline bool
+operator<=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
+ const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
+ return !(__y < __x);
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+inline bool
+operator>=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
+ const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
+ return !(__x < __y);
+}
+
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+inline void
+swap(_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
+ _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y)
+{
+ __x.swap(__y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>&
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::operator=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x)
+{
+ if (this != &__x) {
+ // Note that _Key may be a constant type.
+ clear();
+ _M_node_count = 0;
+ _M_key_compare = __x._M_key_compare;
+ if (__x._M_root() == 0) {
+ _M_root() = 0;
+ _M_leftmost() = _M_header;
+ _M_rightmost() = _M_header;
+ }
+ else {
+ _M_root() = _M_copy(__x._M_root(), _M_header);
+ _M_leftmost() = _S_minimum(_M_root());
+ _M_rightmost() = _S_maximum(_M_root());
+ _M_node_count = __x._M_node_count;
+ }
+ }
+ return *this;
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::iterator
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::_M_insert(_Base_ptr __x_, _Base_ptr __y_, const _Value& __v)
+{
+ _Link_type __x = (_Link_type) __x_;
+ _Link_type __y = (_Link_type) __y_;
+ _Link_type __z;
+
+ if (__y == _M_header || __x != 0 ||
+ _M_key_compare(_KeyOfValue()(__v), _S_key(__y))) {
+ __z = _M_create_node(__v);
+ _S_left(__y) = __z; // also makes _M_leftmost() = __z
+ // when __y == _M_header
+ if (__y == _M_header) {
+ _M_root() = __z;
+ _M_rightmost() = __z;
+ }
+ else if (__y == _M_leftmost())
+ _M_leftmost() = __z; // maintain _M_leftmost() pointing to min node
+ }
+ else {
+ __z = _M_create_node(__v);
+ _S_right(__y) = __z;
+ if (__y == _M_rightmost())
+ _M_rightmost() = __z; // maintain _M_rightmost() pointing to max node
+ }
+ _S_parent(__z) = __y;
+ _S_left(__z) = 0;
+ _S_right(__z) = 0;
+ _Rb_tree_rebalance(__z, _M_header->_M_parent);
+ ++_M_node_count;
+ return iterator(__z);
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::iterator
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::insert_equal(const _Value& __v)
+{
+ _Link_type __y = _M_header;
+ _Link_type __x = _M_root();
+ while (__x != 0) {
+ __y = __x;
+ __x = _M_key_compare(_KeyOfValue()(__v), _S_key(__x)) ?
+ _S_left(__x) : _S_right(__x);
+ }
+ return _M_insert(__x, __y, __v);
+}
+
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+pair<typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::iterator,
+ bool>
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::insert_unique(const _Value& __v)
+{
+ _Link_type __y = _M_header;
+ _Link_type __x = _M_root();
+ bool __comp = true;
+ while (__x != 0) {
+ __y = __x;
+ __comp = _M_key_compare(_KeyOfValue()(__v), _S_key(__x));
+ __x = __comp ? _S_left(__x) : _S_right(__x);
+ }
+ iterator __j = iterator(__y);
+ if (__comp)
+ if (__j == begin())
+ return pair<iterator,bool>(_M_insert(__x, __y, __v), true);
+ else
+ --__j;
+ if (_M_key_compare(_S_key(__j._M_node), _KeyOfValue()(__v)))
+ return pair<iterator,bool>(_M_insert(__x, __y, __v), true);
+ return pair<iterator,bool>(__j, false);
+}
+
+
+template <class _Key, class _Val, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
+_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>
+ ::insert_unique(iterator __position, const _Val& __v)
+{
+ if (__position._M_node == _M_header->_M_left) { // begin()
+ if (size() > 0 &&
+ _M_key_compare(_S_key(__position._M_node), _KeyOfValue()(__v)))
+ return _M_insert(__position._M_node, __position._M_node, __v);
+ // first argument just needs to be non-null
+ else
+ return insert_unique(__v).first;
+ } else if (__position._M_node == _M_header) { // end()
+ if (_M_key_compare(_S_key(_M_rightmost()), _KeyOfValue()(__v)))
+ return _M_insert(0, _M_rightmost(), __v);
+ else
+ return insert_unique(__v).first;
+ } else {
+ iterator __before = __position;
+ --__before;
+ if (_M_key_compare(_S_key(__before._M_node), _KeyOfValue()(__v))
+ && _M_key_compare(_KeyOfValue()(__v), _S_key(__position._M_node))) {
+ if (_S_right(__before._M_node) == 0)
+ return _M_insert(0, __before._M_node, __v);
+ else
+ return _M_insert(__position._M_node, __position._M_node, __v);
+ // first argument just needs to be non-null
+ } else
+ return insert_unique(__v).first;
+ }
+}
+
+template <class _Key, class _Val, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::iterator
+_Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>
+ ::insert_equal(iterator __position, const _Val& __v)
+{
+ if (__position._M_node == _M_header->_M_left) { // begin()
+ if (size() > 0 &&
+ ! _M_key_compare(_S_key(__position._M_node), _KeyOfValue()(__v)))
+ return _M_insert(__position._M_node, __position._M_node, __v);
+ // first argument just needs to be non-null
+ else
+ return insert_equal(__v);
+ } else if (__position._M_node == _M_header) {// end()
+ if (!_M_key_compare(_KeyOfValue()(__v), _S_key(_M_rightmost())))
+ return _M_insert(0, _M_rightmost(), __v);
+ else
+ return insert_equal(__v);
+ } else {
+ iterator __before = __position;
+ --__before;
+ if (!_M_key_compare(_KeyOfValue()(__v), _S_key(__before._M_node))
+ && !_M_key_compare(_S_key(__position._M_node), _KeyOfValue()(__v))) {
+ if (_S_right(__before._M_node) == 0)
+ return _M_insert(0, __before._M_node, __v);
+ else
+ return _M_insert(__position._M_node, __position._M_node, __v);
+ // first argument just needs to be non-null
+ } else
+ return insert_equal(__v);
+ }
+}
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+template <class _Key, class _Val, class _KoV, class _Cmp, class _Alloc>
+ template<class _II>
+void _Rb_tree<_Key,_Val,_KoV,_Cmp,_Alloc>
+ ::insert_equal(_II __first, _II __last)
+{
+ for ( ; __first != __last; ++__first)
+ insert_equal(*__first);
+}
+
+template <class _Key, class _Val, class _KoV, class _Cmp, class _Alloc>
+ template<class _II>
+void _Rb_tree<_Key,_Val,_KoV,_Cmp,_Alloc>
+ ::insert_unique(_II __first, _II __last) {
+ for ( ; __first != __last; ++__first)
+ insert_unique(*__first);
+}
+
+#else /* __STL_MEMBER_TEMPLATES */
+
+template <class _Key, class _Val, class _KoV, class _Cmp, class _Alloc>
+void
+_Rb_tree<_Key,_Val,_KoV,_Cmp,_Alloc>
+ ::insert_equal(const _Val* __first, const _Val* __last)
+{
+ for ( ; __first != __last; ++__first)
+ insert_equal(*__first);
+}
+
+template <class _Key, class _Val, class _KoV, class _Cmp, class _Alloc>
+void
+_Rb_tree<_Key,_Val,_KoV,_Cmp,_Alloc>
+ ::insert_equal(const_iterator __first, const_iterator __last)
+{
+ for ( ; __first != __last; ++__first)
+ insert_equal(*__first);
+}
+
+template <class _Key, class _Val, class _KoV, class _Cmp, class _Alloc>
+void
+_Rb_tree<_Key,_Val,_KoV,_Cmp,_Alloc>
+ ::insert_unique(const _Val* __first, const _Val* __last)
+{
+ for ( ; __first != __last; ++__first)
+ insert_unique(*__first);
+}
+
+template <class _Key, class _Val, class _KoV, class _Cmp, class _Alloc>
+void _Rb_tree<_Key,_Val,_KoV,_Cmp,_Alloc>
+ ::insert_unique(const_iterator __first, const_iterator __last)
+{
+ for ( ; __first != __last; ++__first)
+ insert_unique(*__first);
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+inline void _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::erase(iterator __position)
+{
+ _Link_type __y =
+ (_Link_type) _Rb_tree_rebalance_for_erase(__position._M_node,
+ _M_header->_M_parent,
+ _M_header->_M_left,
+ _M_header->_M_right);
+ destroy_node(__y);
+ --_M_node_count;
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::size_type
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::erase(const _Key& __x)
+{
+ pair<iterator,iterator> __p = equal_range(__x);
+ size_type __n = 0;
+ distance(__p.first, __p.second, __n);
+ erase(__p.first, __p.second);
+ return __n;
+}
+
+template <class _Key, class _Val, class _KoV, class _Compare, class _Alloc>
+typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type
+_Rb_tree<_Key,_Val,_KoV,_Compare,_Alloc>
+ ::_M_copy(_Link_type __x, _Link_type __p)
+{
+ // structural copy. __x and __p must be non-null.
+ _Link_type __top = _M_clone_node(__x);
+ __top->_M_parent = __p;
+
+ __STL_TRY {
+ if (__x->_M_right)
+ __top->_M_right = _M_copy(_S_right(__x), __top);
+ __p = __top;
+ __x = _S_left(__x);
+
+ while (__x != 0) {
+ _Link_type __y = _M_clone_node(__x);
+ __p->_M_left = __y;
+ __y->_M_parent = __p;
+ if (__x->_M_right)
+ __y->_M_right = _M_copy(_S_right(__x), __y);
+ __p = __y;
+ __x = _S_left(__x);
+ }
+ }
+ __STL_UNWIND(_M_erase(__top));
+
+ return __top;
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+void _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::_M_erase(_Link_type __x)
+{
+ // erase without rebalancing
+ while (__x != 0) {
+ _M_erase(_S_right(__x));
+ _Link_type __y = _S_left(__x);
+ destroy_node(__x);
+ __x = __y;
+ }
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+void _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::erase(iterator __first, iterator __last)
+{
+ if (__first == begin() && __last == end())
+ clear();
+ else
+ while (__first != __last) erase(__first++);
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+void _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::erase(const _Key* __first, const _Key* __last)
+{
+ while (__first != __last) erase(*__first++);
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::iterator
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::find(const _Key& __k)
+{
+ _Link_type __y = _M_header; // Last node which is not less than __k.
+ _Link_type __x = _M_root(); // Current node.
+
+ while (__x != 0)
+ if (!_M_key_compare(_S_key(__x), __k))
+ __y = __x, __x = _S_left(__x);
+ else
+ __x = _S_right(__x);
+
+ iterator __j = iterator(__y);
+ return (__j == end() || _M_key_compare(__k, _S_key(__j._M_node))) ?
+ end() : __j;
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::const_iterator
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::find(const _Key& __k) const
+{
+ _Link_type __y = _M_header; /* Last node which is not less than __k. */
+ _Link_type __x = _M_root(); /* Current node. */
+
+ while (__x != 0) {
+ if (!_M_key_compare(_S_key(__x), __k))
+ __y = __x, __x = _S_left(__x);
+ else
+ __x = _S_right(__x);
+ }
+ const_iterator __j = const_iterator(__y);
+ return (__j == end() || _M_key_compare(__k, _S_key(__j._M_node))) ?
+ end() : __j;
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::size_type
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::count(const _Key& __k) const
+{
+ pair<const_iterator, const_iterator> __p = equal_range(__k);
+ size_type __n = 0;
+ distance(__p.first, __p.second, __n);
+ return __n;
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::iterator
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::lower_bound(const _Key& __k)
+{
+ _Link_type __y = _M_header; /* Last node which is not less than __k. */
+ _Link_type __x = _M_root(); /* Current node. */
+
+ while (__x != 0)
+ if (!_M_key_compare(_S_key(__x), __k))
+ __y = __x, __x = _S_left(__x);
+ else
+ __x = _S_right(__x);
+
+ return iterator(__y);
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::const_iterator
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::lower_bound(const _Key& __k) const
+{
+ _Link_type __y = _M_header; /* Last node which is not less than __k. */
+ _Link_type __x = _M_root(); /* Current node. */
+
+ while (__x != 0)
+ if (!_M_key_compare(_S_key(__x), __k))
+ __y = __x, __x = _S_left(__x);
+ else
+ __x = _S_right(__x);
+
+ return const_iterator(__y);
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::iterator
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::upper_bound(const _Key& __k)
+{
+ _Link_type __y = _M_header; /* Last node which is greater than __k. */
+ _Link_type __x = _M_root(); /* Current node. */
+
+ while (__x != 0)
+ if (_M_key_compare(__k, _S_key(__x)))
+ __y = __x, __x = _S_left(__x);
+ else
+ __x = _S_right(__x);
+
+ return iterator(__y);
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::const_iterator
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::upper_bound(const _Key& __k) const
+{
+ _Link_type __y = _M_header; /* Last node which is greater than __k. */
+ _Link_type __x = _M_root(); /* Current node. */
+
+ while (__x != 0)
+ if (_M_key_compare(__k, _S_key(__x)))
+ __y = __x, __x = _S_left(__x);
+ else
+ __x = _S_right(__x);
+
+ return const_iterator(__y);
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+inline
+pair<typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::iterator,
+ typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::iterator>
+_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>
+ ::equal_range(const _Key& __k)
+{
+ return pair<iterator, iterator>(lower_bound(__k), upper_bound(__k));
+}
+
+template <class _Key, class _Value, class _KoV, class _Compare, class _Alloc>
+inline
+pair<typename _Rb_tree<_Key, _Value, _KoV, _Compare, _Alloc>::const_iterator,
+ typename _Rb_tree<_Key, _Value, _KoV, _Compare, _Alloc>::const_iterator>
+_Rb_tree<_Key, _Value, _KoV, _Compare, _Alloc>
+ ::equal_range(const _Key& __k) const
+{
+ return pair<const_iterator,const_iterator>(lower_bound(__k),
+ upper_bound(__k));
+}
+
+inline int
+__black_count(_Rb_tree_node_base* __node, _Rb_tree_node_base* __root)
+{
+ if (__node == 0)
+ return 0;
+ int __sum = 0;
+ do {
+ if (__node->_M_color == _S_rb_tree_black)
+ ++__sum;
+ if (__node == __root)
+ break;
+ __node = __node->_M_parent;
+ } while (1);
+ return __sum;
+}
+
+template <class _Key, class _Value, class _KeyOfValue,
+ class _Compare, class _Alloc>
+bool _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::__rb_verify() const
+{
+ if (_M_node_count == 0 || begin() == end())
+ return _M_node_count == 0 && begin() == end() &&
+ _M_header->_M_left == _M_header && _M_header->_M_right == _M_header;
+
+ int __len = __black_count(_M_leftmost(), _M_root());
+ for (const_iterator __it = begin(); __it != end(); ++__it) {
+ _Link_type __x = (_Link_type) __it._M_node;
+ _Link_type __L = _S_left(__x);
+ _Link_type __R = _S_right(__x);
+
+ if (__x->_M_color == _S_rb_tree_red)
+ if ((__L && __L->_M_color == _S_rb_tree_red) ||
+ (__R && __R->_M_color == _S_rb_tree_red))
+ return false;
+
+ if (__L && _M_key_compare(_S_key(__x), _S_key(__L)))
+ return false;
+ if (__R && _M_key_compare(_S_key(__R), _S_key(__x)))
+ return false;
+
+ if (!__L && !__R && __black_count(__x, _M_root()) != __len)
+ return false;
+ }
+
+ if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root()))
+ return false;
+ if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root()))
+ return false;
+
+ return true;
+}
+
+// Class rb_tree is not part of the C++ standard. It is provided for
+// compatibility with the HP STL.
+
+template <class _Key, class _Value, class _KeyOfValue, class _Compare,
+ class _Alloc = allocator<_Value> >
+struct rb_tree : public _Rb_tree<_Key, _Value, _KeyOfValue, _Compare, _Alloc>
+{
+ typedef _Rb_tree<_Key, _Value, _KeyOfValue, _Compare, _Alloc> _Base;
+ typedef typename _Base::allocator_type allocator_type;
+
+ rb_tree(const _Compare& __comp = _Compare(),
+ const allocator_type& __a = allocator_type())
+ : _Base(__comp, __a) {}
+
+ ~rb_tree() {}
+};
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1375
+#endif
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_TREE_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_uninitialized.h b/libstdc++-v3/bits/stl_uninitialized.h
new file mode 100644
index 0000000..087424a
--- /dev/null
+++ b/libstdc++-v3/bits/stl_uninitialized.h
@@ -0,0 +1,281 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996,1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef _CPP_BITS_STL_UNINITIALIZED_H
+#define _CPP_BITS_STL_UNINITIALIZED_H 1
+
+#include <bits/std_cstring.h>
+
+__STL_BEGIN_NAMESPACE
+
+// uninitialized_copy
+
+// Valid if copy construction is equivalent to assignment, and if the
+// destructor is trivial.
+template <class _InputIter, class _ForwardIter>
+inline _ForwardIter
+__uninitialized_copy_aux(_InputIter __first, _InputIter __last,
+ _ForwardIter __result,
+ __true_type)
+{
+ return copy(__first, __last, __result);
+}
+
+template <class _InputIter, class _ForwardIter>
+_ForwardIter
+__uninitialized_copy_aux(_InputIter __first, _InputIter __last,
+ _ForwardIter __result,
+ __false_type)
+{
+ _ForwardIter __cur = __result;
+ __STL_TRY {
+ for ( ; __first != __last; ++__first, ++__cur)
+ construct(&*__cur, *__first);
+ return __cur;
+ }
+ __STL_UNWIND(destroy(__result, __cur));
+}
+
+
+template <class _InputIter, class _ForwardIter, class _Tp>
+inline _ForwardIter
+__uninitialized_copy(_InputIter __first, _InputIter __last,
+ _ForwardIter __result, _Tp*)
+{
+ typedef typename __type_traits<_Tp>::is_POD_type _Is_POD;
+ return __uninitialized_copy_aux(__first, __last, __result, _Is_POD());
+}
+
+template <class _InputIter, class _ForwardIter>
+inline _ForwardIter
+ uninitialized_copy(_InputIter __first, _InputIter __last,
+ _ForwardIter __result)
+{
+ return __uninitialized_copy(__first, __last, __result,
+ __VALUE_TYPE(__result));
+}
+
+inline char* uninitialized_copy(const char* __first, const char* __last,
+ char* __result) {
+ memmove(__result, __first, __last - __first);
+ return __result + (__last - __first);
+}
+
+inline wchar_t*
+uninitialized_copy(const wchar_t* __first, const wchar_t* __last,
+ wchar_t* __result)
+{
+ memmove(__result, __first, sizeof(wchar_t) * (__last - __first));
+ return __result + (__last - __first);
+}
+
+// uninitialized_copy_n (not part of the C++ standard)
+
+template <class _InputIter, class _Size, class _ForwardIter>
+pair<_InputIter, _ForwardIter>
+__uninitialized_copy_n(_InputIter __first, _Size __count,
+ _ForwardIter __result,
+ input_iterator_tag)
+{
+ _ForwardIter __cur = __result;
+ __STL_TRY {
+ for ( ; __count > 0 ; --__count, ++__first, ++__cur)
+ construct(&*__cur, *__first);
+ return pair<_InputIter, _ForwardIter>(__first, __cur);
+ }
+ __STL_UNWIND(destroy(__result, __cur));
+}
+
+template <class _RandomAccessIter, class _Size, class _ForwardIter>
+inline pair<_RandomAccessIter, _ForwardIter>
+__uninitialized_copy_n(_RandomAccessIter __first, _Size __count,
+ _ForwardIter __result,
+ random_access_iterator_tag) {
+ _RandomAccessIter __last = __first + __count;
+ return pair<_RandomAccessIter, _ForwardIter>(
+ __last,
+ uninitialized_copy(__first, __last, __result));
+}
+
+template <class _InputIter, class _Size, class _ForwardIter>
+inline pair<_InputIter, _ForwardIter>
+__uninitialized_copy_n(_InputIter __first, _Size __count,
+ _ForwardIter __result) {
+ return __uninitialized_copy_n(__first, __count, __result,
+ __ITERATOR_CATEGORY(__first));
+}
+
+template <class _InputIter, class _Size, class _ForwardIter>
+inline pair<_InputIter, _ForwardIter>
+uninitialized_copy_n(_InputIter __first, _Size __count,
+ _ForwardIter __result) {
+ return __uninitialized_copy_n(__first, __count, __result,
+ __ITERATOR_CATEGORY(__first));
+}
+
+// Valid if copy construction is equivalent to assignment, and if the
+// destructor is trivial.
+template <class _ForwardIter, class _Tp>
+inline void
+__uninitialized_fill_aux(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __x, __true_type)
+{
+ fill(__first, __last, __x);
+}
+
+template <class _ForwardIter, class _Tp>
+void
+__uninitialized_fill_aux(_ForwardIter __first, _ForwardIter __last,
+ const _Tp& __x, __false_type)
+{
+ _ForwardIter __cur = __first;
+ __STL_TRY {
+ for ( ; __cur != __last; ++__cur)
+ construct(&*__cur, __x);
+ }
+ __STL_UNWIND(destroy(__first, __cur));
+}
+
+template <class _ForwardIter, class _Tp, class _Tp1>
+inline void __uninitialized_fill(_ForwardIter __first,
+ _ForwardIter __last, const _Tp& __x, _Tp1*)
+{
+ typedef typename __type_traits<_Tp1>::is_POD_type _Is_POD;
+ __uninitialized_fill_aux(__first, __last, __x, _Is_POD());
+
+}
+
+template <class _ForwardIter, class _Tp>
+inline void uninitialized_fill(_ForwardIter __first,
+ _ForwardIter __last,
+ const _Tp& __x)
+{
+ __uninitialized_fill(__first, __last, __x, __VALUE_TYPE(__first));
+}
+
+// Valid if copy construction is equivalent to assignment, and if the
+// destructor is trivial.
+template <class _ForwardIter, class _Size, class _Tp>
+inline _ForwardIter
+__uninitialized_fill_n_aux(_ForwardIter __first, _Size __n,
+ const _Tp& __x, __true_type)
+{
+ return fill_n(__first, __n, __x);
+}
+
+template <class _ForwardIter, class _Size, class _Tp>
+_ForwardIter
+__uninitialized_fill_n_aux(_ForwardIter __first, _Size __n,
+ const _Tp& __x, __false_type)
+{
+ _ForwardIter __cur = __first;
+ __STL_TRY {
+ for ( ; __n > 0; --__n, ++__cur)
+ construct(&*__cur, __x);
+ return __cur;
+ }
+ __STL_UNWIND(destroy(__first, __cur));
+}
+
+template <class _ForwardIter, class _Size, class _Tp, class _Tp1>
+inline _ForwardIter
+__uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x, _Tp1*)
+{
+ typedef typename __type_traits<_Tp1>::is_POD_type _Is_POD;
+ return __uninitialized_fill_n_aux(__first, __n, __x, _Is_POD());
+}
+
+template <class _ForwardIter, class _Size, class _Tp>
+inline _ForwardIter
+uninitialized_fill_n(_ForwardIter __first, _Size __n, const _Tp& __x)
+{
+ return __uninitialized_fill_n(__first, __n, __x, __VALUE_TYPE(__first));
+}
+
+// Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill,
+// __uninitialized_fill_copy.
+
+// __uninitialized_copy_copy
+// Copies [first1, last1) into [result, result + (last1 - first1)), and
+// copies [first2, last2) into
+// [result, result + (last1 - first1) + (last2 - first2)).
+
+template <class _InputIter1, class _InputIter2, class _ForwardIter>
+inline _ForwardIter
+__uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
+ _InputIter2 __first2, _InputIter2 __last2,
+ _ForwardIter __result)
+{
+ _ForwardIter __mid = uninitialized_copy(__first1, __last1, __result);
+ __STL_TRY {
+ return uninitialized_copy(__first2, __last2, __mid);
+ }
+ __STL_UNWIND(destroy(__result, __mid));
+}
+
+// __uninitialized_fill_copy
+// Fills [result, mid) with x, and copies [first, last) into
+// [mid, mid + (last - first)).
+template <class _ForwardIter, class _Tp, class _InputIter>
+inline _ForwardIter
+__uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid,
+ const _Tp& __x,
+ _InputIter __first, _InputIter __last)
+{
+ uninitialized_fill(__result, __mid, __x);
+ __STL_TRY {
+ return uninitialized_copy(__first, __last, __mid);
+ }
+ __STL_UNWIND(destroy(__result, __mid));
+}
+
+// __uninitialized_copy_fill
+// Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
+// fills [first2 + (last1 - first1), last2) with x.
+template <class _InputIter, class _ForwardIter, class _Tp>
+inline void
+__uninitialized_copy_fill(_InputIter __first1, _InputIter __last1,
+ _ForwardIter __first2, _ForwardIter __last2,
+ const _Tp& __x)
+{
+ _ForwardIter __mid2 = uninitialized_copy(__first1, __last1, __first2);
+ __STL_TRY {
+ uninitialized_fill(__mid2, __last2, __x);
+ }
+ __STL_UNWIND(destroy(__first2, __mid2));
+}
+
+__STL_END_NAMESPACE
+
+#endif /* _CPP_BITS_STL_UNINITIALIZED_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/stl_vector.h b/libstdc++-v3/bits/stl_vector.h
new file mode 100644
index 0000000..3d2994cc
--- /dev/null
+++ b/libstdc++-v3/bits/stl_vector.h
@@ -0,0 +1,873 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ *
+ * Copyright (c) 1996
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+/* NOTE: This is an internal header file, included by other STL headers.
+ * You should not attempt to use it directly.
+ */
+
+#ifndef __SGI_STL_INTERNAL_VECTOR_H
+#define __SGI_STL_INTERNAL_VECTOR_H
+
+#include <bits/exception_support.h>
+
+__STL_BEGIN_NAMESPACE
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma set woff 1174
+#pragma set woff 1375
+#endif
+
+// The vector base class serves two purposes. First, its constructor
+// and destructor allocate (but don't initialize) storage. This makes
+// exception safety easier. Second, the base class encapsulates all of
+// the differences between SGI-style allocators and standard-conforming
+// allocators.
+
+#ifdef __STL_USE_STD_ALLOCATORS
+
+// Base class for ordinary allocators.
+template <class _Tp, class _Allocator, bool _IsStatic>
+class _Vector_alloc_base {
+public:
+ typedef typename _Alloc_traits<_Tp, _Allocator>::allocator_type
+ allocator_type;
+ allocator_type get_allocator() const { return _M_data_allocator; }
+
+ _Vector_alloc_base(const allocator_type& __a)
+ : _M_data_allocator(__a), _M_start(0), _M_finish(0), _M_end_of_storage(0)
+ {}
+
+protected:
+ allocator_type _M_data_allocator;
+ _Tp* _M_start;
+ _Tp* _M_finish;
+ _Tp* _M_end_of_storage;
+
+ _Tp* _M_allocate(size_t __n)
+ { return _M_data_allocator.allocate(__n); }
+ void _M_deallocate(_Tp* __p, size_t __n)
+ { if (__p) _M_data_allocator.deallocate(__p, __n); }
+};
+
+// Specialization for allocators that have the property that we don't
+// actually have to store an allocator object.
+template <class _Tp, class _Allocator>
+class _Vector_alloc_base<_Tp, _Allocator, true> {
+public:
+ typedef typename _Alloc_traits<_Tp, _Allocator>::allocator_type
+ allocator_type;
+ allocator_type get_allocator() const { return allocator_type(); }
+
+ _Vector_alloc_base(const allocator_type&)
+ : _M_start(0), _M_finish(0), _M_end_of_storage(0)
+ {}
+
+protected:
+ _Tp* _M_start;
+ _Tp* _M_finish;
+ _Tp* _M_end_of_storage;
+
+ typedef typename _Alloc_traits<_Tp, _Allocator>::_Alloc_type _Alloc_type;
+ _Tp* _M_allocate(size_t __n)
+ { return _Alloc_type::allocate(__n); }
+ void _M_deallocate(_Tp* __p, size_t __n)
+ { _Alloc_type::deallocate(__p, __n);}
+};
+
+template <class _Tp, class _Alloc>
+struct _Vector_base
+ : public _Vector_alloc_base<_Tp, _Alloc,
+ _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
+{
+ typedef _Vector_alloc_base<_Tp, _Alloc,
+ _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
+ _Base;
+ typedef typename _Base::allocator_type allocator_type;
+
+ _Vector_base(const allocator_type& __a) : _Base(__a) {}
+ _Vector_base(size_t __n, const allocator_type& __a) : _Base(__a) {
+ _M_start = _M_allocate(__n);
+ _M_finish = _M_start;
+ _M_end_of_storage = _M_start + __n;
+ }
+
+ ~_Vector_base() { _M_deallocate(_M_start, _M_end_of_storage - _M_start); }
+};
+
+#else /* __STL_USE_STD_ALLOCATORS */
+
+template <class _Tp, class _Alloc>
+class _Vector_base {
+public:
+ typedef _Alloc allocator_type;
+ allocator_type get_allocator() const { return allocator_type(); }
+
+ _Vector_base(const _Alloc&)
+ : _M_start(0), _M_finish(0), _M_end_of_storage(0) {}
+ _Vector_base(size_t __n, const _Alloc&)
+ : _M_start(0), _M_finish(0), _M_end_of_storage(0)
+ {
+ _M_start = _M_allocate(__n);
+ _M_finish = _M_start;
+ _M_end_of_storage = _M_start + __n;
+ }
+
+ ~_Vector_base() { _M_deallocate(_M_start, _M_end_of_storage - _M_start); }
+
+protected:
+ _Tp* _M_start;
+ _Tp* _M_finish;
+ _Tp* _M_end_of_storage;
+
+ typedef simple_alloc<_Tp, _Alloc> _M_data_allocator;
+ _Tp* _M_allocate(size_t __n)
+ { return _M_data_allocator::allocate(__n); }
+ void _M_deallocate(_Tp* __p, size_t __n)
+ { _M_data_allocator::deallocate(__p, __n); }
+};
+
+#endif /* __STL_USE_STD_ALLOCATORS */
+
+template <class _Tp, class _Alloc = allocator<_Tp> >
+class vector : protected _Vector_base<_Tp, _Alloc>
+{
+private:
+ typedef _Vector_base<_Tp, _Alloc> _Base;
+ typedef vector<_Tp, _Alloc> vector_type;
+public:
+ typedef _Tp value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef __normal_iterator<pointer, vector_type> iterator;
+ typedef __normal_iterator<const_pointer, vector_type> const_iterator;
+ typedef value_type& reference;
+ typedef const value_type& const_reference;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+
+ typedef typename _Base::allocator_type allocator_type;
+ allocator_type get_allocator() const { return _Base::get_allocator(); }
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+ typedef reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef reverse_iterator<iterator> reverse_iterator;
+#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+ typedef reverse_iterator<const_iterator, value_type, const_reference,
+ difference_type> const_reverse_iterator;
+ typedef reverse_iterator<iterator, value_type, reference, difference_type>
+ reverse_iterator;
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+protected:
+#ifdef __STL_HAS_NAMESPACES
+ using _Base::_M_allocate;
+ using _Base::_M_deallocate;
+ using _Base::_M_start;
+ using _Base::_M_finish;
+ using _Base::_M_end_of_storage;
+#endif /* __STL_HAS_NAMESPACES */
+
+protected:
+ void _M_insert_aux(iterator __position, const _Tp& __x);
+ void _M_insert_aux(iterator __position);
+
+public:
+ iterator begin() { return iterator (_M_start); }
+ const_iterator begin() const
+ { return const_iterator (_M_start); }
+ iterator end() { return iterator (_M_finish); }
+ const_iterator end() const { return const_iterator (_M_finish); }
+
+ 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()); }
+
+ size_type size() const
+ { return size_type(end() - begin()); }
+ size_type max_size() const
+ { return size_type(-1) / sizeof(_Tp); }
+ size_type capacity() const
+ { return size_type(const_iterator(_M_end_of_storage) - begin()); }
+ bool empty() const
+ { return begin() == end(); }
+
+ reference operator[](size_type __n) { return *(begin() + __n); }
+ const_reference operator[](size_type __n) const { return *(begin() + __n); }
+
+#ifdef __STL_THROW_RANGE_ERRORS
+ void _M_range_check(size_type __n) const {
+ if (__n >= this->size())
+ __out_of_range("vector");
+ }
+
+ reference at(size_type __n)
+ { _M_range_check(__n); return (*this)[__n]; }
+ const_reference at(size_type __n) const
+ { _M_range_check(__n); return (*this)[__n]; }
+#endif /* __STL_THROW_RANGE_ERRORS */
+
+ explicit vector(const allocator_type& __a = allocator_type())
+ : _Base(__a) {}
+
+ vector(size_type __n, const _Tp& __value,
+ const allocator_type& __a = allocator_type())
+ : _Base(__n, __a)
+ { _M_finish = uninitialized_fill_n(_M_start, __n, __value); }
+
+ explicit vector(size_type __n)
+ : _Base(__n, allocator_type())
+ { _M_finish = uninitialized_fill_n(_M_start, __n, _Tp()); }
+
+ vector(const vector<_Tp, _Alloc>& __x)
+ : _Base(__x.size(), __x.get_allocator())
+ { _M_finish = uninitialized_copy(__x.begin(), __x.end(), _M_start); }
+
+#ifdef __STL_MEMBER_TEMPLATES
+ // Check whether it's an integral type. If so, it's not an iterator.
+ template <class _InputIterator>
+ vector(_InputIterator __first, _InputIterator __last,
+ const allocator_type& __a = allocator_type()) : _Base(__a) {
+ typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
+ _M_initialize_aux(__first, __last, _Integral());
+ }
+
+ template <class _Integer>
+ void _M_initialize_aux(_Integer __n, _Integer __value, __true_type) {
+ _M_start = _M_allocate(__n);
+ _M_end_of_storage = _M_start + __n;
+ _M_finish = uninitialized_fill_n(_M_start, __n, __value);
+ }
+
+ template <class _InputIterator>
+ void _M_initialize_aux(_InputIterator __first, _InputIterator __last,
+ __false_type) {
+ _M_range_initialize(__first, __last, __ITERATOR_CATEGORY(__first));
+ }
+
+#else
+ vector(const _Tp* __first, const _Tp* __last,
+ const allocator_type& __a = allocator_type())
+ : _Base(__last - __first, __a)
+ { _M_finish = uninitialized_copy(__first, __last, _M_start); }
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ ~vector() { destroy(_M_start, _M_finish); }
+
+ vector<_Tp, _Alloc>& operator=(const vector<_Tp, _Alloc>& __x);
+ void reserve(size_type __n) {
+ if (capacity() < __n) {
+ const size_type __old_size = size();
+ pointer __tmp = _M_allocate_and_copy(__n, _M_start, _M_finish);
+ destroy(_M_start, _M_finish);
+ _M_deallocate(_M_start, _M_end_of_storage - _M_start);
+ _M_start = __tmp;
+ _M_finish = __tmp + __old_size;
+ _M_end_of_storage = _M_start + __n;
+ }
+ }
+
+ // assign(), a generalized assignment member function. Two
+ // versions: one that takes a count, and one that takes a range.
+ // The range version is a member template, so we dispatch on whether
+ // or not the type is an integer.
+
+ void assign(size_type __n, const _Tp& __val) { _M_fill_assign(__n, __val); }
+ void _M_fill_assign(size_type __n, const _Tp& __val);
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+ template <class _InputIterator>
+ void assign(_InputIterator __first, _InputIterator __last) {
+ typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
+ _M_assign_dispatch(__first, __last, _Integral());
+ }
+
+ template <class _Integer>
+ void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
+ { _M_fill_assign((size_type) __n, (_Tp) __val); }
+
+ template <class _InputIter>
+ void _M_assign_dispatch(_InputIter __first, _InputIter __last, __false_type)
+ { _M_assign_aux(__first, __last, __ITERATOR_CATEGORY(__first)); }
+
+ template <class _InputIterator>
+ void _M_assign_aux(_InputIterator __first, _InputIterator __last,
+ input_iterator_tag);
+
+ template <class _ForwardIterator>
+ void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
+ forward_iterator_tag);
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ reference front() { return *begin(); }
+ const_reference front() const { return *begin(); }
+ reference back() { return *(end() - 1); }
+ const_reference back() const { return *(end() - 1); }
+
+ void push_back(const _Tp& __x) {
+ if (_M_finish != _M_end_of_storage) {
+ construct(_M_finish, __x);
+ ++_M_finish;
+ }
+ else
+ _M_insert_aux(end(), __x);
+ }
+ void push_back() {
+ if (_M_finish != _M_end_of_storage) {
+ construct(_M_finish);
+ ++_M_finish;
+ }
+ else
+ _M_insert_aux(end());
+ }
+ void swap(vector<_Tp, _Alloc>& __x) {
+ __STD::swap(_M_start, __x._M_start);
+ __STD::swap(_M_finish, __x._M_finish);
+ __STD::swap(_M_end_of_storage, __x._M_end_of_storage);
+ }
+
+ iterator insert(iterator __position, const _Tp& __x) {
+ size_type __n = __position - begin();
+ if (_M_finish != _M_end_of_storage && __position == end()) {
+ construct(_M_finish, __x);
+ ++_M_finish;
+ }
+ else
+ _M_insert_aux(iterator(__position), __x);
+ return begin() + __n;
+ }
+ iterator insert(iterator __position) {
+ size_type __n = __position - begin();
+ if (_M_finish != _M_end_of_storage && __position == end()) {
+ construct(_M_finish);
+ ++_M_finish;
+ }
+ else
+ _M_insert_aux(iterator(__position));
+ return begin() + __n;
+ }
+#ifdef __STL_MEMBER_TEMPLATES
+ // Check whether it's an integral type. If so, it's not an iterator.
+ template <class _InputIterator>
+ void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
+ typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
+ _M_insert_dispatch(__pos, __first, __last, _Integral());
+ }
+
+ template <class _Integer>
+ void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
+ __true_type)
+ { _M_fill_insert(__pos, (size_type) __n, (_Tp) __val); }
+
+ template <class _InputIterator>
+ void _M_insert_dispatch(iterator __pos,
+ _InputIterator __first, _InputIterator __last,
+ __false_type) {
+ _M_range_insert(__pos, __first, __last, __ITERATOR_CATEGORY(__first));
+ }
+#else /* __STL_MEMBER_TEMPLATES */
+ void insert(iterator __position,
+ const_iterator __first, const_iterator __last);
+#endif /* __STL_MEMBER_TEMPLATES */
+
+ void insert (iterator __pos, size_type __n, const _Tp& __x)
+ { _M_fill_insert(__pos, __n, __x); }
+
+ void _M_fill_insert (iterator __pos, size_type __n, const _Tp& __x);
+
+ void pop_back() {
+ --_M_finish;
+ destroy(_M_finish);
+ }
+ iterator erase(iterator __position) {
+ if (__position + 1 != end())
+ copy(__position + 1, end(), __position);
+ --_M_finish;
+ destroy(_M_finish);
+ return __position;
+ }
+ iterator erase(iterator __first, iterator __last) {
+ iterator __i(copy(__last, end(), __first));
+ destroy(__i, end());
+ _M_finish = _M_finish - (__last - __first);
+ return __first;
+ }
+
+ void resize(size_type __new_size, const _Tp& __x) {
+ if (__new_size < size())
+ erase(begin() + __new_size, end());
+ else
+ insert(end(), __new_size - size(), __x);
+ }
+ void resize(size_type __new_size) { resize(__new_size, _Tp()); }
+ void clear() { erase(begin(), end()); }
+
+protected:
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _ForwardIterator>
+ pointer _M_allocate_and_copy(size_type __n, _ForwardIterator __first,
+ _ForwardIterator __last)
+{
+ pointer __result = _M_allocate(__n);
+ __STL_TRY {
+ uninitialized_copy(__first, __last, __result);
+ return __result;
+ }
+ __STL_UNWIND(_M_deallocate(__result, __n));
+ }
+#else /* __STL_MEMBER_TEMPLATES */
+ pointer _M_allocate_and_copy(size_type __n, const_iterator __first,
+ const_iterator __last)
+ {
+ iterator __result(_M_allocate(__n));
+ __STL_TRY {
+ uninitialized_copy(__first, __last, __result);
+ return __result;
+ }
+ __STL_UNWIND(_M_deallocate(__result, __n));
+ }
+#endif /* __STL_MEMBER_TEMPLATES */
+
+
+#ifdef __STL_MEMBER_TEMPLATES
+ template <class _InputIterator>
+ void _M_range_initialize(_InputIterator __first,
+ _InputIterator __last, input_iterator_tag)
+ {
+ for ( ; __first != __last; ++__first)
+ push_back(*__first);
+ }
+
+ // This function is only called by the constructor.
+ template <class _ForwardIterator>
+ void _M_range_initialize(_ForwardIterator __first,
+ _ForwardIterator __last, forward_iterator_tag)
+ {
+ size_type __n = 0;
+ distance(__first, __last, __n);
+ _M_start = _M_allocate(__n);
+ _M_end_of_storage = _M_start + __n;
+ _M_finish = uninitialized_copy(__first, __last, _M_start);
+ }
+
+ template <class _InputIterator>
+ void _M_range_insert(iterator __pos,
+ _InputIterator __first, _InputIterator __last,
+ input_iterator_tag);
+
+ template <class _ForwardIterator>
+ void _M_range_insert(iterator __pos,
+ _ForwardIterator __first, _ForwardIterator __last,
+ forward_iterator_tag);
+
+#endif /* __STL_MEMBER_TEMPLATES */
+};
+
+template <class _Tp, class _Alloc>
+inline bool
+operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
+{
+ return __x.size() == __y.size() &&
+ equal(__x.begin(), __x.end(), __y.begin());
+}
+
+template <class _Tp, class _Alloc>
+inline bool
+operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
+{
+ return lexicographical_compare(__x.begin(), __x.end(),
+ __y.begin(), __y.end());
+}
+
+#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
+
+template <class _Tp, class _Alloc>
+inline void swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y)
+{
+ __x.swap(__y);
+}
+
+template <class _Tp, class _Alloc>
+inline bool
+operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) {
+ return !(__x == __y);
+}
+
+template <class _Tp, class _Alloc>
+inline bool
+operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) {
+ return __y < __x;
+}
+
+template <class _Tp, class _Alloc>
+inline bool
+operator<=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) {
+ return !(__y < __x);
+}
+
+template <class _Tp, class _Alloc>
+inline bool
+operator>=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) {
+ return !(__x < __y);
+}
+
+#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
+
+template <class _Tp, class _Alloc>
+vector<_Tp,_Alloc>&
+vector<_Tp,_Alloc>::operator=(const vector<_Tp, _Alloc>& __x)
+{
+ if (&__x != this) {
+ const size_type __xlen = __x.size();
+ if (__xlen > capacity()) {
+ pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(), __x.end());
+ destroy(_M_start, _M_finish);
+ _M_deallocate(_M_start, _M_end_of_storage - _M_start);
+ _M_start = __tmp;
+ _M_end_of_storage = _M_start + __xlen;
+ }
+ else if (size() >= __xlen) {
+ iterator __i(copy(__x.begin(), __x.end(), begin()));
+ destroy(__i, end());
+ }
+ else {
+ copy(__x.begin(), __x.begin() + size(), _M_start);
+ uninitialized_copy(__x.begin() + size(), __x.end(), _M_finish);
+ }
+ _M_finish = _M_start + __xlen;
+ }
+ return *this;
+}
+
+template <class _Tp, class _Alloc>
+void vector<_Tp, _Alloc>::_M_fill_assign(size_t __n, const value_type& __val)
+{
+ if (__n > capacity()) {
+ vector<_Tp, _Alloc> __tmp(__n, __val, get_allocator());
+ __tmp.swap(*this);
+ }
+ else if (__n > size()) {
+ fill(begin(), end(), __val);
+ _M_finish = uninitialized_fill_n(_M_finish, __n - size(), __val);
+ }
+ else
+ erase(fill_n(begin(), __n, __val), end());
+}
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+template <class _Tp, class _Alloc> template <class _InputIter>
+void vector<_Tp, _Alloc>::_M_assign_aux(_InputIter __first, _InputIter __last,
+ input_iterator_tag) {
+ iterator __cur(begin());
+ for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
+ *__cur = *__first;
+ if (__first == __last)
+ erase(__cur, end());
+ else
+ insert(end(), __first, __last);
+}
+
+template <class _Tp, class _Alloc> template <class _ForwardIter>
+void
+vector<_Tp, _Alloc>::_M_assign_aux(_ForwardIter __first, _ForwardIter __last,
+ forward_iterator_tag) {
+ size_type __len = 0;
+ distance(__first, __last, __len);
+
+ if (__len > capacity()) {
+ pointer __tmp(_M_allocate_and_copy(__len, __first, __last));
+ destroy(_M_start, _M_finish);
+ _M_deallocate(_M_start, _M_end_of_storage - _M_start);
+ _M_start = __tmp;
+ _M_end_of_storage = _M_finish = _M_start + __len;
+ }
+ else if (size() >= __len) {
+ iterator __new_finish(copy(__first, __last, _M_start));
+ destroy(__new_finish, end());
+ _M_finish = __new_finish.base();
+ }
+ else {
+ _ForwardIter __mid = __first;
+ advance(__mid, size());
+ copy(__first, __mid, _M_start);
+ _M_finish = uninitialized_copy(__mid, __last, _M_finish);
+ }
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+template <class _Tp, class _Alloc>
+void
+vector<_Tp, _Alloc>::_M_insert_aux(iterator __position, const _Tp& __x)
+{
+ if (_M_finish != _M_end_of_storage) {
+ construct(_M_finish, *(_M_finish - 1));
+ ++_M_finish;
+ _Tp __x_copy = __x;
+ copy_backward(__position, iterator(_M_finish - 2), iterator(_M_finish- 1));
+ *__position = __x_copy;
+ }
+ else {
+ const size_type __old_size = size();
+ const size_type __len = __old_size != 0 ? 2 * __old_size : 1;
+ iterator __new_start(_M_allocate(__len));
+ iterator __new_finish(__new_start);
+ __STL_TRY {
+ __new_finish = uninitialized_copy(iterator(_M_start), __position,
+ __new_start);
+ construct(__new_finish.base(), __x);
+ ++__new_finish;
+ __new_finish = uninitialized_copy(__position, iterator(_M_finish),
+ __new_finish);
+ }
+ __STL_UNWIND((destroy(__new_start,__new_finish),
+ _M_deallocate(__new_start.base(),__len)));
+ destroy(begin(), end());
+ _M_deallocate(_M_start, _M_end_of_storage - _M_start);
+ _M_start = __new_start.base();
+ _M_finish = __new_finish.base();
+ _M_end_of_storage = __new_start.base() + __len;
+ }
+}
+
+template <class _Tp, class _Alloc>
+void
+vector<_Tp, _Alloc>::_M_insert_aux(iterator __position)
+{
+ if (_M_finish != _M_end_of_storage) {
+ construct(_M_finish, *(_M_finish - 1));
+ ++_M_finish;
+ copy_backward(__position, iterator(_M_finish - 2),
+ iterator(_M_finish - 1));
+ *__position = _Tp();
+ }
+ else {
+ const size_type __old_size = size();
+ const size_type __len = __old_size != 0 ? 2 * __old_size : 1;
+ pointer __new_start = _M_allocate(__len);
+ pointer __new_finish = __new_start;
+ __STL_TRY {
+ __new_finish = uninitialized_copy(iterator(_M_start), __position,
+ __new_start);
+ construct(__new_finish);
+ ++__new_finish;
+ __new_finish = uninitialized_copy(__position, iterator(_M_finish),
+ __new_finish);
+ }
+ __STL_UNWIND((destroy(__new_start,__new_finish),
+ _M_deallocate(__new_start,__len)));
+ destroy(begin(), end());
+ _M_deallocate(_M_start, _M_end_of_storage - _M_start);
+ _M_start = __new_start;
+ _M_finish = __new_finish;
+ _M_end_of_storage = __new_start + __len;
+ }
+}
+
+template <class _Tp, class _Alloc>
+void vector<_Tp, _Alloc>::_M_fill_insert(iterator __position, size_type __n,
+ const _Tp& __x)
+{
+ if (__n != 0) {
+ if (size_type(_M_end_of_storage - _M_finish) >= __n) {
+ _Tp __x_copy = __x;
+ const size_type __elems_after = end() - __position;
+ iterator __old_finish(_M_finish);
+ if (__elems_after > __n) {
+ uninitialized_copy(_M_finish - __n, _M_finish, _M_finish);
+ _M_finish += __n;
+ copy_backward(__position, __old_finish - __n, __old_finish);
+ fill(__position, __position + __n, __x_copy);
+ }
+ else {
+ uninitialized_fill_n(_M_finish, __n - __elems_after, __x_copy);
+ _M_finish += __n - __elems_after;
+ uninitialized_copy(__position, __old_finish, _M_finish);
+ _M_finish += __elems_after;
+ fill(__position, __old_finish, __x_copy);
+ }
+ }
+ else {
+ const size_type __old_size = size();
+ const size_type __len = __old_size + max(__old_size, __n);
+ iterator __new_start(_M_allocate(__len));
+ iterator __new_finish(__new_start);
+ __STL_TRY {
+ __new_finish = uninitialized_copy(begin(), __position, __new_start);
+ __new_finish = uninitialized_fill_n(__new_finish, __n, __x);
+ __new_finish
+ = uninitialized_copy(__position, end(), __new_finish);
+ }
+ __STL_UNWIND((destroy(__new_start,__new_finish),
+ _M_deallocate(__new_start.base(),__len)));
+ destroy(_M_start, _M_finish);
+ _M_deallocate(_M_start, _M_end_of_storage - _M_start);
+ _M_start = __new_start.base();
+ _M_finish = __new_finish.base();
+ _M_end_of_storage = __new_start.base() + __len;
+ }
+ }
+}
+
+#ifdef __STL_MEMBER_TEMPLATES
+
+template <class _Tp, class _Alloc> template <class _InputIterator>
+void
+vector<_Tp, _Alloc>::_M_range_insert(iterator __pos,
+ _InputIterator __first,
+ _InputIterator __last,
+ input_iterator_tag)
+{
+ for ( ; __first != __last; ++__first) {
+ __pos = insert(__pos, *__first);
+ ++__pos;
+ }
+}
+
+template <class _Tp, class _Alloc> template <class _ForwardIterator>
+void
+vector<_Tp, _Alloc>::_M_range_insert(iterator __position,
+ _ForwardIterator __first,
+ _ForwardIterator __last,
+ forward_iterator_tag)
+{
+ if (__first != __last) {
+ size_type __n = 0;
+ distance(__first, __last, __n);
+ if (size_type(_M_end_of_storage - _M_finish) >= __n) {
+ const size_type __elems_after = end() - __position;
+ iterator __old_finish(_M_finish);
+ if (__elems_after > __n) {
+ uninitialized_copy(_M_finish - __n, _M_finish, _M_finish);
+ _M_finish += __n;
+ copy_backward(__position, __old_finish - __n, __old_finish);
+ copy(__first, __last, __position);
+ }
+ else {
+ _ForwardIterator __mid = __first;
+ advance(__mid, __elems_after);
+ uninitialized_copy(__mid, __last, _M_finish);
+ _M_finish += __n - __elems_after;
+ uninitialized_copy(__position, __old_finish, _M_finish);
+ _M_finish += __elems_after;
+ copy(__first, __mid, __position);
+ }
+ }
+ else {
+ const size_type __old_size = size();
+ const size_type __len = __old_size + max(__old_size, __n);
+ iterator __new_start(_M_allocate(__len));
+ iterator __new_finish(__new_start);
+ __STL_TRY {
+ __new_finish = uninitialized_copy(iterator(_M_start),
+ __position, __new_start);
+ __new_finish = uninitialized_copy(__first, __last, __new_finish);
+ __new_finish
+ = uninitialized_copy(__position, iterator(_M_finish), __new_finish);
+ }
+ __STL_UNWIND((destroy(__new_start,__new_finish),
+ _M_deallocate(__new_start.base(),__len)));
+ destroy(_M_start, _M_finish);
+ _M_deallocate(_M_start, _M_end_of_storage - _M_start);
+ _M_start = __new_start.base();
+ _M_finish = __new_finish.base();
+ _M_end_of_storage = __new_start.base() + __len;
+ }
+ }
+}
+
+#else /* __STL_MEMBER_TEMPLATES */
+
+template <class _Tp, class _Alloc>
+void
+vector<_Tp, _Alloc>::insert(iterator __position,
+ const_iterator __first,
+ const_iterator __last)
+{
+ if (__first != __last) {
+ size_type __n = 0;
+ distance(__first, __last, __n);
+ if (size_type(_M_end_of_storage - _M_finish) >= __n) {
+ const size_type __elems_after = _M_finish - __position;
+ iterator __old_finish(_M_finish);
+ if (__elems_after > __n) {
+ uninitialized_copy(_M_finish - __n, _M_finish, _M_finish);
+ _M_finish += __n;
+ copy_backward(__position, __old_finish - __n, __old_finish);
+ copy(__first, __last, __position);
+ }
+ else {
+ uninitialized_copy(__first + __elems_after, __last, _M_finish);
+ _M_finish += __n - __elems_after;
+ uninitialized_copy(__position, __old_finish, _M_finish);
+ _M_finish += __elems_after;
+ copy(__first, __first + __elems_after, __position);
+ }
+ }
+ else {
+ const size_type __old_size = size();
+ const size_type __len = __old_size + max(__old_size, __n);
+ iterator __new_start(_M_allocate(__len));
+ iterator __new_finish(__new_start);
+ __STL_TRY {
+ __new_finish = uninitialized_copy(_M_start, __position, __new_start);
+ __new_finish = uninitialized_copy(__first, __last, __new_finish);
+ __new_finish
+ = uninitialized_copy(__position, _M_finish, __new_finish);
+ }
+ __STL_UNWIND((destroy(__new_start,__new_finish),
+ _M_deallocate(__new_start,__len)));
+ destroy(_M_start, _M_finish);
+ _M_deallocate(_M_start, _M_end_of_storage - _M_start);
+ _M_start = __new_start;
+ _M_finish = __new_finish;
+ _M_end_of_storage = __new_start + __len;
+ }
+ }
+}
+
+#endif /* __STL_MEMBER_TEMPLATES */
+
+#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
+#pragma reset woff 1174
+#pragma reset woff 1375
+#endif
+
+__STL_END_NAMESPACE
+
+#endif /* __SGI_STL_INTERNAL_VECTOR_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/streambuf.tcc b/libstdc++-v3/bits/streambuf.tcc
new file mode 100644
index 0000000..f956ab2
--- /dev/null
+++ b/libstdc++-v3/bits/streambuf.tcc
@@ -0,0 +1,259 @@
+// Stream buffer classes -*- C++ -*-
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 27.5 Stream buffers
+//
+
+#ifndef _CPP_BITS_STREAMBUF_TCC
+#define _CPP_BITS_STREAMBUF_TCC 1
+
+namespace std {
+
+ template<typename _CharT, typename _Traits>
+ basic_streambuf<_CharT, _Traits>::int_type
+ basic_streambuf<_CharT, _Traits>::
+ sbumpc()
+ {
+ int_type __retval;
+ if (_M_in_cur && _M_in_cur < _M_in_end)
+ {
+ char_type __c = *gptr();
+ ++_M_in_cur;
+ if (_M_buf_unified && _M_mode & ios_base::out)
+ ++_M_out_cur;
+ __retval = traits_type::to_int_type(__c);
+ }
+ else
+ __retval = this->uflow();
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_streambuf<_CharT, _Traits>::int_type
+ basic_streambuf<_CharT, _Traits>::
+ sputbackc(char_type __c)
+ {
+ int_type __retval;
+ bool __testpos = _M_in_cur && _M_in_beg < _M_in_cur;
+ bool __testne = _M_in_cur && !traits_type::eq(__c, this->gptr()[-1]);
+ if (!__testpos || __testne)
+ __retval = pbackfail(traits_type::to_int_type(__c));
+ else
+ {
+ --_M_in_cur;
+ if (_M_buf_unified && _M_mode & ios_base::out)
+ --_M_out_cur;
+ __retval = traits_type::to_int_type(*this->gptr());
+ }
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ basic_streambuf<_CharT, _Traits>::int_type
+ basic_streambuf<_CharT, _Traits>::
+ sungetc()
+ {
+ int_type __retval;
+ if (_M_in_cur && _M_in_beg < _M_in_cur)
+ {
+ --_M_in_cur;
+ if (_M_buf_unified && _M_mode & ios_base::out)
+ --_M_out_cur;
+ __retval = traits_type::to_int_type(*_M_in_cur);
+ }
+ else
+ __retval = this->pbackfail();
+ return __retval;
+ }
+
+ // Don't test against _M_buf + _M_buf_size, because _M_buf reflects
+ // allocated space, and on certain (rare but entirely legal)
+ // situations, there will be no allocated space yet the internal
+ // buffers will still be valid. (This happens if setp is used to set
+ // the internal buffer to say some externally-allocated sequence.)
+ template<typename _CharT, typename _Traits>
+ basic_streambuf<_CharT, _Traits>::int_type
+ basic_streambuf<_CharT, _Traits>::
+ sputc(char_type __c)
+ {
+ int_type __retval;
+
+ if (_M_out_cur && _M_out_cur < _M_out_beg + _M_buf_size)
+ {
+ *_M_out_cur = __c;
+ _M_buf_bump(1);
+ __retval = traits_type::to_int_type(__c);
+ }
+ else
+ __retval = this->overflow(traits_type::to_int_type(__c));
+ return __retval;
+ }
+
+ template<typename _CharT, typename _Traits>
+ streamsize
+ basic_streambuf<_CharT, _Traits>::
+ xsgetn(char_type* __s, streamsize __n)
+ {
+ bool __testout = _M_mode & ios_base::out;
+ streamsize __retval = 0;
+
+ if (__n)
+ {
+ while (__retval < __n)
+ {
+ bool __testget = _M_in_cur < _M_in_end;
+ if (__testget)
+ {
+ size_t __len;
+ if (_M_in_cur + __n - __retval <= _M_in_end)
+ __len = __n - __retval;
+ else
+ __len = _M_in_end - _M_in_cur;
+ traits_type::copy(__s, _M_in_cur, __len);
+ __retval += __len;
+ __s += __len;
+ _M_in_cur += __len;
+ if (_M_buf_unified && __testout)
+ _M_out_cur += __len;
+ }
+
+ if (__retval != __n)
+ {
+ if (this->uflow() != traits_type::eof())
+ ++__retval;
+ else
+ break;
+ }
+ }
+ }
+ return __retval;
+ }
+
+ // Don't test against _M_buf + _M_buf_size, because _M_buf reflects
+ // allocated space, and on certain (rare but entirely legal)
+ // situations, there will be no allocated space yet the internal
+ // buffers will still be valid. (This happens if setp is used to set
+ // the internal buffer to say some externally-allocated sequence.)
+ template<typename _CharT, typename _Traits>
+ streamsize
+ basic_streambuf<_CharT, _Traits>::
+ xsputn(const char_type* __s, streamsize __n)
+ {
+ streamsize __retval = 0;
+
+ if (__n)
+ {
+ while (__retval < __n)
+ {
+ bool __testput = _M_out_cur < _M_out_beg + _M_buf_size;
+ bool __testout = _M_mode & ios_base::out;
+ if (!(__testput && __testout))
+ {
+ char_type __c = *__s;
+ char_type __overfc = this->overflow(__c);
+ if (__c == __overfc)
+ {
+ ++__retval;
+ ++__s;
+ }
+ else
+ break;
+ }
+
+ if (__retval != __n)
+ {
+ size_t __len;
+ if (_M_out_cur + __n - __retval <= _M_out_beg + _M_buf_size)
+ __len = __n - __retval;
+ else
+ __len = _M_out_beg + _M_buf_size - _M_out_cur;
+ traits_type::copy(_M_out_cur, __s, __len);
+ __retval += __len;
+ __s += __len;
+ _M_buf_bump(__len);
+ }
+ }
+ }
+ return __retval;
+ }
+
+
+ // Conceivably, this could be used to implement buffer-to-buffer
+ // copies, if this was ever desired in an un-ambiguous way by the
+ // standard. If so, then checks for __ios being zero would be
+ // necessary.
+ template<typename _CharT, typename _Traits>
+ static streamsize
+ _S_copy_streambufs(basic_ios<_CharT, _Traits>& __ios,
+ basic_streambuf<_CharT, _Traits>* __sbin,
+ basic_streambuf<_CharT, _Traits>* __sbout)
+ {
+ typedef typename _Traits::int_type int_type;
+
+ streamsize __retval = 0;
+ streamsize __bufsize = __sbin->in_avail();
+ streamsize __xtrct;
+ bool __testout = __sbin->_M_mode & ios_base::out;
+ bool __testput = __sbout->_M_mode & ios_base::out;
+ try {
+ while (__testput && __bufsize != -1)
+ {
+ __xtrct = __sbout->sputn(__sbin->gptr(), __bufsize);
+ __retval += __xtrct;
+ __sbin->_M_in_cur += __xtrct;
+ if (__testout && __sbin->_M_buf_unified)
+ __sbin->_M_out_cur += __xtrct;
+ if (__xtrct == __bufsize)
+ {
+ int_type __c = __sbin->sgetc();
+ if (__c == _Traits::eof())
+ {
+ __ios.setstate(ios_base::eofbit);
+ break;
+ }
+ }
+ else
+ break;
+ }
+ }
+ catch(exception& __fail) {
+ if ((__ios.exceptions() & ios_base::failbit) != 0)
+ throw;
+ }
+ return __retval;
+ }
+
+} // namespace std
+
+#endif // _CPP_BITS_STREAMBUF_TCC
+
+
+
+
diff --git a/libstdc++-v3/bits/string.tcc b/libstdc++-v3/bits/string.tcc
new file mode 100644
index 0000000..7ad2b5d
--- /dev/null
+++ b/libstdc++-v3/bits/string.tcc
@@ -0,0 +1,858 @@
+// Components for manipulating sequences of characters -*- C++ -*-
+
+// Copyright (C) 2000, 1999, 1998, 1997 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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.
+
+//
+// ISO C++ 14882: 21 Strings library
+//
+
+// This file is included by <string>. It is not meant to be included
+// separately.
+
+// Written by Jason Merrill based upon the specification by Takanori Adachi
+// in ANSI X3J16/94-0013R2. Rewritten by Nathan Myers to ISO-14882.
+
+#ifndef _CPP_BITS_STRING_TCC
+#define _CPP_BITS_STRING_TCC 1
+
+namespace std
+{
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ _CharT
+ basic_string<_CharT, _Traits, _Alloc>::
+ _Rep::_S_terminal = _CharT();
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ _Rep::_S_max_size = (((npos - sizeof(_Rep))/sizeof(_CharT)) - 1) / 4;
+
+ // NB: This is the special case for Input Iterators, used in
+ // istreambuf_iterators, etc.
+ // Input Iterators have a cost structure very different from
+ // pointers, calling for a different coding style.
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ template<typename _InIter>
+ _CharT*
+ basic_string<_CharT, _Traits, _Alloc>::
+ _S_construct(_InIter __beg, _InIter __end, const _Alloc& __a,
+ input_iterator_tag)
+ {
+ if (__beg == __end && __a == _Alloc())
+ return _S_empty_rep()._M_refcopy();
+ // Avoid reallocation for common case.
+ _CharT __buf[100];
+ size_type __i = 0;
+ while (__beg != __end && __i < sizeof(__buf) / sizeof(_CharT))
+ {
+ __buf[__i++] = *__beg;
+ ++__beg;
+ }
+ _Rep* __r = _Rep::_S_create(__i, __a);
+ traits_type::copy(__r->_M_refdata(), __buf, __i);
+ __r->_M_length = __i;
+ try {
+ // NB: this loop looks precisely this way because
+ // it avoids comparing __beg != __end any more
+ // than strictly necessary; != might be expensive!
+ for (;;)
+ {
+ _CharT* __p = __r->_M_refdata() + __r->_M_length;
+ _CharT* __last = __r->_M_refdata() + __r->_M_capacity;
+ for (;;)
+ {
+ if (__beg == __end)
+ {
+ __r->_M_length = __p - __r->_M_refdata();
+ *__p = _Rep::_S_terminal; // grrr.
+ return __r->_M_refdata();
+ }
+ if (__p == __last)
+ break;
+ *__p++ = *__beg;
+ ++__beg;
+ }
+ // Allocate more space.
+ size_type __len = __p - __r->_M_refdata();
+ _Rep* __another = _Rep::_S_create(__len + 1, __a);
+ traits_type::copy(__another->_M_refdata(),
+ __r->_M_refdata(), __len);
+ __r->_M_destroy(__a);
+ __r = __another;
+ __r->_M_length = __len;
+ }
+ }
+ catch (...) {
+ __r->_M_destroy(__a);
+ throw;
+ }
+ return 0;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ template <class _InIter>
+ _CharT*
+ basic_string<_CharT,_Traits,_Alloc>::
+ _S_construct(_InIter __beg, _InIter __end, const _Alloc& __a,
+ forward_iterator_tag)
+ {
+ size_type __dnew = static_cast<size_type>(distance(__beg, __end));
+
+ if (__beg == __end && __a == _Alloc())
+ return _S_empty_rep()._M_refcopy();
+
+ // Check for out_of_range and length_error exceptions.
+ _Rep* __r = _Rep::_S_create(__dnew, __a);
+ try {
+ _S_copy_chars(__r->_M_refdata(), __beg, __end);
+ }
+ catch (...) {
+ __r->_M_destroy(__a);
+ throw;
+ }
+ __r->_M_length = __dnew;
+
+ __r->_M_refdata()[__dnew] = _Rep::_S_terminal; // grrr.
+ return __r->_M_refdata();
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ _CharT*
+ basic_string<_CharT,_Traits, _Alloc>::
+ _S_construct(size_type __n, _CharT __c, const _Alloc& __a)
+ {
+ if (__n == 0 && __a == _Alloc())
+ return _S_empty_rep()._M_refcopy();
+
+ // Check for out_of_range and length_error exceptions.
+ _Rep* __r = _Rep::_S_create(__n, __a);
+ try {
+ if (__n)
+ traits_type::assign(__r->_M_refdata(), __n, __c);
+ }
+ catch (...) {
+ __r->_M_destroy(__a);
+ throw;
+ }
+ __r->_M_length = __n;
+ __r->_M_refdata()[__n] = _Rep::_S_terminal; // grrr
+ return __r->_M_refdata();
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::
+ basic_string(const basic_string& __str)
+ : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(), __str.get_allocator()),
+ __str.get_allocator())
+ { }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::
+ basic_string(const _Alloc& __a)
+ : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
+ { }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::
+ basic_string(const basic_string& __str, size_type __pos, size_type __n)
+ : _M_dataplus(_S_construct(__str._M_check(__pos),
+ __str._M_fold(__pos, __n), _Alloc()), _Alloc())
+ { }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::
+ basic_string(const basic_string& __str, size_type __pos,
+ size_type __n, const _Alloc& __a)
+ : _M_dataplus(_S_construct(__str._M_check(__pos),
+ __str._M_fold(__pos, __n), __a), __a)
+ { }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::
+ basic_string(const _CharT* __s, size_type __n, const _Alloc& __a)
+ : _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
+ { }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::
+ basic_string(const _CharT* __s, const _Alloc& __a)
+ : _M_dataplus(_S_construct(__s, __s + traits_type::length(__s), __a), __a)
+ { }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::
+ basic_string(size_type __n, _CharT __c, const _Alloc& __a)
+ : _M_dataplus(_S_construct(__n, __c, __a), __a)
+ { }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ template<typename _InputIter>
+ basic_string<_CharT, _Traits, _Alloc>::
+ basic_string(_InputIter __beg, _InputIter __end, const _Alloc& __a)
+ : _M_dataplus(_S_construct(__beg, __end, __a), __a)
+ { }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>&
+ basic_string<_CharT, _Traits, _Alloc>::assign(const basic_string& __str)
+ {
+ if (_M_rep() != __str._M_rep())
+ {
+ // XXX MT
+ allocator_type __a = this->get_allocator();
+ _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.get_allocator());
+ _M_rep()->_M_dispose(__a);
+ _M_data(__tmp);
+ }
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ void
+ basic_string<_CharT, _Traits, _Alloc>::_Rep::
+ _M_destroy(const _Alloc& __a) throw ()
+ {
+ size_type __size = sizeof(_Rep) + (_M_capacity + 1) * sizeof(_CharT);
+ _Raw_bytes_alloc(__a).deallocate(reinterpret_cast<char*>(this), __size);
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ void
+ basic_string<_CharT, _Traits, _Alloc>::_M_leak_hard()
+ {
+ if (_M_rep()->_M_is_shared())
+ _M_mutate(0, 0, 0);
+ _M_rep()->_M_set_leaked();
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ void
+ basic_string<_CharT, _Traits, _Alloc>::
+ _M_mutate(size_type __pos, size_type __len1, size_type __len2)
+ {
+ size_type __old_size = this->size();
+ const size_type __new_size = __old_size + __len2 - __len1;
+ const _CharT* __src = _M_data() + __pos + __len1;
+ const size_type __how_much = __old_size - __pos - __len1;
+
+ if (_M_rep()->_M_is_shared() || __new_size > capacity())
+ {
+ // Must reallocate.
+ allocator_type __a = get_allocator();
+ _Rep* __r = _Rep::_S_create(__new_size, __a);
+ try {
+ if (__pos)
+ traits_type::copy(__r->_M_refdata(), _M_data(), __pos);
+ if (__how_much)
+ traits_type::copy(__r->_M_refdata() + __pos + __len2,
+ __src, __how_much);
+ }
+ catch (...) {
+ __r->_M_dispose(get_allocator());
+ throw;
+ }
+ _M_rep()->_M_dispose(__a);
+ _M_data(__r->_M_refdata());
+ }
+ else if (__how_much)
+ {
+ // Work in-place
+ traits_type::move(_M_data() + __pos + __len2, __src, __how_much);
+ }
+ _M_rep()->_M_set_sharable();
+ _M_rep()->_M_length = __new_size;
+ _M_data()[__new_size] = _Rep::_S_terminal; // grrr. (per 21.3.4)
+ // You cannot leave those LWG people alone for a second.
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ void
+ basic_string<_CharT, _Traits, _Alloc>::reserve(size_type __res)
+ {
+ if (__res > this->capacity() || _M_rep()->_M_is_shared())
+ {
+ __LENGTHERROR(__res > this->max_size());
+ allocator_type __a = get_allocator();
+ _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->size());
+ _M_rep()->_M_dispose(__a);
+ _M_data(__tmp);
+ }
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ void basic_string<_CharT, _Traits, _Alloc>::swap(basic_string& __s)
+ {
+ if (_M_rep()->_M_is_leaked())
+ _M_rep()->_M_set_sharable();
+ if (__s._M_rep()->_M_is_leaked())
+ __s._M_rep()->_M_set_sharable();
+ if (this->get_allocator() == __s.get_allocator())
+ {
+ _CharT* __tmp = _M_data();
+ _M_data(__s._M_data());
+ __s._M_data(__tmp);
+ }
+ // The code below can usually be optimized away.
+ else
+ {
+ basic_string __tmp1(_M_ibegin(), _M_iend(), __s.get_allocator());
+ basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
+ this->get_allocator());
+ *this = __tmp2;
+ __s = __tmp1;
+ }
+ }
+
+#ifdef _GLIBCPP_ALLOC_CONTROL
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ bool (*basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_excess_slop)
+ (size_t, size_t) =
+ basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_default_excess;
+#endif
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::_Rep*
+ basic_string<_CharT, _Traits, _Alloc>::_Rep::
+ _S_create(size_t __capacity, const _Alloc& __alloc)
+ {
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ // 83. String::npos vs. string::max_size()
+ typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
+ __LENGTHERROR(__capacity > _S_max_size);
+#else
+ __LENGTHERROR(__capacity == npos);
+#endif
+
+ // NB: Need an array of char_type[__capacity], plus a
+ // terminating null char_type() element, plus enough for the
+ // _Rep data structure. Whew. Seemingly so needy, yet so elemental.
+ size_t __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
+ // NB: Might throw, but no worries about a leak, mate: _Rep()
+ // does not throw.
+ void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
+ _Rep *__p = new (__place) _Rep;
+ __p->_M_capacity = __capacity;
+ __p->_M_set_sharable(); // one reference
+ __p->_M_length = 0;
+ return __p;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ _CharT*
+ basic_string<_CharT, _Traits, _Alloc>::_Rep::
+ _M_clone(const _Alloc& __alloc, size_type __res)
+ {
+ _Rep* __r = _Rep::_S_create(_M_length + __res, __alloc);
+ if (_M_length)
+ {
+ try {
+ traits_type::copy(__r->_M_refdata(), _M_refdata(), _M_length);
+ }
+ catch (...) {
+ __r->_M_destroy(__alloc);
+ throw;
+ }
+ }
+ __r->_M_length = _M_length;
+ return __r->_M_refdata();
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ inline bool
+#ifdef _GLIBCPP_ALLOC_CONTROL
+ basic_string<_CharT, _Traits, _Alloc>::_Rep::
+ _S_default_excess(size_t __s, size_t __r)
+#else
+ basic_string<_CharT, _Traits, _Alloc>::_Rep::
+ _S_excess_slop(size_t __s, size_t __r)
+#endif
+ {
+ return 2 * (__s <= 16 ? 16 : __s) < __r;
+ }
+
+ // Linker sets _S_empty_rep_storage to all 0s (one reference, empty string)
+ // at static init time (before static ctors are run).
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ typename _Alloc::size_type
+ basic_string<_CharT, _Traits, _Alloc>::_S_empty_rep_storage[
+ (sizeof(_Rep) + sizeof(_CharT) + sizeof(size_type) - 1)/sizeof(size_type)];
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ void
+ basic_string<_CharT, _Traits, _Alloc>::resize(size_type __n, _CharT __c)
+ {
+ __LENGTHERROR(__n > max_size());
+ size_type __size = this->size();
+ if (__size < __n)
+ this->append(__n - __size, __c);
+ else if (__n < __size)
+ this->erase(__n);
+ // else nothing (in particular, avoid calling _M_mutate() unnecessarily.)
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ template<typename _InputIter>
+ basic_string<_CharT, _Traits, _Alloc>&
+ basic_string<_CharT, _Traits, _Alloc>::
+ _M_replace(iterator __i1, iterator __i2, _InputIter __j1,
+ _InputIter __j2, input_iterator_tag)
+ {
+ basic_string __s(__j1, __j2);
+ return this->replace(__i1, __i2, __s._M_ibegin(), __s._M_iend());
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ template<typename _ForwardIter>
+ basic_string<_CharT, _Traits, _Alloc>&
+ basic_string<_CharT, _Traits, _Alloc>::
+ _M_replace(iterator __i1, iterator __i2, _ForwardIter __j1,
+ _ForwardIter __j2, forward_iterator_tag)
+ {
+ size_type __dold = __i2 - __i1;
+ size_type __dmax = this->max_size();
+ size_type __dnew = static_cast<size_type>(distance(__j1, __j2));
+
+ __LENGTHERROR(__dmax <= __dnew);
+ size_type __off = __i1 - _M_ibegin();
+ _M_mutate(__off, __dold, __dnew);
+ // Invalidated __i1, __i2
+ if (__dnew)
+ _S_copy_chars(_M_data() + __off, __j1, __j2);
+
+ return *this;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>&
+ basic_string<_CharT, _Traits, _Alloc>::
+ replace(size_type __pos1, size_type __n1, const basic_string& __str,
+ size_type __pos2, size_type __n2)
+ {
+ return this->replace(_M_check(__pos1), _M_fold(__pos1, __n1),
+ __str._M_check(__pos2),
+ __str._M_fold(__pos2, __n2));
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT,_Traits,_Alloc>&
+ basic_string<_CharT,_Traits,_Alloc>::
+ append(const basic_string& __str)
+ {
+ // Iff appending itself, string needs to pre-reserve the
+ // correct size so that _M_mutate does not clobber the
+ // iterators formed here.
+ size_type __size = __str.size();
+ size_type __len = __size + this->size();
+ if (__len > this->capacity())
+ this->reserve(__len);
+ return this->replace(_M_iend(), _M_iend(), __str._M_ibegin(),
+ __str._M_iend());
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT,_Traits,_Alloc>&
+ basic_string<_CharT,_Traits,_Alloc>::
+ append(const basic_string& __str, size_type __pos, size_type __n)
+ {
+ // Iff appending itself, string needs to pre-reserve the
+ // correct size so that _M_mutate does not clobber the
+ // iterators formed here.
+ size_type __len = min(__str.size() - __pos, __n) + this->size();
+ if (__len > this->capacity())
+ this->reserve(__len);
+ return this->replace(_M_iend(), _M_iend(), __str._M_check(__pos),
+ __str._M_fold(__pos, __n));
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT,_Traits,_Alloc>&
+ basic_string<_CharT,_Traits,_Alloc>::
+ append(const _CharT* __s, size_type __n)
+ {
+ size_type __len = __n + this->size();
+ if (__len > this->capacity())
+ this->reserve(__len);
+ return this->replace(_M_iend(), _M_iend(), __s, __s + __n);
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT,_Traits,_Alloc>&
+ basic_string<_CharT,_Traits,_Alloc>::
+ append(size_type __n, _CharT __c)
+ {
+ size_type __len = __n + this->size();
+ if (__len > this->capacity())
+ this->reserve(__len);
+ return this->replace(_M_iend(), _M_iend(), __n, __c);
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT,_Traits,_Alloc>
+ operator+(const _CharT* __lhs,
+ const basic_string<_CharT,_Traits,_Alloc>& __rhs)
+ {
+ typedef basic_string<_CharT,_Traits,_Alloc> __string_type;
+ __string_type::size_type __len = _Traits::length(__lhs);
+ __string_type __str;
+ __str.reserve(__len + __rhs.size());
+ __str.append(__lhs, __lhs + __len);
+ __str.append(__rhs);
+ return __str;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT,_Traits,_Alloc>
+ operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
+ {
+ typedef basic_string<_CharT,_Traits,_Alloc> __string_type;
+ __string_type __str;
+ __string_type::size_type __len = __rhs.size();
+ __str.reserve(__len + 1);
+ __str.append(__string_type::size_type(1), __lhs);
+ __str.append(__rhs);
+ return __str;
+ }
+
+
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>&
+ basic_string<_CharT, _Traits, _Alloc>::
+ replace(iterator __i1, iterator __i2, size_type __n2, _CharT __c)
+ {
+ size_type __n1 = __i2 - __i1;
+ size_type __off1 = __i1 - _M_ibegin();
+ __LENGTHERROR(max_size() - (this->size() - __n1) <= __n2);
+ _M_mutate (__off1, __n1, __n2);
+ // Invalidated __i1, __i2
+ if (__n2)
+ traits_type::assign(_M_data() + __off1, __n2, __c);
+ return *this;
+ }
+
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ copy(_CharT* __s, size_type __n, size_type __pos) const
+ {
+ __OUTOFRANGE(__pos > this->size());
+
+ if (__n > this->size() - __pos)
+ __n = this->size() - __pos;
+
+ traits_type::copy(__s, _M_data() + __pos, __n);
+ // 21.3.5.7 par 3: do not append null. (good.)
+ return __n;
+ }
+
+ // String operations
+ // NB: This is specialized for the standard char_traits<char>
+ // specialization to use the same optimizations as strchr.
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ const _CharT*
+ basic_string<_CharT, _Traits, _Alloc>::
+ _S_find(const _CharT* __beg, const _CharT* __end, _CharT __c)
+ {
+ return find_if(__beg, __end, _Char_traits_match<_CharT, _Traits>(__c));
+ }
+
+ // Specialization for char, definitions in src/string-inst.cc.
+ template<>
+ const char*
+ string::_S_find(const char* __beg, const char* __end, char __c);
+
+ // Specialization for wchar_t.
+#ifdef _GLIBCPP_USE_WCHAR_T
+ template<>
+ const wchar_t*
+ wstring::_S_find(const wchar_t* __beg, const wchar_t* __end, wchar_t __c);
+#endif
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ find(const _CharT* __s, size_type __pos, size_type __n) const
+ {
+ size_t __xpos = __pos;
+ const _CharT* __data = _M_data();
+ for (; __xpos + __n <= this->size(); ++__xpos)
+ if (traits_type::eq(__data[__xpos], *__s)
+ && traits_type::compare(__data + __xpos, __s, __n) == 0)
+ return __xpos;
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ find(_CharT __c, size_type __pos) const
+ {
+ size_type __size = this->size();
+ size_type __retval = npos;
+ if (__pos < __size)
+ {
+ const _CharT* __data = _M_data();
+ const _CharT* __end = __data + __size;
+ const _CharT* __p = _S_find(__data + __pos, __end, __c);
+ if (__p != __end)
+ __retval = __p - __data;
+ }
+ return __retval;
+ }
+
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ rfind(const _CharT* __s, size_type __pos, size_type __n) const
+ {
+ size_type __size = this->size();
+ if (__n <= __size)
+ {
+ size_t __xpos = __size - __n;
+ if (__xpos > __pos)
+ __xpos = __pos;
+
+ for (++__xpos; __xpos-- > 0; )
+ if (traits_type::eq(_M_data()[__xpos], *__s)
+ && traits_type::compare(_M_data() + __xpos, __s, __n) == 0)
+ return __xpos;
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ rfind(_CharT __c, size_type __pos) const
+ {
+ size_type __size = this->size();
+ if (__size)
+ {
+ size_t __xpos = __size - 1;
+ if (__xpos > __pos)
+ __xpos = __pos;
+
+ for (++__xpos; __xpos-- > 0; )
+ if (traits_type::eq(_M_data()[__xpos], __c))
+ return __xpos;
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
+ {
+ const _CharT* __end = __s + __n;
+ for (; __n && __pos < this->size(); ++__pos)
+ {
+ const _CharT* __p = _S_find(__s, __end, _M_data()[__pos]);
+ if (__p != __end)
+ return __pos;
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
+ {
+ size_type __size = this->size();
+ if (__size && __n)
+ {
+ if (--__size > __pos)
+ __size = __pos;
+ do
+ {
+ const _CharT* __p = _S_find(__s, __s + __n, _M_data()[__size]);
+ if (__p != __s + __n)
+ return __size;
+ }
+ while (__size-- != 0);
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
+ {
+ size_t __xpos = __pos;
+ for (; __n && __xpos < this->size(); ++__xpos)
+ if (_S_find(__s, __s + __n, _M_data()[__xpos]) == __s + __n)
+ return __xpos;
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ find_first_not_of(_CharT __c, size_type __pos) const
+ {
+ size_t __xpos = __pos;
+ for (; __xpos < size(); ++__xpos)
+ if (!traits_type::eq(_M_data()[__xpos], __c))
+ return __xpos;
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
+ {
+ size_type __size = this->size();
+ if (__size && __n)
+ {
+ if (--__size > __pos)
+ __size = __pos;
+ do
+ {
+ if (_S_find(__s, __s + __n, _M_data()[__size]) == __s + __n)
+ return __size;
+ }
+ while (__size--);
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ basic_string<_CharT, _Traits, _Alloc>::size_type
+ basic_string<_CharT, _Traits, _Alloc>::
+ find_last_not_of(_CharT __c, size_type __pos) const
+ {
+ size_type __size = this->size();
+ if (__size)
+ {
+ if (--__size > __pos)
+ __size = __pos;
+ do
+ {
+ if (!traits_type::eq(_M_data()[__size], __c))
+ return __size;
+ }
+ while (__size--);
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ int
+ basic_string<_CharT, _Traits, _Alloc>::
+ compare(size_type __pos, size_type __n, const basic_string& __str) const
+ {
+ size_type __size = this->size();
+ size_type __osize = __str.size();
+ __OUTOFRANGE(__pos > __size);
+
+ size_type __rsize= min(__size - __pos, __n);
+ size_type __len = min(__rsize, __osize);
+ int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
+ if (!__r)
+ __r = __rsize - __osize;
+ return __r;
+ }
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ int
+ basic_string<_CharT, _Traits, _Alloc>::
+ compare(size_type __pos1, size_type __n1, const basic_string& __str,
+ size_type __pos2, size_type __n2) const
+ {
+ size_type __size = this->size();
+ size_type __osize = __str.size();
+ __OUTOFRANGE(__pos1 > __size);
+ __OUTOFRANGE(__pos2 > __osize);
+
+ size_type __rsize = min(__size - __pos1, __n1);
+ size_type __rosize = min(__osize - __pos2, __n2);
+ size_type __len = min(__rsize, __rosize);
+ int __r = traits_type::compare(_M_data() + __pos1,
+ __str.data() + __pos2, __len);
+ if (!__r)
+ __r = __rsize - __rosize;
+ return __r;
+ }
+
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ int
+ basic_string<_CharT, _Traits, _Alloc>::
+ compare(const _CharT* __s) const
+ {
+ size_type __size = this->size();
+ int __r = traits_type::compare(_M_data(), __s, __size);
+ if (!__r)
+ __r = __size - traits_type::length(__s);
+ return __r;
+ }
+
+
+ template<typename _CharT, typename _Traits, typename _Alloc>
+ int
+ basic_string <_CharT,_Traits,_Alloc>::
+ compare(size_type __pos, size_type __n1, const _CharT* __s,
+ size_type __n2) const
+ {
+ size_type __size = this->size();
+ __OUTOFRANGE(__pos > __size);
+
+ size_type __osize = min(traits_type::length(__s), __n2);
+ size_type __rsize = min(__size - __pos, __n1);
+ size_type __len = min(__rsize, __osize);
+ int __r = traits_type::compare(_M_data() + __pos, __s, __len);
+ if (!__r)
+ __r = __rsize - __osize;
+ return __r;
+ }
+
+ template <class _CharT, class _Traits, class _Alloc>
+ void
+ _S_string_copy(const basic_string<_CharT, _Traits, _Alloc>& __str,
+ _CharT* __buf, typename _Alloc::size_type __bufsiz)
+ {
+ typedef typename _Alloc::size_type size_type;
+ size_type __strsize = __str.size();
+ size_type __bytes = min(__strsize, __bufsiz - 1);
+ _Traits::copy(__buf, __str.data(), __bytes);
+ __buf[__bytes] = _CharT();
+ }
+
+} // std::
+
+#endif /* _CPP_BITS_STRING_TCC */
+
+// Local Variables:
+// mode:c++
+// End:
diff --git a/libstdc++-v3/bits/type_traits.h b/libstdc++-v3/bits/type_traits.h
new file mode 100644
index 0000000..dbcaa2a
--- /dev/null
+++ b/libstdc++-v3/bits/type_traits.h
@@ -0,0 +1,387 @@
+/*
+ *
+ * Copyright (c) 1997
+ * Silicon Graphics Computer Systems, Inc.
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Silicon Graphics makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ */
+
+#ifndef _CPP_BITS_TYPE_TRAITS_H
+#define _CPP_BITS_TYPE_TRAITS_H 1
+
+#ifndef _CPP_BITS_STL_CONFIG_H
+#include <bits/stl_config.h>
+#endif
+
+/*
+This header file provides a framework for allowing compile time dispatch
+based on type attributes. This is useful when writing template code.
+For example, when making a copy of an array of an unknown type, it helps
+to know if the type has a trivial copy constructor or not, to help decide
+if a memcpy can be used.
+
+The class template __type_traits provides a series of typedefs each of
+which is either __true_type or __false_type. The argument to
+__type_traits can be any type. The typedefs within this template will
+attain their correct values by one of these means:
+ 1. The general instantiation contain conservative values which work
+ for all types.
+ 2. Specializations may be declared to make distinctions between types.
+ 3. Some compilers (such as the Silicon Graphics N32 and N64 compilers)
+ will automatically provide the appropriate specializations for all
+ types.
+
+EXAMPLE:
+
+//Copy an array of elements which have non-trivial copy constructors
+template <class _Tp> void
+ copy(_Tp* __source,_Tp* __destination,int __n,__false_type);
+//Copy an array of elements which have trivial copy constructors. Use memcpy.
+template <class _Tp> void
+ copy(_Tp* __source,_Tp* __destination,int __n,__true_type);
+
+//Copy an array of any type by using the most efficient copy mechanism
+template <class _Tp> inline void copy(_Tp* __source,_Tp* __destination,int __n) {
+ copy(__source,__destination,__n,
+ typename __type_traits<_Tp>::has_trivial_copy_constructor());
+}
+*/
+
+
+template <bool _Truth> struct _Bool {};
+typedef _Bool<true> __true_type;
+typedef _Bool<false> __false_type;
+
+template <class _Tp>
+struct __type_traits {
+ typedef __true_type this_dummy_member_must_be_first;
+ /* Do not remove this member. It informs a compiler which
+ automatically specializes __type_traits that this
+ __type_traits template is special. It just makes sure that
+ things work if an implementation is using a template
+ called __type_traits for something unrelated. */
+
+ /* The following restrictions should be observed for the sake of
+ compilers which automatically produce type specific specializations
+ of this class:
+ - You may reorder the members below if you wish
+ - You may remove any of the members below if you wish
+ - You must not rename members without making the corresponding
+ name change in the compiler
+ - Members you add will be treated like regular members unless
+ you add the appropriate support in the compiler. */
+
+
+ typedef __false_type has_trivial_default_constructor;
+ typedef __false_type has_trivial_copy_constructor;
+ typedef __false_type has_trivial_assignment_operator;
+ typedef __false_type has_trivial_destructor;
+ typedef __false_type is_POD_type;
+};
+
+
+
+// Provide some specializations. This is harmless for compilers that
+// have built-in __types_traits support, and essential for compilers
+// that don't.
+
+#ifndef __STL_NO_BOOL
+
+__STL_TEMPLATE_NULL struct __type_traits<bool> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+#endif /* __STL_NO_BOOL */
+
+__STL_TEMPLATE_NULL struct __type_traits<char> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<signed char> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<unsigned char> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+#ifdef __STL_HAS_WCHAR_T
+
+__STL_TEMPLATE_NULL struct __type_traits<wchar_t> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+#endif /* __STL_HAS_WCHAR_T */
+
+__STL_TEMPLATE_NULL struct __type_traits<short> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<unsigned short> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<int> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<unsigned int> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<long> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<unsigned long> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+#ifdef __STL_LONG_LONG
+
+__STL_TEMPLATE_NULL struct __type_traits<long long> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<unsigned long long> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+#endif /* __STL_LONG_LONG */
+
+__STL_TEMPLATE_NULL struct __type_traits<float> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<double> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<long double> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
+
+template <class _Tp>
+struct __type_traits<_Tp*> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+__STL_TEMPLATE_NULL struct __type_traits<char*> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<signed char*> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<unsigned char*> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<const char*> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<const signed char*> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+__STL_TEMPLATE_NULL struct __type_traits<const unsigned char*> {
+ typedef __true_type has_trivial_default_constructor;
+ typedef __true_type has_trivial_copy_constructor;
+ typedef __true_type has_trivial_assignment_operator;
+ typedef __true_type has_trivial_destructor;
+ typedef __true_type is_POD_type;
+};
+
+#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
+
+
+// The following could be written in terms of numeric_limits.
+// We're doing it separately to reduce the number of dependencies.
+
+template <class _Tp> struct _Is_integer {
+ typedef __false_type _Integral;
+};
+
+#ifndef __STL_NO_BOOL
+
+__STL_TEMPLATE_NULL struct _Is_integer<bool> {
+ typedef __true_type _Integral;
+};
+
+#endif /* __STL_NO_BOOL */
+
+__STL_TEMPLATE_NULL struct _Is_integer<char> {
+ typedef __true_type _Integral;
+};
+
+__STL_TEMPLATE_NULL struct _Is_integer<signed char> {
+ typedef __true_type _Integral;
+};
+
+__STL_TEMPLATE_NULL struct _Is_integer<unsigned char> {
+ typedef __true_type _Integral;
+};
+
+#ifdef __STL_HAS_WCHAR_T
+
+__STL_TEMPLATE_NULL struct _Is_integer<wchar_t> {
+ typedef __true_type _Integral;
+};
+
+#endif /* __STL_HAS_WCHAR_T */
+
+__STL_TEMPLATE_NULL struct _Is_integer<short> {
+ typedef __true_type _Integral;
+};
+
+__STL_TEMPLATE_NULL struct _Is_integer<unsigned short> {
+ typedef __true_type _Integral;
+};
+
+__STL_TEMPLATE_NULL struct _Is_integer<int> {
+ typedef __true_type _Integral;
+};
+
+__STL_TEMPLATE_NULL struct _Is_integer<unsigned int> {
+ typedef __true_type _Integral;
+};
+
+__STL_TEMPLATE_NULL struct _Is_integer<long> {
+ typedef __true_type _Integral;
+};
+
+__STL_TEMPLATE_NULL struct _Is_integer<unsigned long> {
+ typedef __true_type _Integral;
+};
+
+#ifdef __STL_LONG_LONG
+
+__STL_TEMPLATE_NULL struct _Is_integer<long long> {
+ typedef __true_type _Integral;
+};
+
+__STL_TEMPLATE_NULL struct _Is_integer<unsigned long long> {
+ typedef __true_type _Integral;
+};
+
+#endif /* __STL_LONG_LONG */
+
+template<typename _Tp> struct _Is_normal_iterator {
+ typedef __false_type _Normal;
+};
+
+// Forward declaration hack, should really include this from somewhere.
+namespace std {
+ template<typename _Iterator, typename _Container> class __normal_iterator;
+};
+
+template<typename _Iterator, typename _Container>
+struct _Is_normal_iterator< std::__normal_iterator<_Iterator, _Container> > {
+ typedef __true_type _Normal;
+};
+
+#endif /* _CPP_BITS_TYPE_TRAITS_H */
+
+// Local Variables:
+// mode:C++
+// End:
diff --git a/libstdc++-v3/bits/valarray_array.h b/libstdc++-v3/bits/valarray_array.h
new file mode 100644
index 0000000..fc610ee
--- /dev/null
+++ b/libstdc++-v3/bits/valarray_array.h
@@ -0,0 +1,535 @@
+// The template and inlines for the -*- C++ -*- internal _Array helper class.
+
+// Copyright (C) 1997-2000 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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 Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
+
+#ifndef _CPP_BITS_ARRAY_H
+#define _CPP_BITS_ARRAY_H 1
+
+#include <bits/c++config.h>
+#include <bits/cpp_type_traits.h>
+#include <bits/std_cstdlib.h>
+#include <bits/std_cstring.h>
+#include <bits/std_new.h>
+
+namespace std
+{
+
+ //
+ // Helper functions on raw pointers
+ //
+
+ // We get memory by the old fashion way
+ inline void*
+ __valarray_get_memory(size_t __n)
+ { return operator new(__n); }
+
+ // Return memory to the system
+ inline void
+ __valarray_release_memory(void* __p)
+ { operator delete(__p); }
+
+ // Turn a raw-memory into an array of _Tp filled with _Tp()
+ // This is required in 'valarray<T> v(n);'
+ template<typename _Tp, bool>
+ struct _Array_default_ctor
+ {
+ // Please note that this isn't exception safe. But
+ // valarrays aren't required to be exception safe.
+ inline static void
+ _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ { while (__b != __e) new(__b++) _Tp(); }
+ };
+
+ template<typename _Tp>
+ struct _Array_default_ctor<_Tp, true>
+ {
+ // For fundamental types, it suffices to say 'memset()'
+ inline static void
+ _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ { memset(__b, 0, __e - __b); }
+ };
+
+ template<typename _Tp>
+ inline void
+ __valarray_default_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ {
+ _Array_default_ctor<_Tp, __is_fundamental<_Tp>::_M_type>::
+ _S_do_it(__b, __e);
+ }
+
+ // Turn a raw-memory into an array of _Tp filled with __t
+ // This is the required in valarray<T> v(n, t). Also
+ // used in valarray<>::resize().
+ template<typename _Tp, bool>
+ struct _Array_init_ctor
+ {
+ // Please note that this isn't exception safe. But
+ // valarrays aren't required to be exception safe.
+ inline static void
+ _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t)
+ { while (__b != __e) new(__b++) _Tp(__t); }
+ };
+
+ template<typename _Tp>
+ struct _Array_init_ctor<_Tp, true>
+ {
+ inline static void
+ _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t)
+ { while (__b != __e) *__b++ = __t; }
+ };
+
+ template<typename _Tp>
+ inline void
+ __valarray_fill_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e,
+ const _Tp __t)
+ {
+ _Array_init_ctor<_Tp, __is_fundamental<_Tp>::_M_type>::
+ _S_do_it(__b, __e, __t);
+ }
+
+ //
+ // copy-construct raw array [__o, *) from plain array [__b, __e)
+ // We can't just say 'memcpy()'
+ //
+ template<typename _Tp, bool>
+ struct _Array_copy_ctor
+ {
+ // Please note that this isn't exception safe. But
+ // valarrays aren't required to be exception safe.
+ inline static void
+ _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e,
+ _Tp* __restrict__ __o)
+ { while (__b != __e) new(__o++) _Tp(*__b++); }
+ };
+
+ template<typename _Tp>
+ struct _Array_copy_ctor<_Tp, true>
+ {
+ inline static void
+ _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e,
+ _Tp* __restrict__ __o)
+ { memcpy(__o, __b, __e - __b); }
+ };
+
+ template<typename _Tp>
+ inline void
+ __valarray_copy_construct(const _Tp* __restrict__ __b,
+ const _Tp* __restrict__ __e,
+ _Tp* __restrict__ __o)
+ {
+ _Array_copy_ctor<_Tp, __is_fundamental<_Tp>::_M_type>::
+ _S_do_it(__b, __e, __o);
+ }
+
+ // copy-construct raw array [__o, *) from strided array __a[<__n : __s>]
+ template<typename _Tp>
+ inline void
+ __valarray_copy_construct (const _Tp* __restrict__ __a, size_t __n,
+ size_t __s, _Tp* __restrict__ __o)
+ {
+ if (__is_fundamental<_Tp>::_M_type)
+ while (__n--) { *__o++ = *__a; __a += __s; }
+ else
+ while (__n--) { new(__o++) _Tp(*__a); __a += __s; }
+ }
+
+ // copy-construct raw array [__o, *) from indexed array __a[__i[<__n>]]
+ template<typename _Tp>
+ inline void
+ __valarray_copy_construct (const _Tp* __restrict__ __a,
+ const size_t* __restrict__ __i,
+ _Tp* __restrict__ __o, size_t __n)
+ {
+ if (__is_fundamental<_Tp>::_M_type)
+ while (__n--) *__o++ = __a[*__i++];
+ else
+ while (__n--) new (__o++) _Tp(__a[*__i++]);
+ }
+
+ // Do the necessary cleanup when we're done with arrays.
+ template<typename _Tp>
+ inline void
+ __valarray_destroy_elements(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
+ {
+ if (!__is_fundamental<_Tp>::_M_type)
+ while (__b != __e) { __b->~_Tp(); ++__b; }
+ }
+
+ // fill plain array __a[<__n>] with __t
+ template<typename _Tp>
+ void
+ __valarray_fill (_Tp* __restrict__ __a, size_t __n, const _Tp& __t)
+ { while (__n--) *__a++ = __t; }
+
+ // fill strided array __a[<__n-1 : __s>] with __t
+ template<typename _Tp>
+ inline void
+ __valarray_fill (_Tp* __restrict__ __a, size_t __n,
+ size_t __s, const _Tp& __t)
+ { for (size_t __i=0; __i<__n; ++__i, __a+=__s) *__a = __t; }
+
+ // fill indir ect array __a[__i[<__n>]] with __i
+ template<typename _Tp>
+ inline void
+ __valarray_fill(_Tp* __restrict__ __a, const size_t* __restrict__ __i,
+ size_t __n, const _Tp& __t)
+ { for (size_t __j=0; __j<__n; ++__j, ++__i) __a[*__i] = __t; }
+
+ // copy plain array __a[<__n>] in __b[<__n>]
+ // For non-fundamental types, it is wrong to say 'memcpy()'
+ template<typename _Tp, bool>
+ struct _Array_copier
+ {
+ inline static void
+ _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b)
+ { while (__n--) *__b++ = *__a++; }
+ };
+
+ template<typename _Tp>
+ struct _Array_copier<_Tp, true>
+ {
+ inline static void
+ _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b)
+ { memcpy (__b, __a, __n * sizeof (_Tp)); }
+ };
+
+ template<typename _Tp>
+ inline void
+ __valarray_copy (const _Tp* __restrict__ __a, size_t __n,
+ _Tp* __restrict__ __b)
+ {
+ _Array_copier<_Tp, __is_fundamental<_Tp>::_M_type>::
+ _S_do_it(__a, __n, __b);
+ }
+
+ // copy strided array __a[<__n : __s>] in plain __b[<__n>]
+ template<typename _Tp>
+ inline void
+ __valarray_copy (const _Tp* __restrict__ __a, size_t __n, size_t __s,
+ _Tp* __restrict__ __b)
+ { for (size_t __i=0; __i<__n; ++__i, ++__b, __a += __s) *__b = *__a; }
+
+ // copy plain __a[<__n>] in strided __b[<__n : __s>]
+ template<typename _Tp>
+ inline void
+ __valarray_copy (const _Tp* __restrict__ __a, _Tp* __restrict__ __b,
+ size_t __n, size_t __s)
+ { for (size_t __i=0; __i<__n; ++__i, ++__a, __b+=__s) *__b = *__a; }
+
+ // copy indexed __a[__i[<__n>]] in plain __b[<__n>]
+ template<typename _Tp>
+ inline void
+ __valarray_copy (const _Tp* __restrict__ __a,
+ const size_t* __restrict__ __i,
+ _Tp* __restrict__ __b, size_t __n)
+ { for (size_t __j=0; __j<__n; ++__j, ++__b, ++__i) *__b = __a[*__i]; }
+
+ // copy plain __a[<__n>] in indexed __b[__i[<__n>]]
+ template<typename _Tp>
+ inline void
+ __valarray_copy (const _Tp* __restrict__ __a, size_t __n,
+ _Tp* __restrict__ __b, const size_t* __restrict__ __i)
+ { for (size_t __j=0; __j<__n; ++__j, ++__a, ++__i) __b[*__i] = *__a; }
+
+
+ //
+ // Compute the sum of elements in range [__f, __l)
+ // This is a naive algorithm. It suffers from cancelling.
+ // In the future try to specialize
+ // for _Tp = float, double, long double using a more accurate
+ // algorithm.
+ //
+ template<typename _Tp>
+ inline _Tp
+ __valarray_sum(const _Tp* __restrict__ __f, const _Tp* __restrict__ __l)
+ {
+ _Tp __r = _Tp();
+ while (__f != __l) __r += *__f++;
+ return __r;
+ }
+
+ // Compute the product of all elements in range [__f, __l)
+ template<typename _Tp>
+ _Tp
+ __valarray_product(const _Tp* __restrict__ __f,
+ const _Tp* __restrict__ __l)
+ {
+ _Tp __r = _Tp(1);
+ while (__f != __l) __r = __r * *__f++;
+ return __r;
+ }
+
+
+ //
+ // Helper class _Array, first layer of valarray abstraction.
+ // All operations on valarray should be forwarded to this class
+ // whenever possible. -- gdr
+ //
+
+ template<typename _Tp>
+ struct _Array
+ {
+ explicit _Array (size_t);
+ explicit _Array (_Tp* const __restrict__);
+ explicit _Array (const valarray<_Tp>&);
+ _Array (const _Tp* __restrict__, size_t);
+
+ _Tp* begin () const;
+
+ _Tp* const __restrict__ _M_data;
+ };
+
+ template<typename _Tp>
+ inline void
+ __valarray_fill (_Array<_Tp> __a, size_t __n, const _Tp& __t)
+ { __valarray_fill (__a._M_data, __n, __t); }
+
+ template<typename _Tp>
+ inline void
+ __valarray_fill (_Array<_Tp> __a, size_t __n, size_t __s, const _Tp& __t)
+ { __valarray_fill (__a._M_data, __n, __s, __t); }
+
+ template<typename _Tp>
+ inline void
+ __valarray_fill (_Array<_Tp> __a, _Array<size_t> __i,
+ size_t __n, const _Tp& __t)
+ { __valarray_fill (__a._M_data, __i._M_data, __n, __t); }
+
+ template<typename _Tp>
+ inline void
+ __valarray_copy (_Array<_Tp> __a, size_t __n, _Array<_Tp> __b)
+ { __valarray_copy (__a._M_data, __n, __b._M_data); }
+
+ template<typename _Tp>
+ inline void
+ __valarray_copy (_Array<_Tp> __a, size_t __n, size_t __s, _Array<_Tp> __b)
+ { __valarray_copy(__a._M_data, __n, __s, __b._M_data); }
+
+ template<typename _Tp>
+ inline void
+ __valarray_copy (_Array<_Tp> __a, _Array<_Tp> __b, size_t __n, size_t __s)
+ { __valarray_copy (__a._M_data, __b._M_data, __n, __s); }
+
+ template<typename _Tp>
+ inline void
+ __valarray_copy (_Array<_Tp> __a, _Array<size_t> __i,
+ _Array<_Tp> __b, size_t __n)
+ { __valarray_copy (__a._M_data, __i._M_data, __b._M_data, __n); }
+
+ template<typename _Tp>
+ inline void
+ __valarray_copy (_Array<_Tp> __a, size_t __n, _Array<_Tp> __b,
+ _Array<size_t> __i)
+ { __valarray_copy (__a._M_data, __n, __b._M_data, __i._M_data); }
+
+ template<typename _Tp>
+ inline
+ _Array<_Tp>::_Array (size_t __n)
+ : _M_data(__valarray_get_memory(__n * sizeof (_Tp)))
+ { __valarray_default_construct(_M_data, _M_data + __n); }
+
+ template<typename _Tp>
+ inline
+ _Array<_Tp>::_Array (_Tp* const __restrict__ __p) : _M_data (__p) {}
+
+ template<typename _Tp>
+ inline _Array<_Tp>::_Array (const valarray<_Tp>& __v)
+ : _M_data (__v._M_data) {}
+
+ template<typename _Tp>
+ inline
+ _Array<_Tp>::_Array (const _Tp* __restrict__ __b, size_t __s)
+ : _M_data(__valarray_get_memory(__s * sizeof (_Tp)))
+ { __valarray_copy_construct(__b, __s, _M_data); }
+
+ template<typename _Tp>
+ inline _Tp*
+ _Array<_Tp>::begin () const
+ { return _M_data; }
+
+#define _DEFINE_ARRAY_FUNCTION(_Op, _Name) \
+template<typename _Tp> \
+inline void \
+_Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, const _Tp& __t) \
+{ \
+ for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p) \
+ *__p _Op##= __t; \
+} \
+ \
+template<typename _Tp> \
+inline void \
+_Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, _Array<_Tp> __b) \
+{ \
+ _Tp* __p = __a._M_data; \
+ for (_Tp* __q=__b._M_data; __q<__b._M_data+__n; ++__p, ++__q) \
+ *__p _Op##= *__q; \
+} \
+ \
+template<typename _Tp, class _Dom> \
+void \
+_Array_augmented_##_Name (_Array<_Tp> __a, \
+ const _Expr<_Dom,_Tp>& __e, size_t __n) \
+{ \
+ _Tp* __p (__a._M_data); \
+ for (size_t __i=0; __i<__n; ++__i, ++__p) *__p _Op##= __e[__i]; \
+} \
+ \
+template<typename _Tp> \
+inline void \
+_Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, size_t __s, \
+ _Array<_Tp> __b) \
+{ \
+ _Tp* __q (__b._M_data); \
+ for (_Tp* __p=__a._M_data; __p<__a._M_data+__s*__n; __p+=__s, ++__q) \
+ *__p _Op##= *__q; \
+} \
+ \
+template<typename _Tp> \
+inline void \
+_Array_augmented_##_Name (_Array<_Tp> __a, _Array<_Tp> __b, \
+ size_t __n, size_t __s) \
+{ \
+ _Tp* __q (__b._M_data); \
+ for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p, __q+=__s) \
+ *__p _Op##= *__q; \
+} \
+ \
+template<typename _Tp, class _Dom> \
+void \
+_Array_augmented_##_Name (_Array<_Tp> __a, size_t __s, \
+ const _Expr<_Dom,_Tp>& __e, size_t __n) \
+{ \
+ _Tp* __p (__a._M_data); \
+ for (size_t __i=0; __i<__n; ++__i, __p+=__s) *__p _Op##= __e[__i]; \
+} \
+ \
+template<typename _Tp> \
+inline void \
+_Array_augmented_##_Name (_Array<_Tp> __a, _Array<size_t> __i, \
+ _Array<_Tp> __b, size_t __n) \
+{ \
+ _Tp* __q (__b._M_data); \
+ for (size_t* __j=__i._M_data; __j<__i._M_data+__n; ++__j, ++__q) \
+ __a._M_data[*__j] _Op##= *__q; \
+} \
+ \
+template<typename _Tp> \
+inline void \
+_Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, \
+ _Array<_Tp> __b, _Array<size_t> __i) \
+{ \
+ _Tp* __p (__a._M_data); \
+ for (size_t* __j=__i._M_data; __j<__i._M_data+__n; ++__j, ++__p) \
+ *__p _Op##= __b._M_data[*__j]; \
+} \
+ \
+template<typename _Tp, class _Dom> \
+void \
+_Array_augmented_##_Name (_Array<_Tp> __a, _Array<size_t> __i, \
+ const _Expr<_Dom, _Tp>& __e, size_t __n) \
+{ \
+ size_t* __j (__i._M_data); \
+ for (size_t __k=0; __k<__n; ++__k, ++__j) \
+ __a._M_data[*__j] _Op##= __e[__k]; \
+} \
+ \
+template<typename _Tp> \
+void \
+_Array_augmented_##_Name (_Array<_Tp> __a, _Array<bool> __m, \
+ _Array<_Tp> __b, size_t __n) \
+{ \
+ bool* ok (__m._M_data); \
+ _Tp* __p (__a._M_data); \
+ for (_Tp* __q=__b._M_data; __q<__b._M_data+__n; ++__q, ++ok, ++__p) { \
+ while (! *ok) { \
+ ++ok; \
+ ++__p; \
+ } \
+ *__p _Op##= *__q; \
+ } \
+} \
+ \
+template<typename _Tp> \
+void \
+_Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, \
+ _Array<_Tp> __b, _Array<bool> __m) \
+{ \
+ bool* ok (__m._M_data); \
+ _Tp* __q (__b._M_data); \
+ for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p, ++ok, ++__q) { \
+ while (! *ok) { \
+ ++ok; \
+ ++__q; \
+ } \
+ *__p _Op##= *__q; \
+ } \
+} \
+ \
+template<typename _Tp, class _Dom> \
+void \
+_Array_augmented_##_Name (_Array<_Tp> __a, _Array<bool> __m, \
+ const _Expr<_Dom, _Tp>& __e, size_t __n) \
+{ \
+ bool* ok(__m._M_data); \
+ _Tp* __p (__a._M_data); \
+ for (size_t __i=0; __i<__n; ++__i, ++ok, ++__p) { \
+ while (! *ok) { \
+ ++ok; \
+ ++__p; \
+ } \
+ *__p _Op##= __e[__i]; \
+ } \
+}
+
+_DEFINE_ARRAY_FUNCTION(+, plus)
+_DEFINE_ARRAY_FUNCTION(-, minus)
+_DEFINE_ARRAY_FUNCTION(*, multiplies)
+_DEFINE_ARRAY_FUNCTION(/, divides)
+_DEFINE_ARRAY_FUNCTION(%, modulus)
+_DEFINE_ARRAY_FUNCTION(^, xor)
+_DEFINE_ARRAY_FUNCTION(|, or)
+_DEFINE_ARRAY_FUNCTION(&, and)
+_DEFINE_ARRAY_FUNCTION(<<, shift_left)
+_DEFINE_ARRAY_FUNCTION(>>, shift_right)
+
+#undef _DEFINE_VALARRAY_FUNCTION
+
+} // std::
+
+#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
+# define export
+# include <bits/valarray_array.tcc>
+#endif
+
+#endif /* _CPP_BITS_ARRAY_H */
+
+// Local Variables:
+// mode:c++
+// End:
diff --git a/libstdc++-v3/bits/valarray_array.tcc b/libstdc++-v3/bits/valarray_array.tcc
new file mode 100644
index 0000000..ab77f4a
--- /dev/null
+++ b/libstdc++-v3/bits/valarray_array.tcc
@@ -0,0 +1,161 @@
+// The template and inlines for the -*- C++ -*- internal _Array helper class.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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 Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
+
+#ifndef _CPP_BITS_VALARRAY_ARRAY_TCC
+#define _CPP_BITS_VALARRAY_ARRAY_TCC 1
+
+namespace std
+{
+
+export template<typename _Tp>
+void
+__valarray_fill (_Array<_Tp> __a, size_t __n, _Array<bool> __m, const _Tp& __t)
+{
+ _Tp* __p = __a._M_data;
+ bool* __ok (__m._M_data);
+ for (size_t __i=0; __i<__n; ++__i, ++__ok, ++__p) {
+ while (! *__ok) {
+ ++__ok;
+ ++__p;
+ }
+ *__p = __t;
+ }
+}
+
+export template<typename _Tp>
+void
+__valarray_copy (_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b, size_t __n)
+{
+ _Tp* __p (__a._M_data);
+ bool* __ok (__m._M_data);
+ for (_Tp* __q=__b._M_data; __q<__b._M_data+__n; ++__q, ++__ok, ++__p) {
+ while (! *__ok) {
+ ++__ok;
+ ++__p;
+ }
+ *__q = *__p;
+ }
+}
+
+export template<typename _Tp>
+void
+__valarray_copy (_Array<_Tp> __a, size_t __n, _Array<_Tp> __b, _Array<bool> __m)
+{
+ _Tp* __q (__b._M_data);
+ bool* __ok (__m._M_data);
+ for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p, ++__ok, ++__q) {
+ while (! *__ok) {
+ ++__ok;
+ ++__q;
+ }
+ *__q = *__p;
+ }
+}
+
+export template<typename _Tp, class _Dom>
+void
+__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a)
+{
+ _Tp* __p (__a._M_data);
+ for (size_t __i=0; __i<__n; ++__i, ++__p) *__p = __e[__i];
+}
+
+export template<typename _Tp, class _Dom>
+void
+__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n,
+ _Array<_Tp> __a, size_t __s)
+{
+ _Tp* __p (__a._M_data);
+ for (size_t __i=0; __i<__n; ++__i, __p+=__s) *__p = __e[__i];
+}
+
+export template<typename _Tp, class _Dom>
+void
+__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n,
+ _Array<_Tp> __a, _Array<size_t> __i)
+{
+ size_t* __j (__i._M_data);
+ for (size_t __k=0; __k<__n; ++__k, ++__j) __a._M_data[*__j] = __e[__k];
+}
+
+export template<typename _Tp, class _Dom>
+void
+__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n,
+ _Array<_Tp> __a, _Array<bool> __m)
+{
+ bool* __ok (__m._M_data);
+ _Tp* __p (__a._M_data);
+ for (size_t __i=0; __i<__n; ++__i, ++__ok, ++__p) {
+ while (! *__ok) {
+ ++__ok;
+ ++__p;
+ }
+ *__p = __e[__i];
+ }
+}
+
+
+export template<typename _Tp, class _Dom>
+void
+__valarray_copy_construct (const _Expr<_Dom, _Tp>& __e, size_t __n,
+ _Array<_Tp> __a)
+{
+ _Tp* __p (__a._M_data);
+ for (size_t __i=0; __i<__n; ++__i, ++__p) new (__p) _Tp(__e[__i]);
+}
+
+
+export template<typename _Tp>
+void
+__valarray_copy_construct (_Array<_Tp> __a, _Array<bool> __m,
+ _Array<_Tp> __b, size_t __n)
+{
+ _Tp* __p (__a._M_data);
+ bool* __ok (__m._M_data);
+ for (_Tp* __q=__b._M_data; __q<__b._M_data+__n; ++__q, ++__ok, ++__p) {
+ while (! *__ok) {
+ ++__ok;
+ ++__p;
+ }
+ new (__q) _Tp(*__p);
+ }
+}
+
+
+
+
+} // std::
+
+#endif /* _CPP_BITS_VALARRAY_ARRAY_TCC */
+
+// Local Variables:
+// mode:c++
+// End:
diff --git a/libstdc++-v3/bits/valarray_meta.h b/libstdc++-v3/bits/valarray_meta.h
new file mode 100644
index 0000000..1207bd9
--- /dev/null
+++ b/libstdc++-v3/bits/valarray_meta.h
@@ -0,0 +1,1057 @@
+// The template and inlines for the -*- C++ -*- internal _Meta class.
+
+// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO 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, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself 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 Gabriel Dos Reis <Gabriel.Dos-Reis@cmla.ens-cachan.fr>
+
+#ifndef _CPP_VALARRAY_META_H
+#define _CPP_VALARRAY_META_H 1
+
+namespace std {
+
+ //
+ // Implementing a loosened valarray return value is tricky.
+ // First we need to meet 26.3.1/3: we should not add more than
+ // two levels of template nesting. Therefore we resort to template
+ // template to "flatten" loosened return value types.
+ // At some point we use partial specialization to remove one level
+ // template nesting due to _Expr<>
+ //
+
+
+ // This class is NOT defined. It doesn't need to.
+ template<typename _Tp1, typename _Tp2> class _Constant;
+
+ //
+ // Unary function application closure.
+ //
+ template<class _Dom> class _UnFunBase {
+ public:
+ typedef typename _Dom::value_type value_type;
+ typedef value_type _Vt;
+
+ _UnFunBase (const _Dom& __e, _Vt __f(_Vt))
+ : _M_expr(__e), _M_func(__f) {}
+
+ _Vt operator[] (size_t __i) const { return _M_func(_M_expr[__i]); }
+ size_t size () const { return _M_expr.size(); }
+
+ private:
+ const _Dom& _M_expr;
+ _Vt (*_M_func)(_Vt);
+ };
+
+ template<template<class, class> class _Meta, class _Dom>
+ class _UnFunClos;
+
+ template<class _Dom>
+ struct _UnFunClos<_Expr,_Dom> : _UnFunBase<_Dom> {
+ typedef _UnFunBase<_Dom> _Base;
+ typedef typename _Base::value_type value_type;
+
+ _UnFunClos (const _Dom& __e, value_type __f(value_type))
+ : _Base (__e, __f) {}
+ };
+
+ template<typename _Tp>
+ struct _UnFunClos<_ValArray,_Tp> : _UnFunBase<valarray<_Tp> > {
+ typedef _UnFunBase<valarray<_Tp> > _Base;
+ typedef typename _Base::value_type value_type;
+
+ _UnFunClos (const valarray<_Tp>& __v, _Tp __f(_Tp))
+ : _Base (__v, __f) {}
+ };
+
+ //
+ // Binary function application closure.
+ //
+ template<template<class, class> class _Meta1,
+ template<class, class> class Meta2,
+ class _Dom1, class _Dom2> class _BinFunClos;
+
+ template<class _Dom1, class _Dom2> class _BinFunBase {
+ public:
+ typedef typename _Dom1::value_type value_type;
+ typedef value_type _Vt;
+
+ _BinFunBase (const _Dom1& __e1, const _Dom2& __e2,
+ _Vt __f (_Vt, _Vt))
+ : _M_expr1 (__e1), _M_expr2 (__e2), _M_func (__f) {}
+
+ value_type operator[] (size_t __i) const
+ { return _M_func (_M_expr1[__i], _M_expr2[__i]); }
+ size_t size () const { return _M_expr1.size (); }
+
+ private:
+ const _Dom1& _M_expr1;
+ const _Dom2& _M_expr2;
+ _Vt (*_M_func)(_Vt, _Vt);
+ };
+
+ template<class _Dom> class _BinFunBase1 {
+ public:
+ typedef typename _Dom::value_type value_type ;
+ typedef value_type _Vt;
+
+ _BinFunBase1 (const _Vt& __c, const _Dom& __e, _Vt __f(_Vt, _Vt))
+ : _M_expr1 (__c), _M_expr2 (__e), _M_func (__f) {}
+
+ value_type operator[] (size_t __i) const
+ { return _M_func (_M_expr1, _M_expr2[__i]); }
+ size_t size () const { return _M_expr2.size (); }
+
+ private:
+ const _Vt& _M_expr1;
+ const _Dom& _M_expr2;
+ _Vt (*_M_func)(_Vt, _Vt);
+ };
+
+ template<class _Dom> class _BinFunBase2 {
+ public:
+ typedef typename _Dom::value_type value_type;
+ typedef value_type _Vt;
+
+ _BinFunBase2 (const _Dom& __e, const _Vt& __c, _Vt __f(_Vt, _Vt))
+ : _M_expr1 (__e), _M_expr2 (__c), _M_func (__f) {}
+
+ value_type operator[] (size_t __i) const
+ { return _M_func (_M_expr1[__i], _M_expr2); }
+ size_t size () const { return _M_expr1.size (); }
+
+ private:
+ const _Dom& _M_expr1;
+ const _Vt& _M_expr2;
+ _Vt (*_M_func)(_Vt, _Vt);
+ };
+
+ template<class _Dom1, class _Dom2>
+ struct _BinFunClos<_Expr,_Expr,_Dom1,_Dom2> : _BinFunBase<_Dom1,_Dom2> {
+ typedef _BinFunBase<_Dom1,_Dom2> _Base;
+ typedef typename _Base::value_type value_type;
+ typedef value_type _Tp;
+
+ _BinFunClos (const _Dom1& __e1, const _Dom2& __e2,
+ _Tp __f(_Tp, _Tp))
+ : _Base (__e1, __e2, __f) {}
+ };
+
+ template<typename _Tp>
+ struct _BinFunClos<_ValArray,_ValArray,_Tp,_Tp>
+ : _BinFunBase<valarray<_Tp>, valarray<_Tp> > {
+ typedef _BinFunBase<valarray<_Tp>, valarray<_Tp> > _Base;
+ typedef _Tp value_type;
+
+ _BinFunClos (const valarray<_Tp>& __v, const valarray<_Tp>& __w,
+ _Tp __f(_Tp, _Tp))
+ : _Base (__v, __w, __f) {}
+ };
+
+ template<class _Dom>
+ struct _BinFunClos<_Expr,_ValArray,_Dom,typename _Dom::value_type>
+ : _BinFunBase<_Dom,valarray<typename _Dom::value_type> > {
+ typedef typename _Dom::value_type _Tp;
+ typedef _BinFunBase<_Dom,valarray<_Tp> > _Base;
+ typedef _Tp value_type;
+
+ _BinFunClos (const _Dom& __e, const valarray<_Tp>& __v,
+ _Tp __f(_Tp, _Tp))
+ : _Base (__e, __v, __f) {}
+ };
+
+ template<class _Dom>
+ struct _BinFunClos<_ValArray,_Expr,typename _Dom::value_type,_Dom>
+ : _BinFunBase<valarray<typename _Dom::value_type>,_Dom> {
+ typedef typename _Dom::value_type _Tp;
+ typedef _BinFunBase<_Dom,valarray<_Tp> > _Base;
+ typedef _Tp value_type;
+
+ _BinFunClos (const valarray<_Tp>& __v, const _Dom& __e,
+ _Tp __f(_Tp, _Tp))
+ : _Base (__v, __e, __f) {}
+ };
+
+ template<class _Dom>
+ struct _BinFunClos<_Expr,_Constant,_Dom,typename _Dom::value_type>
+ : _BinFunBase2<_Dom> {
+ typedef typename _Dom::value_type _Tp;
+ typedef _Tp value_type;
+ typedef _BinFunBase2<_Dom> _Base;
+
+ _BinFunClos (const _Dom& __e, const _Tp& __t, _Tp __f (_Tp, _Tp))
+ : _Base (__e, __t, __f) {}
+ };
+
+ template<class _Dom>
+ struct _BinFunClos<_Constant,_Expr,_Dom,typename _Dom::value_type>
+ : _BinFunBase1<_Dom> {
+ typedef typename _Dom::value_type _Tp;
+ typedef _Tp value_type;
+ typedef _BinFunBase1<_Dom> _Base;
+
+ _BinFunClos (const _Tp& __t, const _Dom& __e, _Tp __f (_Tp, _Tp))
+ : _Base (__t, __e, __f) {}
+ };
+
+ template<typename _Tp>
+ struct _BinFunClos<_ValArray,_Constant,_Tp,_Tp>
+ : _BinFunBase2<valarray<_Tp> > {
+ typedef _BinFunBase2<valarray<_Tp> > _Base;
+ typedef _Tp value_type;
+
+ _BinFunClos (const valarray<_Tp>& __v, const _Tp& __t,
+ _Tp __f(_Tp, _Tp))
+ : _Base (__v, __t, __f) {}
+ };
+
+ template<typename _Tp>
+ struct _BinFunClos<_Constant,_ValArray,_Tp,_Tp>
+ : _BinFunBase1<valarray<_Tp> > {
+ typedef _BinFunBase1<valarray<_Tp> > _Base;
+ typedef _Tp value_type;
+
+ _BinFunClos (const _Tp& __t, const valarray<_Tp>& __v,
+ _Tp __f (_Tp, _Tp))
+ : _Base (__t, __v, __f) {}
+ };
+
+ //
+ // Apply function taking a value/const reference closure
+ //
+
+ template<typename _Dom, typename _Arg> class _FunBase {
+ public:
+ typedef typename _Dom::value_type value_type;
+
+ _FunBase (const _Dom& __e, value_type __f(_Arg))
+ : _M_expr (__e), _M_func (__f) {}
+
+ value_type operator[] (size_t __i) const
+ { return _M_func (_M_expr[__i]); }
+ size_t size() const { return _M_expr.size ();}
+
+ private:
+ const _Dom& _M_expr;
+ value_type (*_M_func)(_Arg);
+ };
+
+ template<class _Dom>
+ struct _ValFunClos<_Expr,_Dom>
+ : _FunBase<_Dom, typename _Dom::value_type> {
+ typedef _FunBase<_Dom, typename _Dom::value_type> _Base;
+ typedef typename _Base::value_type value_type;
+ typedef value_type _Tp;
+
+ _ValFunClos (const _Dom& __e, _Tp __f (_Tp)) : _Base (__e, __f) {}
+ };
+
+ template<typename _Tp>
+ struct _ValFunClos<_ValArray,_Tp>
+ : _FunBase<valarray<_Tp>, _Tp> {
+ typedef _FunBase<valarray<_Tp>, _Tp> _Base;
+ typedef _Tp value_type;
+
+ _ValFunClos (const valarray<_Tp>& __v, _Tp __f(_Tp))
+ : _Base (__v, __f) {}
+ };
+
+ template<class _Dom>
+ struct _RefFunClos<_Expr,_Dom> :
+ _FunBase<_Dom, const typename _Dom::value_type&> {
+ typedef _FunBase<_Dom, const typename _Dom::value_type&> _Base;
+ typedef typename _Base::value_type value_type;
+ typedef value_type _Tp;
+
+ _RefFunClos (const _Dom& __e, _Tp __f (const _Tp&))
+ : _Base (__e, __f) {}
+ };
+
+ template<typename _Tp>
+ struct _RefFunClos<_ValArray,_Tp>
+ : _FunBase<valarray<_Tp>, const _Tp&> {
+ typedef _FunBase<valarray<_Tp>, const _Tp&> _Base;
+ typedef _Tp value_type;
+
+ _RefFunClos (const valarray<_Tp>& __v, _Tp __f(const _Tp&))
+ : _Base (__e, __f) {}
+ };
+
+ //
+ // Unary expression closure.
+ //
+
+ template<template<class> class _Oper, typename _Arg>
+ class _UnBase {
+ public:
+ typedef _Oper<typename _Arg::value_type> _Op;
+ typedef typename _Op::result_type value_type;
+
+ _UnBase (const _Arg& __e) : _M_expr(__e) {}
+ value_type operator[] (size_t) const;
+ size_t size () const { return _M_expr.size (); }
+
+ private:
+ const _Arg& _M_expr;
+ };
+
+ template<template<class> class _Oper, typename _Arg>
+ inline typename _UnBase<_Oper, _Arg>::value_type
+ _UnBase<_Oper, _Arg>::operator[] (size_t __i) const
+ { return _Op() (_M_expr[__i]); }
+
+ template<template<class> class _Oper, class _Dom>
+ struct _UnClos<_Oper, _Expr, _Dom> : _UnBase<_Oper, _Dom> {
+ typedef _Dom _Arg;
+ typedef _UnBase<_Oper, _Dom> _Base;
+ typedef typename _Base::value_type value_type;
+
+ _UnClos (const _Arg& __e) : _Base(__e) {}
+ };
+
+ template<template<class> class _Oper, typename _Tp>
+ struct _UnClos<_Oper, _ValArray, _Tp> : _UnBase<_Oper, valarray<_Tp> > {
+ typedef valarray<_Tp> _Arg;
+ typedef _UnBase<_Oper, valarray<_Tp> > _Base;
+ typedef typename _Base::value_type value_type;
+
+ _UnClos (const _Arg& __e) : _Base(__e) {}
+ };
+
+
+ //
+ // Binary expression closure.
+ //
+
+ template<template<class> class _Oper,
+ typename _FirstArg, typename _SecondArg>
+ class _BinBase {
+ public:
+ typedef _Oper<typename _FirstArg::value_type> _Op;
+ typedef typename _Op::result_type value_type;
+
+ _BinBase (const _FirstArg& __e1, const _SecondArg& __e2)
+ : _M_expr1 (__e1), _M_expr2 (__e2) {}
+ value_type operator[] (size_t) const;
+ size_t size () const { return _M_expr1.size (); }
+
+ private:
+ const _FirstArg& _M_expr1;
+ const _SecondArg& _M_expr2;
+ };
+
+ template<template<class> class _Oper,
+ typename _FirstArg, typename _SecondArg>
+ inline typename _BinBase<_Oper,_FirstArg,_SecondArg>::value_type
+ _BinBase<_Oper,_FirstArg,_SecondArg>::operator[] (size_t __i) const
+ { return _Op() (_M_expr1[__i], _M_expr2[__i]); }
+
+
+ template<template<class> class _Oper, class _Clos>
+ class _BinBase2 {
+ public:
+ typedef typename _Clos::value_type _Vt;
+ typedef _Oper<_Vt> _Op;
+ typedef typename _Op::result_type value_type;
+
+ _BinBase2 (const _Clos& __e, const _Vt& __t)
+ : _M_expr1 (__e), _M_expr2 (__t) {}
+ value_type operator[] (size_t) const;
+ size_t size () const { return _M_expr1.size (); }
+
+ private:
+ const _Clos& _M_expr1;
+ const _Vt& _M_expr2;
+ };
+
+ template<template<class> class _Oper, class _Clos>
+ inline typename _BinBase2<_Oper,_Clos>::value_type
+ _BinBase2<_Oper,_Clos>::operator[] (size_t __i) const
+ { return _Op() (_M_expr1[__i], _M_expr2); }
+
+
+ template<template<class> class _Oper, class _Clos>
+ class _BinBase1 {
+ public:
+ typedef typename _Clos::value_type _Vt;
+ typedef _Oper<_Vt> _Op;
+ typedef typename _Op::result_type value_type;
+
+ _BinBase1 (const _Vt& __t, const _Clos& __e)
+ : _M_expr1 (__t), _M_expr2 (__e) {}
+ value_type operator[] (size_t) const;
+ size_t size () const { return _M_expr2.size (); }
+
+ private:
+ const _Vt& _M_expr1;
+ const _Clos& _M_expr2;
+ };
+
+ template<template<class> class _Oper, class _Clos>
+ inline typename
+ _BinBase1<_Oper,_Clos>::value_type
+ _BinBase1<_Oper,_Clos>:: operator[] (size_t __i) const
+ { return _Op() (_M_expr1, _M_expr2[__i]); }
+
+
+ template<template<class> class _Oper, class _Dom1, class _Dom2>
+ struct _BinClos<_Oper, _Expr, _Expr, _Dom1, _Dom2>
+ : _BinBase<_Oper,_Dom1,_Dom2> {
+ typedef _BinBase<_Oper,_Dom1,_Dom2> _Base;
+ typedef typename _Base::value_type value_type;
+
+ _BinClos(const _Dom1& __e1, const _Dom2& __e2) : _Base(__e1, __e2) {}
+ };
+
+ template<template<class> class _Oper, typename _Tp>
+ struct _BinClos<_Oper,_ValArray,_ValArray,_Tp,_Tp>
+ : _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> > {
+ typedef _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> > _Base;
+ typedef _Tp value_type;
+
+ _BinClos (const valarray<_Tp>& __v, const valarray<_Tp>& __w)
+ : _Base (__v, __w) {}
+ };
+
+ template<template<class> class _Oper, class _Dom>
+ struct _BinClos<_Oper,_Expr,_ValArray,_Dom,typename _Dom::value_type>
+ : _BinBase<_Oper,_Dom,valarray<typename _Dom::value_type> > {
+ typedef typename _Dom::value_type _Tp;
+ typedef _BinBase<_Oper,_Dom,valarray<_Tp> > _Base;
+ typedef typename _Base::value_type value_type;
+
+ _BinClos(const _Dom& __e1, const valarray<_Tp>& __e2)
+ : _Base (__e1, __e2) {}
+ };
+
+ template<template<class> class _Oper, class _Dom>
+ struct _BinClos<_Oper,_ValArray,_Expr,typename _Dom::value_type,_Dom>
+ : _BinBase<_Oper,valarray<typename _Dom::value_type>,_Dom> {
+ typedef typename _Dom::value_type _Tp;
+ typedef _BinBase<_Oper,valarray<_Tp>,_Dom> _Base;
+ typedef typename _Base::value_type value_type;
+
+ _BinClos (const valarray<_Tp>& __e1, const _Dom& __e2)
+ : _Base (__e1, __e2) {}
+ };
+
+ template<template<class> class _Oper, class _Dom>
+ struct _BinClos<_Oper,_Expr,_Constant,_Dom,typename _Dom::value_type>
+ : _BinBase2<_Oper,_Dom> {
+ typedef typename _Dom::value_type _Tp;
+ typedef _BinBase2<_Oper,_Dom> _Base;
+ typedef typename _Base::value_type value_type;
+
+ _BinClos (const _Dom& __e1, const _Tp& __e2) : _Base (__e1, __e2) {}
+ };
+
+ template<template<class> class _Oper, class _Dom>
+ struct _BinClos<_Oper,_Constant,_Expr,typename _Dom::value_type,_Dom>
+ : _BinBase1<_Oper,_Dom> {
+ typedef typename _Dom::value_type _Tp;
+ typedef _BinBase1<_Oper,_Dom> _Base;
+ typedef typename _Base::value_type value_type;
+
+ _BinClos (const _Tp& __e1, const _Dom& __e2) : _Base (__e1, __e2) {}
+ };
+
+ template<template<class> class _Oper, typename _Tp>
+ struct _BinClos<_Oper,_ValArray,_Constant,_Tp,_Tp>
+ : _BinBase2<_Oper,valarray<_Tp> > {
+ typedef _BinBase2<_Oper,valarray<_Tp> > _Base;
+ typedef typename _Base::value_type value_type;
+
+ _BinClos (const valarray<_Tp>& __v, const _Tp& __t)
+ : _Base (__v, __t) {}
+ };
+
+ template<template<class> class _Oper, typename _Tp>
+ struct _BinClos<_Oper,_Constant,_ValArray,_Tp,_Tp>
+ : _BinBase1<_Oper,valarray<_Tp> > {
+ typedef _BinBase1<_Oper,valarray<_Tp> > _Base;
+ typedef typename _Base::value_type value_type;
+
+ _BinClos (const _Tp& __t, const valarray<_Tp>& __v)
+ : _Base (__t, __v) {}
+ };
+
+
+ //
+ // slice_array closure.
+ //
+ template<typename _Dom> class _SBase {
+ public:
+ typedef typename _Dom::value_type value_type;
+
+ _SBase (const _Dom& __e, const slice& __s)
+ : _M_expr (__e), _M_slice (__s) {}
+ value_type operator[] (size_t __i) const
+ { return _M_expr[_M_slice.start () + __i * _M_slice.stride ()]; }
+ size_t size() const { return _M_slice.size (); }
+
+ private:
+ const _Dom& _M_expr;
+ const slice& _M_slice;
+ };
+
+ template<typename _Tp> class _SBase<_Array<_Tp> > {
+ public:
+ typedef _Tp value_type;
+
+ _SBase (_Array<_Tp> __a, const slice& __s)
+ : _M_array (__a._M_data+__s.start()), _M_size (__s.size()),
+ _M_stride (__s.stride()) {}
+ value_type operator[] (size_t __i) const
+ { return _M_array._M_data[__i * _M_stride]; }
+ size_t size() const { return _M_size; }
+
+ private:
+ const _Array<_Tp> _M_array;
+ const size_t _M_size;
+ const size_t _M_stride;
+ };
+
+ template<class _Dom> struct _SClos<_Expr,_Dom> : _SBase<_Dom> {
+ typedef _SBase<_Dom> _Base;
+ typedef typename _Base::value_type value_type;
+
+ _SClos (const _Dom& __e, const slice& __s) : _Base (__e, __s) {}
+ };
+
+ template<typename _Tp>
+ struct _SClos<_ValArray,_Tp> : _SBase<_Array<_Tp> > {
+ typedef _SBase<_Array<_Tp> > _Base;
+ typedef _Tp value_type;
+
+ _SClos (_Array<_Tp> __a, const slice& __s) : _Base (__a, __s) {}
+ };
+
+ //
+ // gslice_array closure.
+ //
+ template<class _Dom> class _GBase {
+ public:
+ typedef typename _Dom::value_type value_type;
+
+ _GBase (const _Dom& __e, const valarray<size_t>& __i)
+ : _M_expr (__e), _M_index(__i) {}
+ value_type operator[] (size_t __i) const
+ { return _M_expr[_M_index[__i]]; }
+ size_t size () const { return _M_index.size(); }
+
+ private:
+ const _Dom& _M_expr;
+ const valarray<size_t>& _M_index;
+ };
+
+ template<typename _Tp> class _GBase<_Array<_Tp> > {
+ public:
+ typedef _Tp value_type;
+
+ _GBase (_Array<_Tp> __a, const valarray<size_t>& __i)
+ : _M_array (__a), _M_index(__i) {}
+ value_type operator[] (size_t __i) const
+ { return _M_array._M_data[_M_index[__i]]; }
+ size_t size () const { return _M_index.size(); }
+
+ private:
+ const _Array<_Tp> _M_array;
+ const valarray<size_t>& _M_index;
+ };
+
+ template<class _Dom> struct _GClos<_Expr,_Dom> : _GBase<_Dom> {
+ typedef _GBase<_Dom> _Base;
+ typedef typename _Base::value_type value_type;
+
+ _GClos (const _Dom& __e, const valarray<size_t>& __i)
+ : _Base (__e, __i) {}
+ };
+
+ template<typename _Tp>
+ struct _GClos<_ValArray,_Tp> : _GBase<_Array<_Tp> > {
+ typedef _GBase<_Array<_Tp> > _Base;
+ typedef typename _Base::value_type value_type;
+
+ _GClos (_Array<_Tp> __a, const valarray<size_t>& __i)
+ : _Base (__a, __i) {}
+ };
+
+ //
+ // indirect_array closure
+ //
+
+ template<class _Dom> class _IBase {
+ public:
+ typedef typename _Dom::value_type value_type;
+
+ _IBase (const _Dom& __e, const valarray<size_t>& __i)
+ : _M_expr (__e), _M_index (__i) {}
+ value_type operator[] (size_t __i) const
+ { return _M_expr[_M_index[__i]]; }
+ size_t size() const { return _M_index.size(); }
+
+ private:
+ const _Dom& _M_expr;
+ const valarray<size_t>& _M_index;
+ };
+
+ template<class _Dom> struct _IClos<_Expr,_Dom> : _IBase<_Dom> {
+ typedef _IBase<_Dom> _Base;
+ typedef typename _Base::value_type value_type;
+
+ _IClos (const _Dom& __e, const valarray<size_t>& __i)
+ : _Base (__e, __i) {}
+ };
+
+ template<typename _Tp>
+ struct _IClos<_ValArray,_Tp> : _IBase<valarray<_Tp> > {
+ typedef _IBase<valarray<_Tp> > _Base;
+ typedef _Tp value_type;
+
+ _IClos (const valarray<_Tp>& __a, const valarray<size_t>& __i)
+ : _Base (__a, __i) {}
+ };
+
+ //
+ // class _Expr
+ //
+ template<class _Clos, typename _Tp> class _Expr {
+ public:
+ typedef _Tp value_type;
+
+ _Expr (const _Clos&);
+
+ const _Clos& operator() () const;
+
+ value_type operator[] (size_t) const;
+ valarray<value_type> operator[] (slice) const;
+ valarray<value_type> operator[] (const gslice&) const;
+ valarray<value_type> operator[] (const valarray<bool>&) const;
+ valarray<value_type> operator[] (const valarray<size_t>&) const;
+
+ _Expr<_UnClos<_Unary_plus,_Expr,_Clos>, value_type>
+ operator+ () const;
+
+ _Expr<_UnClos<negate,_Expr,_Clos>, value_type>
+ operator- () const;
+
+ _Expr<_UnClos<_Bitwise_not,_Expr,_Clos>, value_type>
+ operator~ () const;
+
+ _Expr<_UnClos<logical_not,_Expr,_Clos>, bool>
+ operator! () const;
+
+ size_t size () const;
+ value_type sum () const;
+
+ valarray<value_type> shift (int) const;
+ valarray<value_type> cshift (int) const;
+// _Meta<_ApplyFunctionWithValue<_Expr>, value_type>
+// apply (value_type _M_func (value_type)) const;
+// _Meta<_ApplyFunctionWithConstRef<_Expr>, value_type>
+// apply (value_type _M_func (const value_type&)) const;
+
+ private:
+ const _Clos _M_closure;
+ };
+
+ template<class _Clos, typename _Tp>
+ inline
+ _Expr<_Clos,_Tp>::_Expr (const _Clos& __c) : _M_closure(__c) {}
+
+ template<class _Clos, typename _Tp>
+ inline const _Clos&
+ _Expr<_Clos,_Tp>::operator() () const
+ { return _M_closure; }
+
+ template<class _Clos, typename _Tp>
+ inline _Tp
+ _Expr<_Clos,_Tp>::operator[] (size_t __i) const
+ { return _M_closure[__i]; }
+
+ template<class _Clos, typename _Tp>
+ inline valarray<_Tp>
+ _Expr<_Clos,_Tp>::operator[] (slice __s) const
+ { return _M_closure[__s]; }
+
+ template<class _Clos, typename _Tp>
+ inline valarray<_Tp>
+ _Expr<_Clos,_Tp>::operator[] (const gslice& __gs) const
+ { return _M_closure[__gs]; }
+
+ template<class _Clos, typename _Tp>
+ inline valarray<_Tp>
+ _Expr<_Clos,_Tp>::operator[] (const valarray<bool>& __m) const
+ { return _M_closure[__m]; }
+
+ template<class _Clos, typename _Tp>
+ inline valarray<_Tp>
+ _Expr<_Clos,_Tp>::operator[] (const valarray<size_t>& __i) const
+ { return _M_closure[__i]; }
+
+ template<class _Clos, typename _Tp>
+ inline size_t
+ _Expr<_Clos,_Tp>::size () const { return _M_closure.size (); }
+
+ // XXX: replace this with a more robust summation algorithm.
+ template<class _Clos, typename _Tp>
+ inline _Tp
+ _Expr<_Clos,_Tp>::sum () const
+ {
+ size_t __n = _M_closure.size();
+ if (__n == 0) return _Tp();
+ else {
+ _Tp __s = _M_closure[--__n];
+ while (__n != 0) __s += _M_closure[--__n];
+ return __s;
+ }
+ }
+
+ template<class _Dom, typename _Tp>
+ inline _Tp
+ min (const _Expr<_Dom,_Tp>& __e)
+ {
+ size_t __s = __e.size ();
+ _Tp __m = __e[0];
+ for (size_t __i=1; __i<__s; ++__i)
+ if (__m > __e[__i]) __m = __e[__i];
+ return __m;
+ }
+
+ template<class _Dom, typename _Tp>
+ inline _Tp
+ max (const _Expr<_Dom,_Tp>& __e)
+ {
+ size_t __s = __e.size();
+ _Tp __m = __e[0];
+ for (size_t __i=1; __i<__s; ++__i)
+ if (__m < __e[__i]) __m = __e[__i];
+ return __m;
+ }
+
+ template<class _Dom, typename _Tp>
+ inline _Expr<_UnClos<logical_not,_Expr,_Dom>, bool>
+ _Expr<_Dom,_Tp>::operator! () const
+ {
+ typedef _UnClos<logical_not,_Expr,_Dom> _Closure;
+ return _Expr<_Closure,_Tp> (_Closure(this->_M_closure));
+ }
+
+#define _DEFINE_EXPR_UNARY_OPERATOR(_Op, _Name) \
+template<class _Dom, typename _Tp> \
+inline _Expr<_UnClos<_Name,_Expr,_Dom>,_Tp> \
+_Expr<_Dom,_Tp>::operator##_Op () const \
+{ \
+ typedef _UnClos<_Name,_Expr,_Dom> _Closure; \
+ return _Expr<_Closure,_Tp> (_Closure (this->_M_closure)); \
+}
+
+ _DEFINE_EXPR_UNARY_OPERATOR(+, _Unary_plus)
+ _DEFINE_EXPR_UNARY_OPERATOR(-, negate)
+ _DEFINE_EXPR_UNARY_OPERATOR(~, _Bitwise_not)
+
+#undef _DEFINE_EXPR_UNARY_OPERATOR
+
+
+#define _DEFINE_EXPR_BINARY_OPERATOR(_Op, _Name) \
+template<class _Dom1, class _Dom2> \
+inline _Expr<_BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2>, \
+ typename _Name<typename _Dom1::value_type>::result_type> \
+operator##_Op (const _Expr<_Dom1,typename _Dom1::value_type>& __v, \
+ const _Expr<_Dom2,typename _Dom2::value_type>& __w) \
+{ \
+ typedef typename _Dom1::value_type _Arg; \
+ typedef typename _Name<_Arg>::result_type _Value; \
+ typedef _BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2> _Closure; \
+ return _Expr<_Closure,_Value> (_Closure (__v (), __w ())); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinClos<_Name,_Expr,_Constant,_Dom,typename _Dom::value_type>, \
+ typename _Name<typename _Dom::value_type>::result_type> \
+operator##_Op (const _Expr<_Dom,typename _Dom::value_type>& __v, \
+ const typename _Dom::value_type& __t) \
+{ \
+ typedef typename _Dom::value_type _Arg; \
+ typedef typename _Name<_Arg>::result_type _Value; \
+ typedef _BinClos<_Name,_Expr,_Constant,_Dom,_Arg> _Closure; \
+ return _Expr<_Closure,_Value> (_Closure (__v (), __t)); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinClos<_Name,_Constant,_Expr,typename _Dom::value_type,_Dom>, \
+ typename _Name<typename _Dom::value_type>::result_type> \
+operator##_Op (const typename _Dom::value_type& __t, \
+ const _Expr<_Dom,typename _Dom::value_type>& __v) \
+{ \
+ typedef typename _Dom::value_type _Arg; \
+ typedef typename _Name<_Arg>::result_type _Value; \
+ typedef _BinClos<_Name,_Constant,_Expr,_Arg,_Dom> _Closure; \
+ return _Expr<_Closure,_Value> (_Closure (__t, __v ())); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinClos<_Name,_Expr,_ValArray,_Dom,typename _Dom::value_type>, \
+ typename _Name<typename _Dom::value_type>::result_type> \
+operator##_Op (const _Expr<_Dom,typename _Dom::value_type>& __e, \
+ const valarray<typename _Dom::value_type>& __v) \
+{ \
+ typedef typename _Dom::value_type _Arg; \
+ typedef typename _Name<_Arg>::result_type _Value; \
+ typedef _BinClos<_Name,_Expr,_ValArray,_Dom,_Arg> _Closure; \
+ return _Expr<_Closure,_Value> (_Closure (__e (), __v)); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinClos<_Name,_ValArray,_Expr,typename _Dom::value_type,_Dom>, \
+ typename _Name<typename _Dom::value_type>::result_type> \
+operator##_Op (const valarray<typename _Dom::value_type>& __v, \
+ const _Expr<_Dom,typename _Dom::value_type>& __e) \
+{ \
+ typedef typename _Dom::value_type _Tp; \
+ typedef typename _Name<_Tp>::result_type _Value; \
+ typedef _BinClos<_Name,_ValArray,_Expr,_Tp,_Dom> _Closure; \
+ return _Expr<_Closure,_Value> (_Closure (__v, __e ())); \
+}
+
+ _DEFINE_EXPR_BINARY_OPERATOR(+, plus)
+ _DEFINE_EXPR_BINARY_OPERATOR(-, minus)
+ _DEFINE_EXPR_BINARY_OPERATOR(*, multiplies)
+ _DEFINE_EXPR_BINARY_OPERATOR(/, divides)
+ _DEFINE_EXPR_BINARY_OPERATOR(%, modulus)
+ _DEFINE_EXPR_BINARY_OPERATOR(^, _Bitwise_xor)
+ _DEFINE_EXPR_BINARY_OPERATOR(&, _Bitwise_and)
+ _DEFINE_EXPR_BINARY_OPERATOR(|, _Bitwise_or)
+ _DEFINE_EXPR_BINARY_OPERATOR(<<, _Shift_left)
+ _DEFINE_EXPR_BINARY_OPERATOR(>>, _Shift_right)
+
+#undef _DEFINE_EXPR_BINARY_OPERATOR
+
+#define _DEFINE_EXPR_RELATIONAL_OPERATOR(_Op, _Name) \
+template<class _Dom1, class _Dom2> \
+inline _Expr<_BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2>, bool> \
+operator##_Op (const _Expr<_Dom1,typename _Dom1::value_type>& __v, \
+ const _Expr<_Dom2,typename _Dom2::value_type>& __w) \
+{ \
+ typedef typename _Dom1::value_type _Arg; \
+ typedef _BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2> _Closure; \
+ return _Expr<_Closure,bool> (_Closure (__v (), __w ())); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinClos<_Name,_Expr,_Constant,_Dom,typename _Dom::value_type>, \
+ bool> \
+operator##_Op (const _Expr<_Dom,typename _Dom::value_type>& __v, \
+ const typename _Dom::value_type& __t) \
+{ \
+ typedef typename _Dom::value_type _Arg; \
+ typedef _BinClos<_Name,_Expr,_Constant,_Dom,_Arg> _Closure; \
+ return _Expr<_Closure,bool> (_Closure (__v (), __t)); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinClos<_Name,_Constant,_Expr,typename _Dom::value_type,_Dom>, \
+ bool> \
+operator##_Op (const typename _Dom::value_type& __t, \
+ const _Expr<_Dom,typename _Dom::value_type>& __v) \
+{ \
+ typedef typename _Dom::value_type _Arg; \
+ typedef _BinClos<_Name,_Constant,_Expr,_Arg,_Dom> _Closure; \
+ return _Expr<_Closure,bool> (_Closure (__t, __v ())); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinClos<_Name,_Expr,_ValArray,_Dom,typename _Dom::value_type>, \
+ bool> \
+operator##_Op (const _Expr<_Dom,typename _Dom::value_type>& __e, \
+ const valarray<typename _Dom::value_type>& __v) \
+{ \
+ typedef typename _Dom::value_type _Tp; \
+ typedef _BinClos<_Name,_Expr,_ValArray,_Dom,_Tp> _Closure; \
+ return _Expr<_Closure,bool> (_Closure (__e (), __v)); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinClos<_Name,_ValArray,_Expr,typename _Dom::value_type,_Dom>, \
+ bool> \
+operator##_Op (const valarray<typename _Dom::value_type>& __v, \
+ const _Expr<_Dom,typename _Dom::value_type>& __e) \
+{ \
+ typedef typename _Dom::value_type _Tp; \
+ typedef _BinClos<_Name,_ValArray,_Expr,_Tp,_Dom> _Closure; \
+ return _Expr<_Closure,bool> (_Closure (__v, __e ())); \
+}
+
+ _DEFINE_EXPR_RELATIONAL_OPERATOR(&&, logical_and)
+ _DEFINE_EXPR_RELATIONAL_OPERATOR(||, logical_or)
+ _DEFINE_EXPR_RELATIONAL_OPERATOR(==, equal_to)
+ _DEFINE_EXPR_RELATIONAL_OPERATOR(!=, not_equal_to)
+ _DEFINE_EXPR_RELATIONAL_OPERATOR(<, less)
+ _DEFINE_EXPR_RELATIONAL_OPERATOR(>, greater)
+ _DEFINE_EXPR_RELATIONAL_OPERATOR(<=, less_equal)
+ _DEFINE_EXPR_RELATIONAL_OPERATOR(>=, greater_equal)
+
+#undef _DEFINE_EXPR_RELATIONAL_OPERATOR
+
+
+
+#define _DEFINE_EXPR_UNARY_FUNCTION(_Name) \
+template<class _Dom> \
+inline _Expr<_UnFunClos<_Expr,_Dom>,typename _Dom::value_type> \
+_Name(const _Expr<_Dom,typename _Dom::value_type>& __e) \
+{ \
+ typedef typename _Dom::value_type _Tp; \
+ typedef _UnFunClos<_Expr,_Dom> _Closure; \
+ return _Expr<_Closure,_Tp>(_Closure(__e(), (_Tp(*)(_Tp))(&_Name))); \
+} \
+ \
+template<typename _Tp> \
+inline _Expr<_UnFunClos<_ValArray,_Tp>,_Tp> \
+_Name(const valarray<_Tp>& __v) \
+{ \
+ typedef _UnFunClos<_ValArray,_Tp> _Closure; \
+ return _Expr<_Closure,_Tp> (_Closure (__v, (_Tp(*)(_Tp))(&_Name))); \
+}
+
+
+ _DEFINE_EXPR_UNARY_FUNCTION(abs)
+ _DEFINE_EXPR_UNARY_FUNCTION(cos)
+ _DEFINE_EXPR_UNARY_FUNCTION(acos)
+ _DEFINE_EXPR_UNARY_FUNCTION(cosh)
+ _DEFINE_EXPR_UNARY_FUNCTION(sin)
+ _DEFINE_EXPR_UNARY_FUNCTION(asin)
+ _DEFINE_EXPR_UNARY_FUNCTION(sinh)
+ _DEFINE_EXPR_UNARY_FUNCTION(tan)
+ _DEFINE_EXPR_UNARY_FUNCTION(tanh)
+ _DEFINE_EXPR_UNARY_FUNCTION(atan)
+ _DEFINE_EXPR_UNARY_FUNCTION(exp)
+ _DEFINE_EXPR_UNARY_FUNCTION(log)
+ _DEFINE_EXPR_UNARY_FUNCTION(log10)
+ _DEFINE_EXPR_UNARY_FUNCTION(sqrt)
+
+#undef _DEFINE_EXPR_UNARY_FUNCTION
+
+
+#define _DEFINE_EXPR_BINARY_FUNCTION(_Name) \
+template<class _Dom1, class _Dom2> \
+inline _Expr<_BinFunClos<_Expr,_Expr,_Dom1,_Dom2>,typename _Dom1::value_type>\
+_Name (const _Expr<_Dom1,typename _Dom1::value_type>& __e1, \
+ const _Expr<_Dom2,typename _Dom2::value_type>& __e2) \
+{ \
+ typedef typename _Dom1::value_type _Tp; \
+ typedef _BinFunClos<_Expr,_Expr,_Dom1,_Dom2> _Closure; \
+ return _Expr<_Closure,_Tp> \
+ (_Closure (__e1 (), __e2 (), (_Tp(*)(_Tp, _Tp))(&_Name))); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinFunClos<_Expr,_ValArray,_Dom,typename _Dom::value_type>, \
+ typename _Dom::value_type> \
+_Name (const _Expr<_Dom,typename _Dom::value_type>& __e, \
+ const valarray<typename _Dom::value_type>& __v) \
+{ \
+ typedef typename _Dom::value_type _Tp; \
+ typedef _BinFunClos<_Expr,_ValArray,_Dom,_Tp> _Closure; \
+ return _Expr<_Closure,_Tp> \
+ (_Closure (__e (), __v, (_Tp(*)(_Tp, _Tp))(&_Name))); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinFunClos<_ValArray,_Expr,typename _Dom::value_type,_Dom>, \
+ typename _Dom::value_type> \
+_Name (const valarray<typename _Dom::valarray>& __v, \
+ const _Expr<_Dom,typename _Dom::value_type>& __e) \
+{ \
+ typedef typename _Dom::value_type _Tp; \
+ typedef _BinFunClos<_ValArray,_Expr,_Tp,_Dom> _Closure; \
+ return _Expr<_Closure,_Tp> \
+ (_Closure (__v, __e (), (_Tp(*)(_Tp, _Tp))(&_Name))); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinFunClos<_Expr,_Constant,_Dom,typename _Dom::value_type>, \
+ typename _Dom::value_type> \
+_Name (const _Expr<_Dom, typename _Dom::value_type>& __e, \
+ const typename _Dom::value_type& __t) \
+{ \
+ typedef typename _Dom::value_type _Tp; \
+ typedef _BinFunClos<_Expr,_Constant,_Dom,_Tp> _Closure; \
+ return _Expr<_Closure,_Tp> \
+ (_Closure (__e (), __t, (_Tp(*)(_Tp, _Tp))(&_Name))); \
+} \
+ \
+template<class _Dom> \
+inline _Expr<_BinFunClos<_Constant,_Expr,typename _Dom::value_type,_Dom>, \
+ typename _Dom::value_type> \
+_Name (const typename _Dom::value_type& __t, \
+ const _Expr<_Dom,typename _Dom::value_type>& __e) \
+{ \
+ typedef typename _Dom::value_type _Tp; \
+ typedef _BinFunClos<_Constant,_Expr,_Tp,_Dom> _Closure; \
+ return _Expr<_Closure,_Tp> \
+ (_Closure (__t, __e (), (_Tp(*)(_Tp, _Tp))(&_Name))); \
+} \
+ \
+template<typename _Tp> \
+inline _Expr<_BinFunClos<_ValArray,_ValArray,_Tp,_Tp>, _Tp> \
+_Name (const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
+{ \
+ typedef _BinFunClos<_ValArray,_ValArray,_Tp,_Tp> _Closure; \
+ return _Expr<_Closure,_Tp> \
+ (_Closure (__v, __w, (_Tp(*)(_Tp,_Tp))(&_Name))); \
+} \
+ \
+template<typename _Tp> \
+inline _Expr<_BinFunClos<_ValArray,_Constant,_Tp,_Tp>,_Tp> \
+_Name (const valarray<_Tp>& __v, const _Tp& __t) \
+{ \
+ typedef _BinFunClos<_ValArray,_Constant,_Tp,_Tp> _Closure; \
+ return _Expr<_Closure,_Tp> \
+ (_Closure (__v, __t, (_Tp(*)(_Tp,_Tp))(&_Name))); \
+} \
+ \
+template<typename _Tp> \
+inline _Expr<_BinFunClos<_Constant,_ValArray,_Tp,_Tp>,_Tp> \
+_Name (const _Tp& __t, const valarray<_Tp>& __v) \
+{ \
+ typedef _BinFunClos<_Constant,_ValArray,_Tp,_Tp> _Closure; \
+ return _Expr<_Closure,_Tp> \
+ (_Closure (__t, __v, (_Tp(*)(_Tp,_Tp))(&_Name))); \
+}
+
+_DEFINE_EXPR_BINARY_FUNCTION(atan2)
+_DEFINE_EXPR_BINARY_FUNCTION(pow)
+
+#undef _DEFINE_EXPR_BINARY_FUNCTION
+
+} // std::
+
+
+#endif /* _CPP_VALARRAY_META_H */
+
+// Local Variables:
+// mode:c++
+// End: