Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 4679 → Rev 4680

/contrib/media/updf/include/bits/basic_file.h
0,0 → 1,252
// Wrapper of C-language FILE struct -*- C++ -*-
 
// Copyright (C) 1999, 2000, 2001 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
 
#pragma GCC system_header
 
#include <bits/c++config.h>
#include <bits/std_ios.h>
 
namespace std
{
// Ulrich is going to make some detailed comment here, explaining
// all this unpleasantness, providing detailed performance analysis
// as to why we have to do all this lame vtable hacking instead of a
// sane, function-based approach. This verbiage will provide a clear
// and detailed description of the whole object-layout,
// vtable-swapping, sordid history of this hack.
template<typename _CharT>
struct __basic_file_base: public __c_file_type
{
virtual
~__basic_file_base() { };
 
virtual int
overflow(int __c = EOF) = 0;
 
virtual int
underflow() = 0;
 
virtual int
uflow() = 0;
 
virtual int
pbackfail(int __c) = 0;
 
virtual streamsize
xsputn(const _CharT* __s, streamsize __n) = 0;
 
virtual streamsize
xsgetn(_CharT* __s, streamsize __n) = 0;
 
virtual streamoff
seekoff(streamoff __off, ios_base::seekdir __way,
ios_base::openmode __mode = ios_base::in | ios_base::out) = 0;
 
virtual streamoff
seekpos(streamoff __pos,
ios_base::openmode __mode = ios_base::in | ios_base::out) = 0;
 
virtual streambuf*
setbuf(_CharT* __b, int __len) = 0;
 
virtual int
sync() = 0;
 
virtual int
doallocate() = 0;
 
virtual streamsize
sys_read(_CharT* __s, streamsize __n) = 0;
 
virtual streamsize
sys_write(const _CharT* __s, streamsize __n) = 0;
 
virtual streamoff
sys_seek(streamoff __off, ios_base::seekdir __way) = 0;
 
virtual int
sys_close() = 0;
 
virtual int
sys_stat(void* __v) = 0;
 
virtual int
showmanyc() = 0;
 
virtual void
imbue(void* __v) = 0;
};
 
// 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.
template<typename _CharT>
#ifdef _GLIBCPP_BASIC_FILE_INHERITANCE
class __basic_file: public __basic_file_base<_CharT>
#else
class __basic_file
#endif
{
#if _GLIBCPP_BASIC_FILE_ENCAPSULATION
__c_file_type* _M_cfile;
bool _M_cfile_created;
#else
# ifdef _GLIBCPP_USE_WCHAR_T
__c_wfile_type _M_wfile;
# endif
#endif
 
public:
__basic_file(__c_lock* __lock = 0);
void
_M_open_mode(ios_base::openmode __mode, int& __p_mode, int& __rw_mode,
char* __c_mode);
// Equivalent 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(__c_file_type* __file, ios_base::openmode __mode);
 
_CharT
sys_getc();
 
_CharT
sys_ungetc(_CharT);
 
__basic_file*
close();
 
bool
is_open();
 
// 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
// pointers and associated data members correctly and manages its
// relation to the external byte sequence.
virtual streamsize
xsputn(const _CharT* __s, streamsize __n);
 
// A complex "read" function that sets all of __c_file_type's
// pointers and associated data members correctly and manages its
// relation to the external byte sequence.
virtual streamsize
xsgetn(_CharT* __s, streamsize __n);
 
// A complex "seekoff" function that sets all of __c_file_type's
// pointers and associated data members correctly and manages its
// relation to the external byte sequence.
virtual streamoff
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 its
// relation to the external byte sequence.
virtual streamoff
seekpos(streamoff __pos,
ios_base::openmode __mode = ios_base::in | ios_base::out);
 
virtual streambuf*
setbuf(_CharT* __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(_CharT* __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 _CharT* __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 streamoff
sys_seek(streamoff __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
 
// Now include the bits that are dependant on the underlying I/O
// model chosen at configure time.
#include <bits/basic_file_model.h>
 
#endif // _CPP_BASIC_FILE
/contrib/media/updf/include/bits/basic_ios.h
0,0 → 1,218
// Iostreams base classes -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2001 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
 
#pragma GCC system_header
 
#include <bits/sbuf_iter.h>
#include <bits/locale_facets.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;
typedef ostreambuf_iterator<_CharT, _Traits> __ostreambuf_iter;
typedef num_put<_CharT, __ostreambuf_iter> __numput_type;
typedef istreambuf_iterator<_CharT, _Traits> __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_ios_fctype;
// 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_ios_fctype; }
 
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_ios_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);
 
bool
_M_check_facet(const locale::facet* __f)
{
bool __ret = false;
if (__f)
__ret = true;
else
__throw_bad_cast();
return __ret;
}
 
void
_M_cache_facets(const locale& __loc);
};
} // namespace std
 
#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
# define export
#include <bits/basic_ios.tcc>
#endif
 
#endif /* _CPP_BITS_BASICIOS_H */
 
 
/contrib/media/updf/include/bits/basic_ios.tcc
0,0 → 1,145
// basic_ios locale and locale-related member functions -*- C++ -*-
 
// Copyright (C) 1999, 2001 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_ios_fctype->narrow(__c, __dfault); }
 
template<typename _CharT, typename _Traits>
_CharT
basic_ios<_CharT, _Traits>::widen(char __c) const
{ return _M_ios_fctype->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_cache_facets(__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();
_M_cache_facets(_M_ios_locale);
_M_tie = 0;
_M_fill = this->widen(' ');
_M_exception = goodbit;
_M_streambuf = __sb;
_M_streambuf_state = __sb ? goodbit : badbit;
}
 
template<typename _CharT, typename _Traits>
void
basic_ios<_CharT, _Traits>::_M_cache_facets(const locale& __loc)
{
if (has_facet<__ctype_type>(__loc))
_M_ios_fctype = &use_facet<__ctype_type>(__loc);
// Should be filled in by ostream and istream, respectively.
if (has_facet<__numput_type>(__loc))
_M_fnumput = &use_facet<__numput_type>(__loc);
if (has_facet<__numget_type>(__loc))
_M_fnumget = &use_facet<__numget_type>(__loc);
}
} // namespace std
 
#endif // _CPP_BITS_BASICIOS_TCC
 
 
 
/contrib/media/updf/include/bits/basic_string.h
0,0 → 1,1045
// Components for manipulating sequences of characters -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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
 
#pragma GCC system_header
 
#include <bits/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;
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_references 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;
 
// (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 const size_type _S_max_size;
static const _CharT _S_terminal;
 
size_type _M_length;
size_type _M_capacity;
_Atomic_word _M_references;
bool
_M_is_leaked() const
{ return _M_references < 0; }
 
bool
_M_is_shared() const
{ return _M_references > 0; }
 
void
_M_set_leaked()
{ _M_references = -1; }
 
void
_M_set_sharable()
{ _M_references = 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 (__exchange_and_add(&_M_references, -1) <= 0)
_M_destroy(__a);
} // XXX MT
 
void
_M_destroy(const _Alloc&) throw();
 
_CharT*
_M_refcopy() throw()
{
__atomic_add(&_M_references, 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.
};
 
public:
// Data Members (public):
// 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:
// Data Members (private):
mutable _Alloc_hider _M_dataplus;
 
// 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)];
 
_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
{
if (__pos > this->size())
__throw_out_of_range("basic_string::_M_check");
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 __k1, _Iterator __k2)
{
for (; __k1 != __k2; ++__k1, ++__p)
traits_type::assign(*__p, *__k1); //these types are off
}
 
static void
_S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
{ _S_copy_chars(__p, __k1.base(), __k2.base()); }
 
static void
_S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
{ _S_copy_chars(__p, __k1.base(), __k2.base()); }
static void
_S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
{ traits_type::copy(__p, __k1, __k2 - __k1); }
 
static void
_S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
{ traits_type::copy(__p, __k1, __k2 - __k1); }
 
void
_M_mutate(size_type __pos, size_type __len1, size_type __len2);
 
void
_M_leak_hard();
 
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
{
if (__n >= this->size())
__throw_out_of_range("basic_string::at");
return _M_data()[__n];
}
 
reference
at(size_type __n)
{
if (__n >= size())
__throw_out_of_range("basic_string::at");
_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 __k1, _InputIterator __k2)
{ return _M_replace(__i1, __i2, __k1, __k2,
typename iterator_traits<_InputIterator>::iterator_category()); }
 
private:
template<class _InputIterator>
basic_string&
_M_replace(iterator __i1, iterator __i2, _InputIterator __k1,
_InputIterator __k2, input_iterator_tag);
 
template<class _FwdIterator>
basic_string&
_M_replace(iterator __i1, iterator __i2, _FwdIterator __k1,
_FwdIterator __k2, 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
{
if (__pos > this->size())
__throw_out_of_range("basic_string::substr");
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;
 
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 5. String::compare specification questionable
int
compare(size_type __pos, size_type __n1, const _CharT* __s) const;
 
int
compare(size_type __pos, size_type __n1, const _CharT* __s,
size_type __n2) const;
#endif
};
 
 
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;
typedef typename __string_type::size_type __size_type;
__string_type __str(__lhs);
__str.append(__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 */
/contrib/media/updf/include/bits/basic_string.tcc
0,0 → 1,862
// Components for manipulating sequences of characters -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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>
const _CharT
basic_string<_CharT, _Traits, _Alloc>::
_Rep::_S_terminal = _CharT();
 
template<typename _CharT, typename _Traits, typename _Alloc>
const typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
_Rep::_S_max_size = (((npos - sizeof(_Rep))/sizeof(_CharT)) - 1) / 4;
 
template<typename _CharT, typename _Traits, typename _Alloc>
const typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::npos;
 
// 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 basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::_S_empty_rep_storage[
(sizeof(_Rep) + sizeof(_CharT) + sizeof(size_type) - 1)/sizeof(size_type)];
 
// 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_exception_again;
}
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_exception_again;
}
__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_exception_again;
}
__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_exception_again;
}
_M_rep()->_M_dispose(__a);
_M_data(__r->_M_refdata());
}
else if (__how_much && __len1 != __len2)
{
// 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())
{
if (__res > this->max_size())
__throw_length_error("basic_string::reserve");
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)
{
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 83. String::npos vs. string::max_size()
if (__capacity > _S_max_size)
#else
if (__capacity == npos)
#endif
__throw_length_error("basic_string::_S_create");
 
// 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_exception_again;
}
}
__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;
}
template<typename _CharT, typename _Traits, typename _Alloc>
void
basic_string<_CharT, _Traits, _Alloc>::resize(size_type __n, _CharT __c)
{
if (__n > max_size())
__throw_length_error("basic_string::resize");
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 __k1,
_InputIter __k2, input_iterator_tag)
{
basic_string __s(__k1, __k2);
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 __k1,
_ForwardIter __k2, forward_iterator_tag)
{
size_type __dold = __i2 - __i1;
size_type __dmax = this->max_size();
size_type __dnew = static_cast<size_type>(distance(__k1, __k2));
 
if (__dmax <= __dnew)
__throw_length_error("basic_string::_M_replace");
size_type __off = __i1 - _M_ibegin();
_M_mutate(__off, __dold, __dnew);
// Invalidated __i1, __i2
if (__dnew)
_S_copy_chars(_M_data() + __off, __k1, __k2);
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;
typedef typename __string_type::size_type __size_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;
typedef typename __string_type::size_type __size_type;
__string_type __str;
__size_type __len = __rhs.size();
__str.reserve(__len + 1);
__str.append(__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();
if (max_size() - (this->size() - __n1) <= __n2)
__throw_length_error("basic_string::replace");
_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
{
if (__pos > this->size())
__throw_out_of_range("basic_string::copy");
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;
}
 
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_type __size = this->size();
size_t __xpos = __pos;
const _CharT* __data = _M_data();
for (; __xpos + __n <= __size; ++__xpos)
if (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 __ret = npos;
if (__pos < __size)
{
const _CharT* __data = _M_data();
size_type __n = __size - __pos;
const _CharT* __p = traits_type::find(__data + __pos, __n, __c);
if (__p)
__ret = __p - __data;
}
return __ret;
}
 
 
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)
{
__pos = std::min(__size - __n ,__pos);
const _CharT* __data = _M_data();
do
{
if (traits_type::compare(__data + __pos, __s, __n) == 0)
return __pos;
}
while (__pos-- > 0);
}
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
{
for (; __n && __pos < this->size(); ++__pos)
{
const _CharT* __p = traits_type::find(__s, __n, _M_data()[__pos]);
if (__p)
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
{
if (traits_type::find(__s, __n, _M_data()[__size]))
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 (!traits_type::find(__s, __n, _M_data()[__xpos]))
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 < this->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 (!traits_type::find(__s, __n, _M_data()[__size]))
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();
if (__pos > __size)
__throw_out_of_range("basic_string::compare");
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();
if (__pos1 > __size || __pos2 > __osize)
__throw_out_of_range("basic_string::compare");
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) const
{
size_type __size = this->size();
if (__pos > __size)
__throw_out_of_range("basic_string::compare");
size_type __osize = traits_type::length(__s);
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<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();
if (__pos > __size)
__throw_out_of_range("basic_string::compare");
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();
}
} // namespace std
 
#endif
/contrib/media/updf/include/bits/boost_concept_check.h
0,0 → 1,895
//
// (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
//
 
// GCC Note: based on version 1.12.0 of the Boost library.
#ifndef _GLIBCPP_BOOST_CONCEPT_CHECK
#define _GLIBCPP_BOOST_CONCEPT_CHECK 1
 
#pragma GCC system_header
#include <bits/stl_iterator_base_types.h> // for traits and tags
#include <utility> // for pair<>
 
 
namespace __gnu_cxx
{
 
#define _IsUnused __attribute__ ((__unused__))
 
template <class _Concept>
void __function_requires()
{
void (_Concept::*__x)() _IsUnused = &_Concept::__constraints;
}
 
 
// ??? Should the "concept_checking*" structs begin with more than _ ?
#define _GLIBCPP_CLASS_REQUIRES(_type_var, _ns, _concept) \
typedef void (_ns::_concept <_type_var>::* _func##_type_var##_concept)(); \
template <_func##_type_var##_concept _Tp1> \
struct _concept_checking##_type_var##_concept { }; \
typedef _concept_checking##_type_var##_concept< \
&_ns::_concept <_type_var>::__constraints> \
_concept_checking_typedef##_type_var##_concept
 
#define _GLIBCPP_CLASS_REQUIRES2(_type_var1, _type_var2, _ns, _concept) \
typedef void (_ns::_concept <_type_var1,_type_var2>::* _func##_type_var1##_type_var2##_concept)(); \
template <_func##_type_var1##_type_var2##_concept _Tp1> \
struct _concept_checking##_type_var1##_type_var2##_concept { }; \
typedef _concept_checking##_type_var1##_type_var2##_concept< \
&_ns::_concept <_type_var1,_type_var2>::__constraints> \
_concept_checking_typedef##_type_var1##_type_var2##_concept
 
#define _GLIBCPP_CLASS_REQUIRES3(_type_var1, _type_var2, _type_var3, _ns, _concept) \
typedef void (_ns::_concept <_type_var1,_type_var2,_type_var3>::* _func##_type_var1##_type_var2##_type_var3##_concept)(); \
template <_func##_type_var1##_type_var2##_type_var3##_concept _Tp1> \
struct _concept_checking##_type_var1##_type_var2##_type_var3##_concept { }; \
typedef _concept_checking##_type_var1##_type_var2##_type_var3##_concept< \
&_ns::_concept <_type_var1,_type_var2,_type_var3>::__constraints> \
_concept_checking_typedef##_type_var1##_type_var2##_type_var3##_concept
 
#define _GLIBCPP_CLASS_REQUIRES4(_type_var1, _type_var2, _type_var3, _type_var4, _ns, _concept) \
typedef void (_ns::_concept <_type_var1,_type_var2,_type_var3,_type_var4>::* _func##_type_var1##_type_var2##_type_var3##_type_var4##_concept)(); \
template <_func##_type_var1##_type_var2##_type_var3##_type_var4##_concept _Tp1> \
struct _concept_checking##_type_var1##_type_var2##_type_var3##_type_var4##_concept { }; \
typedef _concept_checking##_type_var1##_type_var2##_type_var3##_type_var4##_concept< \
&_ns::_concept <_type_var1,_type_var2,_type_var3,_type_var4>::__constraints> \
_concept_checking_typedef##_type_var1##_type_var2##_type_var3##_type_var4##_concept
 
 
template <class _Tp1, class _Tp2>
struct _Aux_require_same { };
 
template <class _Tp>
struct _Aux_require_same<_Tp,_Tp> { typedef _Tp _Type; };
 
template <class _Tp1, class _Tp2>
struct _SameTypeConcept
{
void __constraints() {
typedef typename _Aux_require_same<_Tp1, _Tp2>::_Type _Required;
}
};
 
template <class _Tp>
struct _IntegerConcept {
void __constraints() {
__error_type_must_be_an_integer_type();
}
};
template <> struct _IntegerConcept<short> { void __constraints() {} };
template <> struct _IntegerConcept<unsigned short> { void __constraints(){} };
template <> struct _IntegerConcept<int> { void __constraints() {} };
template <> struct _IntegerConcept<unsigned int> { void __constraints() {} };
template <> struct _IntegerConcept<long> { void __constraints() {} };
template <> struct _IntegerConcept<unsigned long> { void __constraints() {} };
#ifdef _GLIBCPP_USE_LONG_LONG
template <> struct _IntegerConcept<long long> { void __constraints() {} };
template <> struct _IntegerConcept<unsigned long long>
{ void __constraints() {} };
#endif
 
template <class _Tp>
struct _SignedIntegerConcept {
void __constraints() {
__error_type_must_be_a_signed_integer_type();
}
};
template <> struct _SignedIntegerConcept<short> { void __constraints() {} };
template <> struct _SignedIntegerConcept<int> { void __constraints() {} };
template <> struct _SignedIntegerConcept<long> { void __constraints() {} };
#ifdef _GLIBCPP_USE_LONG_LONG
template <> struct _SignedIntegerConcept<long long> { void __constraints(){}};
#endif
 
template <class _Tp>
struct _UnsignedIntegerConcept {
void __constraints() {
__error_type_must_be_an_unsigned_integer_type();
}
};
template <> struct _UnsignedIntegerConcept<unsigned short>
{ void __constraints() {} };
template <> struct _UnsignedIntegerConcept<unsigned int>
{ void __constraints() {} };
template <> struct _UnsignedIntegerConcept<unsigned long>
{ void __constraints() {} };
#ifdef _GLIBCPP_USE_LONG_LONG
template <> struct _UnsignedIntegerConcept<unsigned long long>
{ void __constraints() {} };
#endif
 
//===========================================================================
// Basic Concepts
 
template <class _Tp>
struct _DefaultConstructibleConcept
{
void __constraints() {
_Tp __a _IsUnused; // require default constructor
}
};
 
template <class _Tp>
struct _AssignableConcept
{
void __constraints() {
__a = __a; // require assignment operator
__const_constraints(__a);
}
void __const_constraints(const _Tp& __b) {
__a = __b; // const required for argument to assignment
}
_Tp __a;
};
 
template <class _Tp>
struct _CopyConstructibleConcept
{
void __constraints() {
_Tp __a(__b); // require copy constructor
_Tp* __ptr _IsUnused = &__a; // require address of operator
__const_constraints(__a);
}
void __const_constraints(const _Tp& __a) {
_Tp __c(__a) _IsUnused; // require const copy constructor
const _Tp* __ptr _IsUnused = &__a; // require const address of operator
}
_Tp __b;
};
 
// The SGI STL version of Assignable requires copy constructor and operator=
template <class _Tp>
struct _SGIAssignableConcept
{
void __constraints() {
_Tp __b(__a) _IsUnused;
__a = __a; // require assignment operator
__const_constraints(__a);
}
void __const_constraints(const _Tp& __b) {
_Tp __c(__b) _IsUnused;
__a = __b; // const required for argument to assignment
}
_Tp __a;
};
 
template <class _From, class _To>
struct _ConvertibleConcept
{
void __constraints() {
_To __y _IsUnused = __x;
}
_From __x;
};
 
// The C++ standard requirements for many concepts talk about return
// types that must be "convertible to bool". The problem with this
// requirement is that it leaves the door open for evil proxies that
// define things like operator|| with strange return types. Two
// possible solutions are:
// 1) require the return type to be exactly bool
// 2) stay with convertible to bool, and also
// specify stuff about all the logical operators.
// For now we just test for convertible to bool.
template <class _Tp>
void __aux_require_boolean_expr(const _Tp& __t) {
bool __x _IsUnused = __t;
}
 
// FIXME
template <class _Tp>
struct _EqualityComparableConcept
{
void __constraints() {
__aux_require_boolean_expr(__a == __b);
__aux_require_boolean_expr(__a != __b);
}
_Tp __a, __b;
};
 
template <class _Tp>
struct _LessThanComparableConcept
{
void __constraints() {
__aux_require_boolean_expr(__a < __b);
}
_Tp __a, __b;
};
 
// This is equivalent to SGI STL's LessThanComparable.
template <class _Tp>
struct _ComparableConcept
{
void __constraints() {
__aux_require_boolean_expr(__a < __b);
__aux_require_boolean_expr(__a > __b);
__aux_require_boolean_expr(__a <= __b);
__aux_require_boolean_expr(__a >= __b);
}
_Tp __a, __b;
};
 
#define _GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(_OP,_NAME) \
template <class _First, class _Second> \
struct _NAME { \
void __constraints() { (void)__constraints_(); } \
bool __constraints_() { \
return __a _OP __b; \
} \
_First __a; \
_Second __b; \
}
 
#define _GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(_OP,_NAME) \
template <class _Ret, class _First, class _Second> \
struct _NAME { \
void __constraints() { (void)__constraints_(); } \
_Ret __constraints_() { \
return __a _OP __b; \
} \
_First __a; \
_Second __b; \
}
 
_GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(==, _EqualOpConcept);
_GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(!=, _NotEqualOpConcept);
_GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<, _LessThanOpConcept);
_GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<=, _LessEqualOpConcept);
_GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>, _GreaterThanOpConcept);
_GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>=, _GreaterEqualOpConcept);
 
_GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(+, _PlusOpConcept);
_GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(*, _TimesOpConcept);
_GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(/, _DivideOpConcept);
_GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(-, _SubtractOpConcept);
_GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(%, _ModOpConcept);
 
#undef _GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT
#undef _GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT
 
//===========================================================================
// Function Object Concepts
 
template <class _Func, class _Return>
struct _GeneratorConcept
{
void __constraints() {
const _Return& __r _IsUnused = __f();// require operator() member function
}
_Func __f;
};
 
 
template <class _Func>
struct _GeneratorConcept<_Func,void>
{
void __constraints() {
__f(); // require operator() member function
}
_Func __f;
};
 
template <class _Func, class _Return, class _Arg>
struct _UnaryFunctionConcept
{
void __constraints() {
__r = __f(__arg); // require operator()
}
_Func __f;
_Arg __arg;
_Return __r;
};
 
template <class _Func, class _Arg>
struct _UnaryFunctionConcept<_Func, void, _Arg> {
void __constraints() {
__f(__arg); // require operator()
}
_Func __f;
_Arg __arg;
};
 
template <class _Func, class _Return, class _First, class _Second>
struct _BinaryFunctionConcept
{
void __constraints() {
__r = __f(__first, __second); // require operator()
}
_Func __f;
_First __first;
_Second __second;
_Return __r;
};
 
template <class _Func, class _First, class _Second>
struct _BinaryFunctionConcept<_Func, void, _First, _Second>
{
void __constraints() {
__f(__first, __second); // require operator()
}
_Func __f;
_First __first;
_Second __second;
};
 
template <class _Func, class _Arg>
struct _UnaryPredicateConcept
{
void __constraints() {
__aux_require_boolean_expr(__f(__arg)); // require op() returning bool
}
_Func __f;
_Arg __arg;
};
 
template <class _Func, class _First, class _Second>
struct _BinaryPredicateConcept
{
void __constraints() {
__aux_require_boolean_expr(__f(__a, __b)); // require op() returning bool
}
_Func __f;
_First __a;
_Second __b;
};
 
// use this when functor is used inside a container class like std::set
template <class _Func, class _First, class _Second>
struct _Const_BinaryPredicateConcept {
void __constraints() {
__const_constraints(__f);
}
void __const_constraints(const _Func& __fun) {
__function_requires<_BinaryPredicateConcept<_Func, _First, _Second> >();
// operator() must be a const member function
__aux_require_boolean_expr(__fun(__a, __b));
}
_Func __f;
_First __a;
_Second __b;
};
 
//===========================================================================
// Iterator Concepts
 
template <class _Tp>
struct _TrivialIteratorConcept
{
void __constraints() {
__function_requires< _DefaultConstructibleConcept<_Tp> >();
__function_requires< _AssignableConcept<_Tp> >();
__function_requires< _EqualityComparableConcept<_Tp> >();
typedef typename std::iterator_traits<_Tp>::value_type _V;
(void)*__i; // require dereference operator
}
_Tp __i;
};
 
template <class _Tp>
struct _Mutable_TrivialIteratorConcept
{
void __constraints() {
__function_requires< _TrivialIteratorConcept<_Tp> >();
*__i = *__j; // require dereference and assignment
}
_Tp __i, __j;
};
 
template <class _Tp>
struct _InputIteratorConcept
{
void __constraints() {
__function_requires< _TrivialIteratorConcept<_Tp> >();
// require iterator_traits typedef's
typedef typename std::iterator_traits<_Tp>::difference_type _D;
__function_requires< _SignedIntegerConcept<_D> >();
typedef typename std::iterator_traits<_Tp>::reference _R;
typedef typename std::iterator_traits<_Tp>::pointer _Pt;
typedef typename std::iterator_traits<_Tp>::iterator_category _Cat;
__function_requires< _ConvertibleConcept<
typename std::iterator_traits<_Tp>::iterator_category,
std::input_iterator_tag> >();
++__i; // require preincrement operator
__i++; // require postincrement operator
}
_Tp __i;
};
 
template <class _Tp, class _ValueT>
struct _OutputIteratorConcept
{
void __constraints() {
__function_requires< _AssignableConcept<_Tp> >();
++__i; // require preincrement operator
__i++; // require postincrement operator
*__i++ = __t; // require postincrement and assignment
}
_Tp __i;
_ValueT __t;
};
 
template <class _Tp>
struct _ForwardIteratorConcept
{
void __constraints() {
__function_requires< _InputIteratorConcept<_Tp> >();
__function_requires< _ConvertibleConcept<
typename std::iterator_traits<_Tp>::iterator_category,
std::forward_iterator_tag> >();
typedef typename std::iterator_traits<_Tp>::reference _R;
_R __r _IsUnused = *__i;
}
_Tp __i;
};
 
template <class _Tp>
struct _Mutable_ForwardIteratorConcept
{
void __constraints() {
__function_requires< _ForwardIteratorConcept<_Tp> >();
*__i++ = *__i; // require postincrement and assignment
}
_Tp __i;
};
 
template <class _Tp>
struct _BidirectionalIteratorConcept
{
void __constraints() {
__function_requires< _ForwardIteratorConcept<_Tp> >();
__function_requires< _ConvertibleConcept<
typename std::iterator_traits<_Tp>::iterator_category,
std::bidirectional_iterator_tag> >();
--__i; // require predecrement operator
__i--; // require postdecrement operator
}
_Tp __i;
};
 
template <class _Tp>
struct _Mutable_BidirectionalIteratorConcept
{
void __constraints() {
__function_requires< _BidirectionalIteratorConcept<_Tp> >();
__function_requires< _Mutable_ForwardIteratorConcept<_Tp> >();
*__i-- = *__i; // require postdecrement and assignment
}
_Tp __i;
};
 
 
template <class _Tp>
struct _RandomAccessIteratorConcept
{
void __constraints() {
__function_requires< _BidirectionalIteratorConcept<_Tp> >();
__function_requires< _ComparableConcept<_Tp> >();
__function_requires< _ConvertibleConcept<
typename std::iterator_traits<_Tp>::iterator_category,
std::random_access_iterator_tag> >();
// ??? We don't use _R, are we just checking for "referenceability"?
typedef typename std::iterator_traits<_Tp>::reference _R;
 
__i += __n; // require assignment addition operator
__i = __i + __n; __i = __n + __i; // require addition with difference type
__i -= __n; // require assignment subtraction op
__i = __i - __n; // require subtraction with
// difference type
__n = __i - __j; // require difference operator
(void)__i[__n]; // require element access operator
}
_Tp __a, __b;
_Tp __i, __j;
typename std::iterator_traits<_Tp>::difference_type __n;
};
 
template <class _Tp>
struct _Mutable_RandomAccessIteratorConcept
{
void __constraints() {
__function_requires< _RandomAccessIteratorConcept<_Tp> >();
__function_requires< _Mutable_BidirectionalIteratorConcept<_Tp> >();
__i[__n] = *__i; // require element access and assignment
}
_Tp __i;
typename std::iterator_traits<_Tp>::difference_type __n;
};
 
//===========================================================================
// Container Concepts
 
template <class _Container>
struct _ContainerConcept
{
typedef typename _Container::value_type _Value_type;
typedef typename _Container::difference_type _Difference_type;
typedef typename _Container::size_type _Size_type;
typedef typename _Container::const_reference _Const_reference;
typedef typename _Container::const_pointer _Const_pointer;
typedef typename _Container::const_iterator _Const_iterator;
 
void __constraints() {
__function_requires< _InputIteratorConcept<_Const_iterator> >();
__function_requires< _AssignableConcept<_Container> >();
const _Container __c;
__i = __c.begin();
__i = __c.end();
__n = __c.size();
__n = __c.max_size();
__b = __c.empty();
}
bool __b;
_Const_iterator __i;
_Size_type __n;
};
 
template <class _Container>
struct _Mutable_ContainerConcept
{
typedef typename _Container::value_type _Value_type;
typedef typename _Container::reference _Reference;
typedef typename _Container::iterator _Iterator;
typedef typename _Container::pointer _Pointer;
void __constraints() {
__function_requires< _ContainerConcept<_Container> >();
__function_requires< _AssignableConcept<_Value_type> >();
__function_requires< _InputIteratorConcept<_Iterator> >();
 
__i = __c.begin();
__i = __c.end();
__c.swap(__c2);
}
_Iterator __i;
_Container __c, __c2;
};
 
template <class _ForwardContainer>
struct _ForwardContainerConcept
{
void __constraints() {
__function_requires< _ContainerConcept<_ForwardContainer> >();
typedef typename _ForwardContainer::const_iterator _Const_iterator;
__function_requires< _ForwardIteratorConcept<_Const_iterator> >();
}
};
 
template <class _ForwardContainer>
struct _Mutable_ForwardContainerConcept
{
void __constraints() {
__function_requires< _ForwardContainerConcept<_ForwardContainer> >();
__function_requires< _Mutable_ContainerConcept<_ForwardContainer> >();
typedef typename _ForwardContainer::iterator _Iterator;
__function_requires< _Mutable_ForwardIteratorConcept<_Iterator> >();
}
};
 
template <class _ReversibleContainer>
struct _ReversibleContainerConcept
{
typedef typename _ReversibleContainer::const_iterator _Const_iterator;
typedef typename _ReversibleContainer::const_reverse_iterator
_Const_reverse_iterator;
 
void __constraints() {
__function_requires< _ForwardContainerConcept<_ReversibleContainer> >();
__function_requires< _BidirectionalIteratorConcept<_Const_iterator> >();
__function_requires<
_BidirectionalIteratorConcept<_Const_reverse_iterator> >();
 
const _ReversibleContainer __c;
_Const_reverse_iterator __i = __c.rbegin();
__i = __c.rend();
}
};
 
template <class _ReversibleContainer>
struct _Mutable_ReversibleContainerConcept
{
typedef typename _ReversibleContainer::iterator _Iterator;
typedef typename _ReversibleContainer::reverse_iterator _Reverse_iterator;
 
void __constraints() {
__function_requires<_ReversibleContainerConcept<_ReversibleContainer> >();
__function_requires<
_Mutable_ForwardContainerConcept<_ReversibleContainer> >();
__function_requires<_Mutable_BidirectionalIteratorConcept<_Iterator> >();
__function_requires<
_Mutable_BidirectionalIteratorConcept<_Reverse_iterator> >();
 
_Reverse_iterator __i = __c.rbegin();
__i = __c.rend();
}
_ReversibleContainer __c;
};
 
template <class _RandomAccessContainer>
struct _RandomAccessContainerConcept
{
typedef typename _RandomAccessContainer::size_type _Size_type;
typedef typename _RandomAccessContainer::const_reference _Const_reference;
typedef typename _RandomAccessContainer::const_iterator _Const_iterator;
typedef typename _RandomAccessContainer::const_reverse_iterator
_Const_reverse_iterator;
 
void __constraints() {
__function_requires<
_ReversibleContainerConcept<_RandomAccessContainer> >();
__function_requires< _RandomAccessIteratorConcept<_Const_iterator> >();
__function_requires<
_RandomAccessIteratorConcept<_Const_reverse_iterator> >();
 
const _RandomAccessContainer __c;
_Const_reference __r _IsUnused = __c[__n];
}
_Size_type __n;
};
 
template <class _RandomAccessContainer>
struct _Mutable_RandomAccessContainerConcept
{
typedef typename _RandomAccessContainer::size_type _Size_type;
typedef typename _RandomAccessContainer::reference _Reference;
typedef typename _RandomAccessContainer::iterator _Iterator;
typedef typename _RandomAccessContainer::reverse_iterator _Reverse_iterator;
 
void __constraints() {
__function_requires<
_RandomAccessContainerConcept<_RandomAccessContainer> >();
__function_requires<
_Mutable_ReversibleContainerConcept<_RandomAccessContainer> >();
__function_requires< _Mutable_RandomAccessIteratorConcept<_Iterator> >();
__function_requires<
_Mutable_RandomAccessIteratorConcept<_Reverse_iterator> >();
 
_Reference __r _IsUnused = __c[__i];
}
_Size_type __i;
_RandomAccessContainer __c;
};
 
// A Sequence is inherently mutable
template <class _Sequence>
struct _SequenceConcept
{
typedef typename _Sequence::reference _Reference;
typedef typename _Sequence::const_reference _Const_reference;
 
void __constraints() {
// Matt Austern's book puts DefaultConstructible here, the C++
// standard places it in Container
// function_requires< DefaultConstructible<Sequence> >();
__function_requires< _Mutable_ForwardContainerConcept<_Sequence> >();
__function_requires< _DefaultConstructibleConcept<_Sequence> >();
 
_Sequence
__c(__n) _IsUnused,
__c2(__n, __t) _IsUnused,
__c3(__first, __last) _IsUnused;
 
__c.insert(__p, __t);
__c.insert(__p, __n, __t);
__c.insert(__p, __first, __last);
 
__c.erase(__p);
__c.erase(__p, __q);
 
_Reference __r _IsUnused = __c.front();
 
__const_constraints(__c);
}
void __const_constraints(const _Sequence& __c) {
_Const_reference __r _IsUnused = __c.front();
}
typename _Sequence::value_type __t;
typename _Sequence::size_type __n;
typename _Sequence::value_type *__first, *__last;
typename _Sequence::iterator __p, __q;
};
 
template <class _FrontInsertionSequence>
struct _FrontInsertionSequenceConcept
{
void __constraints() {
__function_requires< _SequenceConcept<_FrontInsertionSequence> >();
 
__c.push_front(__t);
__c.pop_front();
}
_FrontInsertionSequence __c;
typename _FrontInsertionSequence::value_type __t;
};
 
template <class _BackInsertionSequence>
struct _BackInsertionSequenceConcept
{
typedef typename _BackInsertionSequence::reference _Reference;
typedef typename _BackInsertionSequence::const_reference _Const_reference;
 
void __constraints() {
__function_requires< _SequenceConcept<_BackInsertionSequence> >();
 
__c.push_back(__t);
__c.pop_back();
_Reference __r _IsUnused = __c.back();
}
void __const_constraints(const _BackInsertionSequence& __c) {
_Const_reference __r _IsUnused = __c.back();
};
_BackInsertionSequence __c;
typename _BackInsertionSequence::value_type __t;
};
 
template <class _AssociativeContainer>
struct _AssociativeContainerConcept
{
void __constraints() {
__function_requires< _ForwardContainerConcept<_AssociativeContainer> >();
__function_requires<
_DefaultConstructibleConcept<_AssociativeContainer> >();
__i = __c.find(__k);
__r = __c.equal_range(__k);
__c.erase(__k);
__c.erase(__i);
__c.erase(__r.first, __r.second);
__const_constraints(__c);
}
void __const_constraints(const _AssociativeContainer& __c) {
__ci = __c.find(__k);
__n = __c.count(__k);
__cr = __c.equal_range(__k);
}
typedef typename _AssociativeContainer::iterator _Iterator;
typedef typename _AssociativeContainer::const_iterator _Const_iterator;
 
_AssociativeContainer __c;
_Iterator __i;
std::pair<_Iterator,_Iterator> __r;
_Const_iterator __ci;
std::pair<_Const_iterator,_Const_iterator> __cr;
typename _AssociativeContainer::key_type __k;
typename _AssociativeContainer::size_type __n;
};
 
template <class _UniqueAssociativeContainer>
struct _UniqueAssociativeContainerConcept
{
void __constraints() {
__function_requires<
_AssociativeContainerConcept<_UniqueAssociativeContainer> >();
_UniqueAssociativeContainer __c(__first, __last);
__pos_flag = __c.insert(__t);
__c.insert(__first, __last);
}
std::pair<typename _UniqueAssociativeContainer::iterator, bool> __pos_flag;
typename _UniqueAssociativeContainer::value_type __t;
typename _UniqueAssociativeContainer::value_type *__first, *__last;
};
 
template <class _MultipleAssociativeContainer>
struct _MultipleAssociativeContainerConcept
{
void __constraints() {
__function_requires<
_AssociativeContainerConcept<_MultipleAssociativeContainer> >();
 
_MultipleAssociativeContainer __c(__first, __last);
__pos = __c.insert(__t);
__c.insert(__first, __last);
 
}
typename _MultipleAssociativeContainer::iterator __pos _IsUnused;
typename _MultipleAssociativeContainer::value_type __t;
typename _MultipleAssociativeContainer::value_type *__first, *__last;
};
 
template <class _SimpleAssociativeContainer>
struct _SimpleAssociativeContainerConcept
{
void __constraints() {
__function_requires<
_AssociativeContainerConcept<_SimpleAssociativeContainer> >();
typedef typename _SimpleAssociativeContainer::key_type _Key_type;
typedef typename _SimpleAssociativeContainer::value_type _Value_type;
typedef typename _Aux_require_same<_Key_type, _Value_type>::_Type
_Requqired;
}
};
 
template <class _SimpleAssociativeContainer>
struct _PairAssociativeContainerConcept
{
void __constraints() {
__function_requires<
_AssociativeContainerConcept<_SimpleAssociativeContainer> >();
typedef typename _SimpleAssociativeContainer::key_type _Key_type;
typedef typename _SimpleAssociativeContainer::value_type _Value_type;
typedef typename _SimpleAssociativeContainer::mapped_type _Mapped_type;
typedef std::pair<const _Key_type, _Mapped_type> _Required_value_type;
typedef typename _Aux_require_same<_Value_type,
_Required_value_type>::_Type _Required;
}
};
 
template <class _SortedAssociativeContainer>
struct _SortedAssociativeContainerConcept
{
void __constraints() {
__function_requires<
_AssociativeContainerConcept<_SortedAssociativeContainer> >();
__function_requires<
_ReversibleContainerConcept<_SortedAssociativeContainer> >();
 
_SortedAssociativeContainer
__c(__kc) _IsUnused,
__c2(__first, __last) _IsUnused,
__c3(__first, __last, __kc) _IsUnused;
 
__p = __c.upper_bound(__k);
__p = __c.lower_bound(__k);
__r = __c.equal_range(__k);
__c.insert(__p, __t);
}
void __const_constraints(const _SortedAssociativeContainer& __c) {
__kc = __c.key_comp();
__vc = __c.value_comp();
 
__cp = __c.upper_bound(__k);
__cp = __c.lower_bound(__k);
__cr = __c.equal_range(__k);
}
typename _SortedAssociativeContainer::key_compare __kc;
typename _SortedAssociativeContainer::value_compare __vc;
typename _SortedAssociativeContainer::value_type __t;
typename _SortedAssociativeContainer::key_type __k;
typedef typename _SortedAssociativeContainer::iterator _Iterator;
typedef typename _SortedAssociativeContainer::const_iterator
_Const_iterator;
 
_Iterator __p;
_Const_iterator __cp;
std::pair<_Iterator,_Iterator> __r;
std::pair<_Const_iterator,_Const_iterator> __cr;
typename _SortedAssociativeContainer::value_type *__first, *__last;
};
 
// HashedAssociativeContainer
 
} // namespace __gnu_cxx
 
#undef _IsUnused
 
#endif // _GLIBCPP_BOOST_CONCEPT_CHECK
 
 
/contrib/media/updf/include/bits/c++config
0,0 → 1,112
// Predefined symbols and macros -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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
 
// Pick up any OS-specific definitions.
#include <bits/os_defines.h>
 
// The current version of the C++ library in compressed ISO date format.
#define __GLIBCPP__ 20010615
 
// This is necessary until GCC 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
 
// Define this to permit user-level control of the expansion of string
// buffers (via a fn pointer), see basic_string.* for more.
//#define _GLIBCPP_ALLOC_CONTROL
 
// To enable older, ARM-style iostreams and other anachronisms use this.
//#define _GLIBCPP_DEPRECATED 1
 
// Use corrected code from the committee library group's issues list.
#define _GLIBCPP_RESOLVE_LIB_DEFECTS 1
 
// Enable concept checking code from the boost libraries.
//#define _GLIBCPP_CONCEPT_CHECKS 1
 
// Map gthr.h abstraction to that required for STL. Do not key off of
// __GTHREADS at this point since we haven't seen the correct symbol
// yet, instead setup so that include/bits/stl_threads.h will know to
// include gthr.h instead of any other type of thread support. Note:
// that gthr.h may well map to gthr-single.h which is a correct way to
// express no threads support in gcc. As a user, do not define
// _NOTHREADS without consideration of the consequences (e.g. it is an
// internal ABI change).
#define __STL_GTHREADS
#define __STL_THREADS
#define __STL_VOLATILE volatile
 
// This is also a user hook, but via -f[no-]exceptions, not direct #defines.
#ifdef __EXCEPTIONS
# define __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
 
// Default to the typically high-speed, pool-based allocator (as
// libstdc++-v2) instead of the malloc-based allocator (libstdc++-v3
// snapshots). See libstdc++-v3/docs/html/17_intro/howto.html for
// details on why you don't want to override this setting. Ensure
// that threads are properly configured on your platform before
// assigning blame to the STL container-memory allocator. After doing
// so, please report any possible issues to libstdc++@gcc.gnu.org .
// Do not blindly #define __USE_MALLOC here or on the command line.
 
// The remainder of the prewritten config is mostly automatic; all the
// user hooks are listed above.
 
// XXX
// Only used in the SGI rope extensions; this is from stl_config.h and
// should be cleaned up.
# define __stl_assert(expr)
 
// End of prewritten config; the discovered settings follow.
/contrib/media/updf/include/bits/char_traits.h
0,0 → 1,275
// Character Traits for use by standard string and iostream -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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
 
#pragma GCC system_header
 
#include <bits/std_cstring.h> // For memmove, memset, memchr
#include <bits/fpos.h> // For streampos
 
namespace std
{
// 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, size_t __n)
{
for (size_t __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, size_t __n, const char_type& __a)
{
for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
if (*__p == __a) return __p;
return 0;
}
 
static char_type*
move(char_type* __s1, const char_type* __s2, size_t __n)
{ return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
 
static char_type*
copy(char_type* __s1, const char_type* __s2, size_t __n)
{ return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
 
static char_type*
assign(char_type* __s, size_t __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 int_type
eof() { return static_cast<int_type>(-1); }
 
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 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, size_t __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, size_t __n, const char_type& __a)
{ return static_cast<const char_type*>(memchr(__s, __a, __n)); }
 
static char_type*
move(char_type* __s1, const char_type* __s2, size_t __n)
{ return static_cast<char_type*>(memmove(__s1, __s2, __n)); }
 
static char_type*
copy(char_type* __s1, const char_type* __s2, size_t __n)
{ return static_cast<char_type*>(memcpy(__s1, __s2, __n)); }
 
static char_type*
assign(char_type* __s, size_t __n, char_type __a)
{ return static_cast<char_type*>(memset(__s, __a, __n)); }
 
static char_type
to_char_type(const int_type& __c)
{ return static_cast<char_type>(__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 int_type
eof() { return static_cast<int_type>(EOF); }
 
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 streamoff 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, size_t __n)
{ return wmemcmp(__s1, __s2, __n); }
 
static size_t
length(const char_type* __s)
{ return wcslen(__s); }
 
static const char_type*
find(const char_type* __s, size_t __n, const char_type& __a)
{ return wmemchr(__s, __a, __n); }
 
static char_type*
move(char_type* __s1, const char_type* __s2, int_type __n)
{ return wmemmove(__s1, __s2, __n); }
 
static char_type*
copy(char_type* __s1, const char_type* __s2, size_t __n)
{ return wmemcpy(__s1, __s2, __n); }
 
static char_type*
assign(char_type* __s, size_t __n, char_type __a)
{ return wmemset(__s, __a, __n); }
 
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 int_type
eof() { return static_cast<int_type>(WEOF); }
 
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
/contrib/media/updf/include/bits/codecvt.h
0,0 → 1,717
// Locale support (codecvt) -*- C++ -*-
 
// Copyright (C) 2000, 2001 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.2.1.5 Template class codecvt
//
 
// Warning: this file is not meant for user inclusion. Use <locale>.
 
// Written by Benjamin Kosnik <bkoz@cygnus.com>
 
#ifndef _CPP_BITS_CODECVT_H
#define _CPP_BITS_CODECVT_H 1
 
#pragma GCC system_header
 
// XXX
// __enc_traits may need to move up the locale header hierarchy,
// depending on if ctype ends up using it.
 
#ifdef _GLIBCPP_USE_WCHAR_T
// Extensions to use icov for dealing with character encodings,
// including conversions and comparisons between various character
// sets. This object encapsulates data that may need to be shared between
// char_traits, codecvt and ctype.
 
#if _GLIBCPP_USE_SHADOW_HEADERS
using _C_legacy::CODESET;
#endif
 
class __enc_traits
{
public:
// Types:
// NB: A conversion descriptor subsumes and enhances the
// functionality of a simple state type such as mbstate_t.
typedef iconv_t __desc_type;
protected:
// Data Members:
// Max size of charset encoding name
static const int _S_max_size = 32;
// Name of internal character set encoding.
char _M_int_enc[_S_max_size];
// Name of external character set encoding.
char _M_ext_enc[_S_max_size];
 
// Conversion descriptor between external encoding to internal encoding.
__desc_type _M_in_desc;
// Conversion descriptor between internal encoding to external encoding.
__desc_type _M_out_desc;
 
// Details the byte-order marker for the external encoding, if necessary.
int _M_ext_bom;
 
// Details the byte-order marker for the internal encoding, if necessary.
int _M_int_bom;
 
public:
__enc_traits()
: _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0)
{
// __intc_end = whatever we are using internally, which is
// UCS4 (linux)
// UCS2 == UNICODE (microsoft, java, aix, whatever...)
// XXX Currently don't know how to get this data from target system...
strcpy(_M_int_enc, "UCS4");
 
// __extc_end = external codeset in current locale
strcpy(_M_ext_enc, nl_langinfo(CODESET));
}
 
__enc_traits(const char* __int, const char* __ext, int __ibom = 0,
int __ebom = 0)
: _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0)
{
strncpy(_M_int_enc, __int, _S_max_size);
strncpy(_M_ext_enc, __ext, _S_max_size);
}
 
// 21.1.2 traits typedefs
// p4
// typedef STATE_T state_type
// requires: state_type shall meet the requirements of
// CopyConstructible types (20.1.3)
__enc_traits(const __enc_traits& __obj)
{
strncpy(_M_int_enc, __obj._M_int_enc, _S_max_size);
strncpy(_M_ext_enc, __obj._M_ext_enc, _S_max_size);
_M_ext_bom = __obj._M_ext_bom;
_M_int_bom = __obj._M_int_bom;
}
 
~__enc_traits()
{
iconv_close(_M_in_desc);
iconv_close(_M_out_desc);
}
 
// Initializes
void
_M_init()
{
_M_in_desc = iconv_open(_M_int_enc, _M_ext_enc);
_M_out_desc = iconv_open(_M_ext_enc, _M_int_enc);
if (_M_out_desc == iconv_t(-1) || _M_in_desc == iconv_t(-1))
{
// XXX Extended error checking.
}
}
 
bool
_M_good()
{
return _M_out_desc && _M_in_desc
&& _M_out_desc != iconv_t(-1) && _M_in_desc != iconv_t(-1);
}
 
const __desc_type*
_M_get_in_descriptor()
{ return &_M_in_desc; }
 
const __desc_type*
_M_get_out_descriptor()
{ return &_M_out_desc; }
 
const char*
_M_get_internal_enc()
{ return _M_int_enc; }
 
const char*
_M_get_external_enc()
{ return _M_ext_enc; }
 
int
_M_get_external_bom()
{ return _M_ext_bom; }
 
int
_M_get_internal_bom()
{ return _M_int_bom; }
};
#endif //_GLIBCPP_USE_WCHAR_T
 
 
// 22.2.1.5 Template class codecvt
class codecvt_base
{
public:
enum result
{
ok,
partial,
error,
noconv
};
};
 
// Template class __codecvt_abstract_base
// NB: An abstract base class that fills in the public inlines, so
// that the specializations don't have to re-copy the public
// interface.
template<typename _InternT, typename _ExternT, typename _StateT>
class __codecvt_abstract_base
: public locale::facet, public codecvt_base
{
public:
// Types:
typedef codecvt_base::result result;
typedef _InternT intern_type;
typedef _ExternT extern_type;
typedef _StateT state_type;
// 22.2.1.5.1 codecvt members
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_end,
extern_type*& __to_next) const
{
return this->do_out(__state, __from, __from_end, __from_next,
__to, __to_end, __to_next);
}
 
result
unshift(state_type& __state, extern_type* __to, extern_type* __to_end,
extern_type*& __to_next) const
{ return this->do_unshift(__state, __to,__to_end,__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_end,
intern_type*& __to_next) const
{
return this->do_in(__state, __from, __from_end, __from_next,
__to, __to_end, __to_next);
}
 
int
encoding() const throw()
{ return this->do_encoding(); }
 
bool
always_noconv() const throw()
{ return this->do_always_noconv(); }
 
int
length(const state_type& __state, const extern_type* __from,
const extern_type* __end, size_t __max) const
{ return this->do_length(__state, __from, __end, __max); }
 
int
max_length() const throw()
{ return this->do_max_length(); }
 
protected:
explicit
__codecvt_abstract_base(size_t __refs = 0) : locale::facet(__refs) { }
 
virtual
~__codecvt_abstract_base() { }
 
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_end,
extern_type*& __to_next) const = 0;
 
virtual result
do_unshift(state_type& __state, extern_type* __to,
extern_type* __to_end, 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_end,
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;
};
 
// 22.2.1.5 Template class codecvt
// NB: Generic, mostly useless implementation.
template<typename _InternT, typename _ExternT, typename _StateT>
class codecvt
: public __codecvt_abstract_base<_InternT, _ExternT, _StateT>
{
public:
// Types:
typedef codecvt_base::result result;
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_abstract_base<_InternT,_ExternT,_StateT> (__refs) { }
 
protected:
virtual
~codecvt() { }
};
 
template<typename _InternT, typename _ExternT, typename _StateT>
locale::id codecvt<_InternT, _ExternT, _StateT>::id;
 
#ifdef _GLIBCPP_USE_WCHAR_T
// partial specialization
// This specialization takes advantage of iconv to provide code
// conversions between a large number of character encodings.
template<typename _InternT, typename _ExternT>
class codecvt<_InternT, _ExternT, __enc_traits>
: public __codecvt_abstract_base<_InternT, _ExternT, __enc_traits>
{
public:
// Types:
typedef codecvt_base::result result;
typedef _InternT intern_type;
typedef _ExternT extern_type;
typedef __enc_traits state_type;
typedef __enc_traits::__desc_type __desc_type;
typedef __enc_traits __enc_type;
 
// Data Members:
static locale::id id;
 
explicit
codecvt(size_t __refs = 0)
: __codecvt_abstract_base<intern_type, extern_type, state_type>(__refs)
{ }
 
explicit
codecvt(__enc_type* __enc, size_t __refs = 0)
: __codecvt_abstract_base<intern_type, extern_type, state_type>(__refs)
{ }
 
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_end,
extern_type*& __to_next) const;
 
virtual result
do_unshift(state_type& __state, extern_type* __to,
extern_type* __to_end, 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_end,
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();
};
 
template<typename _InternT, typename _ExternT>
locale::id
codecvt<_InternT, _ExternT, __enc_traits>::id;
 
// This adaptor works around the signature problems of the second
// argument to iconv(): SUSv2 and others use 'const char**', but glibc 2.2
// uses 'char**', which is what the standard is (apparently) due to use
// in the future. Using this adaptor, g++ will do the work for us.
template<typename _T>
inline size_t
__iconv_adaptor(size_t(*iconv_func)(iconv_t, _T, size_t*, char**, size_t*),
iconv_t cd, char** inbuf, size_t* inbytesleft,
char** outbuf, size_t* outbytesleft)
{
return iconv_func(cd, (_T)inbuf, inbytesleft, outbuf, outbytesleft);
}
 
template<typename _InternT, typename _ExternT>
codecvt_base::result
codecvt<_InternT, _ExternT, __enc_traits>::
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_end,
extern_type*& __to_next) const
{
result __ret = error;
if (__state._M_good())
{
typedef state_type::__desc_type __desc_type;
const __desc_type* __desc = __state._M_get_out_descriptor();
const size_t __fmultiple = sizeof(intern_type) / sizeof(char);
size_t __flen = __fmultiple * (__from_end - __from);
const size_t __tmultiple = sizeof(extern_type) / sizeof(char);
size_t __tlen = __tmultiple * (__to_end - __to);
// Argument list for iconv specifies a byte sequence. Thus,
// all to/from arrays must be brutally casted to char*.
char* __cto = reinterpret_cast<char*>(__to);
char* __cfrom;
size_t __conv;
 
// Some encodings need a byte order marker as the first item
// in the byte stream, to designate endian-ness. The default
// value for the byte order marker is NULL, so if this is
// the case, it's not necessary and we can just go on our
// merry way.
int __int_bom = __state._M_get_internal_bom();
if (__int_bom)
{
size_t __size = __from_end - __from;
intern_type* __cfixed = static_cast<intern_type*>(__builtin_alloca(sizeof(intern_type) * (__size + 1)));
__cfixed[0] = static_cast<intern_type>(__int_bom);
char_traits<intern_type>::copy(__cfixed + 1, __from, __size);
__cfrom = reinterpret_cast<char*>(__cfixed);
__conv = __iconv_adaptor(iconv, *__desc, &__cfrom,
&__flen, &__cto, &__tlen);
}
else
{
intern_type* __cfixed = const_cast<intern_type*>(__from);
__cfrom = reinterpret_cast<char*>(__cfixed);
__conv = __iconv_adaptor(iconv, *__desc, &__cfrom,
&__flen, &__cto, &__tlen);
}
 
if (__conv != size_t(-1))
{
__from_next = reinterpret_cast<const intern_type*>(__cfrom);
__to_next = reinterpret_cast<extern_type*>(__cto);
__ret = ok;
}
else
{
if (__flen < static_cast<size_t>(__from_end - __from))
{
__from_next = reinterpret_cast<const intern_type*>(__cfrom);
__to_next = reinterpret_cast<extern_type*>(__cto);
__ret = partial;
}
else
__ret = error;
}
}
return __ret;
}
 
template<typename _InternT, typename _ExternT>
codecvt_base::result
codecvt<_InternT, _ExternT, __enc_traits>::
do_unshift(state_type& __state, extern_type* __to,
extern_type* __to_end, extern_type*& __to_next) const
{
result __ret = error;
if (__state._M_good())
{
typedef state_type::__desc_type __desc_type;
const __desc_type* __desc = __state._M_get_in_descriptor();
const size_t __tmultiple = sizeof(intern_type) / sizeof(char);
size_t __tlen = __tmultiple * (__to_end - __to);
// Argument list for iconv specifies a byte sequence. Thus,
// all to/from arrays must be brutally casted to char*.
char* __cto = reinterpret_cast<char*>(__to);
size_t __conv = __iconv_adaptor(iconv,*__desc, NULL, NULL,
&__cto, &__tlen);
if (__conv != size_t(-1))
{
__to_next = reinterpret_cast<extern_type*>(__cto);
if (__tlen == __tmultiple * (__to_end - __to))
__ret = noconv;
else if (__tlen == 0)
__ret = ok;
else
__ret = partial;
}
else
__ret = error;
}
return __ret;
}
template<typename _InternT, typename _ExternT>
codecvt_base::result
codecvt<_InternT, _ExternT, __enc_traits>::
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_end,
intern_type*& __to_next) const
{
result __ret = error;
if (__state._M_good())
{
typedef state_type::__desc_type __desc_type;
const __desc_type* __desc = __state._M_get_in_descriptor();
const size_t __fmultiple = sizeof(extern_type) / sizeof(char);
size_t __flen = __fmultiple * (__from_end - __from);
const size_t __tmultiple = sizeof(intern_type) / sizeof(char);
size_t __tlen = __tmultiple * (__to_end - __to);
// Argument list for iconv specifies a byte sequence. Thus,
// all to/from arrays must be brutally casted to char*.
char* __cto = reinterpret_cast<char*>(__to);
char* __cfrom;
size_t __conv;
 
// Some encodings need a byte order marker as the first item
// in the byte stream, to designate endian-ness. The default
// value for the byte order marker is NULL, so if this is
// the case, it's not necessary and we can just go on our
// merry way.
int __ext_bom = __state._M_get_external_bom();
if (__ext_bom)
{
size_t __size = __from_end - __from;
extern_type* __cfixed = static_cast<extern_type*>(__builtin_alloca(sizeof(extern_type) * (__size + 1)));
__cfixed[0] = static_cast<extern_type>(__ext_bom);
char_traits<extern_type>::copy(__cfixed + 1, __from, __size);
__cfrom = reinterpret_cast<char*>(__cfixed);
__conv = __iconv_adaptor(iconv, *__desc, &__cfrom,
&__flen, &__cto, &__tlen);
}
else
{
extern_type* __cfixed = const_cast<extern_type*>(__from);
__cfrom = reinterpret_cast<char*>(__cfixed);
__conv = __iconv_adaptor(iconv, *__desc, &__cfrom,
&__flen, &__cto, &__tlen);
}
 
if (__conv != size_t(-1))
{
__from_next = reinterpret_cast<const extern_type*>(__cfrom);
__to_next = reinterpret_cast<intern_type*>(__cto);
__ret = ok;
}
else
{
if (__flen < static_cast<size_t>(__from_end - __from))
{
__from_next = reinterpret_cast<const extern_type*>(__cfrom);
__to_next = reinterpret_cast<intern_type*>(__cto);
__ret = partial;
}
else
__ret = error;
}
}
return __ret;
}
template<typename _InternT, typename _ExternT>
int
codecvt<_InternT, _ExternT, __enc_traits>::
do_encoding() const throw()
{ return 0; }
template<typename _InternT, typename _ExternT>
bool
codecvt<_InternT, _ExternT, __enc_traits>::
do_always_noconv() const throw()
{ return false; }
template<typename _InternT, typename _ExternT>
int
codecvt<_InternT, _ExternT, __enc_traits>::
do_length(const state_type&, const extern_type* __from,
const extern_type* __end, size_t __max) const
{ return min(__max, static_cast<size_t>(__end - __from)); }
 
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 74. Garbled text for codecvt::do_max_length
template<typename _InternT, typename _ExternT>
int
codecvt<_InternT, _ExternT, __enc_traits>::
do_max_length() const throw()
{ return 1; }
#endif
#endif /* _GLIBCPP_USE_WCHAR_T */
 
// codecvt<char, char, mbstate_t> required specialization
template<>
class codecvt<char, char, mbstate_t>
: public __codecvt_abstract_base<char, char, mbstate_t>
{
public:
// Types:
typedef char intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
 
// Data Members:
static locale::id id;
 
explicit
codecvt(size_t __refs = 0);
 
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_end,
extern_type*& __to_next) const;
 
virtual result
do_unshift(state_type& __state, extern_type* __to,
extern_type* __to_end, 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_end,
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
// codecvt<wchar_t, char, mbstate_t> required specialization
template<>
class codecvt<wchar_t, char, mbstate_t>
: public __codecvt_abstract_base<wchar_t, char, mbstate_t>
{
public:
// Types:
typedef wchar_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
 
// Data Members:
static locale::id id;
 
explicit
codecvt(size_t __refs = 0);
 
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_end,
extern_type*& __to_next) const;
 
virtual result
do_unshift(state_type& __state,
extern_type* __to, extern_type* __to_end,
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_end,
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() { }
};
 
#endif // _CPP_BITS_CODECVT_H
 
// Local Variables:
// mode:c++
// End:
 
/contrib/media/updf/include/bits/concept_check.h
0,0 → 1,81
// Concept-checking control -*- C++ -*-
 
// Copyright (C) 2001 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 _GLIBCPP_CONCEPT_CHECK
#define _GLIBCPP_CONCEPT_CHECK 1
 
#pragma GCC system_header
 
#include <bits/c++config.h>
 
// All places in libstdc++-v3 where these are used, or /might/ be used, or
// don't need to be used, or perhaps /should/ be used, are commented with
// "concept requirements" (and maybe some more text). So grep like crazy
// if you're looking for additional places to use these.
 
// Concept-checking code is off by default unless users turn it on via
// configure options or editing c++config.h.
 
#ifndef _GLIBCPP_CONCEPT_CHECKS
 
#define __glibcpp_function_requires(...)
#define __glibcpp_class_requires(_a,_b)
#define __glibcpp_class_requires2(_a,_b,_c)
#define __glibcpp_class_requires3(_a,_b,_c,_d)
#define __glibcpp_class_requires4(_a,_b,_c,_d,_e)
 
#else // the checks are on
 
#include <bits/boost_concept_check.h>
 
// Note that the obvious and elegant approach of
//
//#define glibcpp_function_requires(C) \
// boost::function_requires< boost::C >()
//
// won't work due to concept templates with more than one parameter, e.g.,
// BinaryPredicateConcept. The preprocessor tries to split things up on
// the commas in the template argument list. We can't use an inner pair of
// parenthesis to hide the commas, because "boost::(Temp<Foo,Bar>)" isn't
// a valid instantiation pattern. Thus, we steal a feature from C99.
 
#define __glibcpp_function_requires(...) \
__gnu_cxx::__function_requires< __gnu_cxx::__VA_ARGS__ >()
#define __glibcpp_class_requires(_a,_C) \
_GLIBCPP_CLASS_REQUIRES(_a, __gnu_cxx, _C)
#define __glibcpp_class_requires2(_a,_b,_C) \
_GLIBCPP_CLASS_REQUIRES2(_a, _b, __gnu_cxx, _C)
#define __glibcpp_class_requires3(_a,_b,_c,_C) \
_GLIBCPP_CLASS_REQUIRES3(_a, _b, _c, __gnu_cxx, _C)
#define __glibcpp_class_requires4(_a,_b,_c,_d,_C) \
_GLIBCPP_CLASS_REQUIRES4(_a, _b, _c, _d, __gnu_cxx, _C)
 
#endif // enable/disable
 
#endif // _GLIBCPP_CONCEPT_CHECK
/contrib/media/updf/include/bits/concept_checks.h
0,0 → 1,811
/*
* Copyright (c) 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 __CONCEPT_CHECKS_H
#define __CONCEPT_CHECKS_H
 
/*
Use these macro like assertions, but they assert properties
on types (usually template arguments). In technical terms they
verify whether a type "models" a "concept".
 
This set of requirements and the terminology used here is derived
from the book "Generic Programming and the STL" by Matt Austern
(Addison Wesley). For further information please consult that
book. The requirements also are intended to match the ANSI/ISO C++
standard.
 
This file covers the basic concepts and the iterator concepts.
There are several other files that provide the requirements
for the STL containers:
container_concepts.h
sequence_concepts.h
assoc_container_concepts.h
 
Jeremy Siek, 1999
 
TO DO:
- some issues with regards to concept classification and mutability
including AssociativeContianer -> ForwardContainer
and SortedAssociativeContainer -> ReversibleContainer
- HashedAssociativeContainer
- Allocator
- Function Object Concepts
 
*/
 
#ifndef __STL_USE_CONCEPT_CHECKS
 
// Some compilers lack the features that are necessary for concept checks.
// On those compilers we define the concept check macros to do nothing.
#define __STL_REQUIRES(__type_var, __concept) do {} while(0)
#define __STL_CLASS_REQUIRES(__type_var, __concept) \
static int __##__type_var##_##__concept
#define __STL_CONVERTIBLE(__type_x, __type_y) do {} while(0)
#define __STL_REQUIRES_SAME_TYPE(__type_x, __type_y) do {} while(0)
#define __STL_CLASS_REQUIRES_SAME_TYPE(__type_x, __type_y) \
static int __##__type_x##__type_y##_require_same_type
#define __STL_GENERATOR_CHECK(__func, __ret) do {} while(0)
#define __STL_CLASS_GENERATOR_CHECK(__func, __ret) \
static int __##__func##__ret##_generator_check
#define __STL_UNARY_FUNCTION_CHECK(__func, __ret, __arg) do {} while(0)
#define __STL_CLASS_UNARY_FUNCTION_CHECK(__func, __ret, __arg) \
static int __##__func##__ret##__arg##_unary_function_check
#define __STL_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
do {} while(0)
#define __STL_CLASS_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
static int __##__func##__ret##__first##__second##_binary_function_check
#define __STL_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
do {} while(0)
#define __STL_CLASS_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
static int __##__opname##__ret##__first##__second##_require_binary_op
 
#else /* __STL_USE_CONCEPT_CHECKS */
 
// This macro tests whether the template argument "__type_var"
// satisfies the requirements of "__concept". Here is a list of concepts
// that we know how to check:
// _Allocator
// _Assignable
// _DefaultConstructible
// _EqualityComparable
// _LessThanComparable
// _TrivialIterator
// _InputIterator
// _OutputIterator
// _ForwardIterator
// _BidirectionalIterator
// _RandomAccessIterator
// _Mutable_TrivialIterator
// _Mutable_ForwardIterator
// _Mutable_BidirectionalIterator
// _Mutable_RandomAccessIterator
 
#define __STL_REQUIRES(__type_var, __concept) \
do { \
void (*__x)( __type_var ) = __concept##_concept_specification< __type_var >\
::__concept##_requirement_violation; __x = __x; } while (0)
 
// Use this to check whether type X is convertible to type Y
#define __STL_CONVERTIBLE(__type_x, __type_y) \
do { \
void (*__x)( __type_x , __type_y ) = _STL_CONVERT_ERROR< __type_x , \
__type_y >::__type_X_is_not_convertible_to_type_Y; \
__x = __x; } while (0)
 
// Use this to test whether two template arguments are the same type
#define __STL_REQUIRES_SAME_TYPE(__type_x, __type_y) \
do { \
void (*__x)( __type_x , __type_y ) = _STL_SAME_TYPE_ERROR< __type_x, \
__type_y >::__type_X_not_same_as_type_Y; \
__x = __x; } while (0)
 
 
// function object checks
#define __STL_GENERATOR_CHECK(__func, __ret) \
do { \
__ret (*__x)( __func&) = \
_STL_GENERATOR_ERROR< \
__func, __ret>::__generator_requirement_violation; \
__x = __x; } while (0)
 
 
#define __STL_UNARY_FUNCTION_CHECK(__func, __ret, __arg) \
do { \
__ret (*__x)( __func&, const __arg& ) = \
_STL_UNARY_FUNCTION_ERROR< \
__func, __ret, __arg>::__unary_function_requirement_violation; \
__x = __x; } while (0)
 
 
#define __STL_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
do { \
__ret (*__x)( __func&, const __first&, const __second& ) = \
_STL_BINARY_FUNCTION_ERROR< \
__func, __ret, __first, __second>::__binary_function_requirement_violation; \
__x = __x; } while (0)
 
 
#define __STL_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
do { \
__ret (*__x)( __first&, __second& ) = _STL_BINARY##__opname##_ERROR< \
__ret, __first, __second>::__binary_operator_requirement_violation; \
__ret (*__y)( const __first&, const __second& ) = \
_STL_BINARY##__opname##_ERROR< __ret, __first, __second>:: \
__const_binary_operator_requirement_violation; \
__y = __y; __x = __x; } while (0)
 
 
#ifdef __STL_NO_FUNCTION_PTR_IN_CLASS_TEMPLATE
 
#define __STL_CLASS_REQUIRES(__type_var, __concept)
#define __STL_CLASS_REQUIRES_SAME_TYPE(__type_x, __type_y)
#define __STL_CLASS_GENERATOR_CHECK(__func, __ret)
#define __STL_CLASS_UNARY_FUNCTION_CHECK(__func, __ret, __arg)
#define __STL_CLASS_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second)
#define __STL_CLASS_REQUIRES_BINARY_OP(__opname, __ret, __first, __second)
 
#else
 
// Use this macro inside of template classes, where you would
// like to place requirements on the template arguments to the class
// Warning: do not pass pointers and such (e.g. T*) in as the __type_var,
// since the type_var is used to construct identifiers. Instead typedef
// the pointer type, then use the typedef name for the __type_var.
#define __STL_CLASS_REQUIRES(__type_var, __concept) \
typedef void (* __func##__type_var##__concept)( __type_var ); \
template <__func##__type_var##__concept _Tp1> \
struct __dummy_struct_##__type_var##__concept { }; \
static __dummy_struct_##__type_var##__concept< \
__concept##_concept_specification< \
__type_var>::__concept##_requirement_violation> \
__dummy_ptr_##__type_var##__concept
 
 
#define __STL_CLASS_REQUIRES_SAME_TYPE(__type_x, __type_y) \
typedef void (* __func_##__type_x##__type_y##same_type)( __type_x, \
__type_y ); \
template < __func_##__type_x##__type_y##same_type _Tp1> \
struct __dummy_struct_##__type_x##__type_y##_same_type { }; \
static __dummy_struct_##__type_x##__type_y##_same_type< \
_STL_SAME_TYPE_ERROR<__type_x, __type_y>::__type_X_not_same_as_type_Y> \
__dummy_ptr_##__type_x##__type_y##_same_type
 
 
#define __STL_CLASS_GENERATOR_CHECK(__func, __ret) \
typedef __ret (* __f_##__func##__ret##_generator)( __func& ); \
template <__f_##__func##__ret##_generator _Tp1> \
struct __dummy_struct_##__func##__ret##_generator { }; \
static __dummy_struct_##__func##__ret##_generator< \
_STL_GENERATOR_ERROR< \
__func, __ret>::__generator_requirement_violation> \
__dummy_ptr_##__func##__ret##_generator
 
 
#define __STL_CLASS_UNARY_FUNCTION_CHECK(__func, __ret, __arg) \
typedef __ret (* __f_##__func##__ret##__arg##_unary_check)( __func&, \
const __arg& ); \
template <__f_##__func##__ret##__arg##_unary_check _Tp1> \
struct __dummy_struct_##__func##__ret##__arg##_unary_check { }; \
static __dummy_struct_##__func##__ret##__arg##_unary_check< \
_STL_UNARY_FUNCTION_ERROR< \
__func, __ret, __arg>::__unary_function_requirement_violation> \
__dummy_ptr_##__func##__ret##__arg##_unary_check
 
 
#define __STL_CLASS_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
typedef __ret (* __f_##__func##__ret##__first##__second##_binary_check)( __func&, const __first&,\
const __second& ); \
template <__f_##__func##__ret##__first##__second##_binary_check _Tp1> \
struct __dummy_struct_##__func##__ret##__first##__second##_binary_check { }; \
static __dummy_struct_##__func##__ret##__first##__second##_binary_check< \
_STL_BINARY_FUNCTION_ERROR<__func, __ret, __first, __second>:: \
__binary_function_requirement_violation> \
__dummy_ptr_##__func##__ret##__first##__second##_binary_check
 
 
#define __STL_CLASS_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
typedef __ret (* __f_##__func##__ret##__first##__second##_binary_op)(const __first&, \
const __second& ); \
template <__f_##__func##__ret##__first##__second##_binary_op _Tp1> \
struct __dummy_struct_##__func##__ret##__first##__second##_binary_op { }; \
static __dummy_struct_##__func##__ret##__first##__second##_binary_op< \
_STL_BINARY##__opname##_ERROR<__ret, __first, __second>:: \
__binary_operator_requirement_violation> \
__dummy_ptr_##__func##__ret##__first##__second##_binary_op
 
#endif
 
/* helper class for finding non-const version of a type. Need to have
something to assign to etc. when testing constant iterators. */
 
template <class _Tp>
struct _Mutable_trait {
typedef _Tp _Type;
};
template <class _Tp>
struct _Mutable_trait<const _Tp> {
typedef _Tp _Type;
};
 
 
/* helper function for avoiding compiler warnings about unused variables */
template <class _Type>
void __sink_unused_warning(_Type) { }
 
template <class _TypeX, class _TypeY>
struct _STL_CONVERT_ERROR {
static void
__type_X_is_not_convertible_to_type_Y(_TypeX __x, _TypeY) {
_TypeY __y = __x;
__sink_unused_warning(__y);
}
};
 
 
template <class _Type> struct __check_equal { };
 
template <class _TypeX, class _TypeY>
struct _STL_SAME_TYPE_ERROR {
static void
__type_X_not_same_as_type_Y(_TypeX , _TypeY ) {
__check_equal<_TypeX> t1 = __check_equal<_TypeY>();
}
};
 
 
// Some Functon Object Checks
 
template <class _Func, class _Ret>
struct _STL_GENERATOR_ERROR {
static _Ret __generator_requirement_violation(_Func& __f) {
return __f();
}
};
 
template <class _Func>
struct _STL_GENERATOR_ERROR<_Func, void> {
static void __generator_requirement_violation(_Func& __f) {
__f();
}
};
 
 
template <class _Func, class _Ret, class _Arg>
struct _STL_UNARY_FUNCTION_ERROR {
static _Ret
__unary_function_requirement_violation(_Func& __f,
const _Arg& __arg) {
return __f(__arg);
}
};
 
template <class _Func, class _Arg>
struct _STL_UNARY_FUNCTION_ERROR<_Func, void, _Arg> {
static void
__unary_function_requirement_violation(_Func& __f,
const _Arg& __arg) {
__f(__arg);
}
};
 
template <class _Func, class _Ret, class _First, class _Second>
struct _STL_BINARY_FUNCTION_ERROR {
static _Ret
__binary_function_requirement_violation(_Func& __f,
const _First& __first,
const _Second& __second) {
return __f(__first, __second);
}
};
 
template <class _Func, class _First, class _Second>
struct _STL_BINARY_FUNCTION_ERROR<_Func, void, _First, _Second> {
static void
__binary_function_requirement_violation(_Func& __f,
const _First& __first,
const _Second& __second) {
__f(__first, __second);
}
};
 
 
#define __STL_DEFINE_BINARY_OP_CHECK(_OP, _NAME) \
template <class _Ret, class _First, class _Second> \
struct _STL_BINARY##_NAME##_ERROR { \
static _Ret \
__const_binary_operator_requirement_violation(const _First& __first, \
const _Second& __second) { \
return __first _OP __second; \
} \
static _Ret \
__binary_operator_requirement_violation(_First& __first, \
_Second& __second) { \
return __first _OP __second; \
} \
}
 
__STL_DEFINE_BINARY_OP_CHECK(==, _OP_EQUAL);
__STL_DEFINE_BINARY_OP_CHECK(!=, _OP_NOT_EQUAL);
__STL_DEFINE_BINARY_OP_CHECK(<, _OP_LESS_THAN);
__STL_DEFINE_BINARY_OP_CHECK(<=, _OP_LESS_EQUAL);
__STL_DEFINE_BINARY_OP_CHECK(>, _OP_GREATER_THAN);
__STL_DEFINE_BINARY_OP_CHECK(>=, _OP_GREATER_EQUAL);
__STL_DEFINE_BINARY_OP_CHECK(+, _OP_PLUS);
__STL_DEFINE_BINARY_OP_CHECK(*, _OP_TIMES);
__STL_DEFINE_BINARY_OP_CHECK(/, _OP_DIVIDE);
__STL_DEFINE_BINARY_OP_CHECK(-, _OP_SUBTRACT);
__STL_DEFINE_BINARY_OP_CHECK(%, _OP_MOD);
// ...
 
// TODO, add unary operators (prefix and postfix)
 
/*
The presence of this class is just to trick EDG into displaying
these error messages before any other errors. Without the
classes, the errors in the functions get reported after
other class errors deep inside the library. The name
choice just makes for an eye catching error message :)
*/
struct _STL_ERROR {
 
template <class _Type>
static _Type
__default_constructor_requirement_violation(_Type) {
return _Type();
}
template <class _Type>
static _Type
__assignment_operator_requirement_violation(_Type __a) {
__a = __a;
return __a;
}
template <class _Type>
static _Type
__copy_constructor_requirement_violation(_Type __a) {
_Type __c(__a);
return __c;
}
template <class _Type>
static _Type
__const_parameter_required_for_copy_constructor(_Type /* __a */,
const _Type& __b) {
_Type __c(__b);
return __c;
}
template <class _Type>
static _Type
__const_parameter_required_for_assignment_operator(_Type __a,
const _Type& __b) {
__a = __b;
return __a;
}
template <class _Type>
static _Type
__less_than_comparable_requirement_violation(_Type __a, _Type __b) {
if (__a < __b) return __a;
return __b;
}
template <class _Type>
static _Type
__equality_comparable_requirement_violation(_Type __a, _Type __b) {
if (__a == __b || __a != __b) return __a;
return __b;
}
template <class _Iterator>
static void
__dereference_operator_requirement_violation(_Iterator __i) {
__sink_unused_warning(*__i);
}
template <class _Iterator>
static void
__dereference_operator_and_assignment_requirement_violation(_Iterator __i) {
*__i = *__i;
}
template <class _Iterator>
static void
__preincrement_operator_requirement_violation(_Iterator __i) {
++__i;
}
template <class _Iterator>
static void
__postincrement_operator_requirement_violation(_Iterator __i) {
__i++;
}
template <class _Iterator>
static void
__predecrement_operator_requirement_violation(_Iterator __i) {
--__i;
}
template <class _Iterator>
static void
__postdecrement_operator_requirement_violation(_Iterator __i) {
__i--;
}
template <class _Iterator, class _Type>
static void
__postincrement_operator_and_assignment_requirement_violation(_Iterator __i,
_Type __t) {
*__i++ = __t;
}
template <class _Iterator, class _Distance>
static _Iterator
__iterator_addition_assignment_requirement_violation(_Iterator __i,
_Distance __n) {
__i += __n;
return __i;
}
template <class _Iterator, class _Distance>
static _Iterator
__iterator_addition_requirement_violation(_Iterator __i, _Distance __n) {
__i = __i + __n;
__i = __n + __i;
return __i;
}
template <class _Iterator, class _Distance>
static _Iterator
__iterator_subtraction_assignment_requirement_violation(_Iterator __i,
_Distance __n) {
__i -= __n;
return __i;
}
template <class _Iterator, class _Distance>
static _Iterator
__iterator_subtraction_requirement_violation(_Iterator __i, _Distance __n) {
__i = __i - __n;
return __i;
}
template <class _Iterator, class _Distance>
static _Distance
__difference_operator_requirement_violation(_Iterator __i, _Iterator __j,
_Distance __n) {
__n = __i - __j;
return __n;
}
template <class _Exp, class _Type, class _Distance>
static _Type
__element_access_operator_requirement_violation(_Exp __x, _Type*,
_Distance __n) {
return __x[__n];
}
template <class _Exp, class _Type, class _Distance>
static void
__element_assignment_operator_requirement_violation(_Exp __x,
_Type* __t,
_Distance __n) {
__x[__n] = *__t;
}
 
}; /* _STL_ERROR */
 
/* Associated Type Requirements */
 
__STL_BEGIN_NAMESPACE
template <class _Iterator> struct iterator_traits;
__STL_END_NAMESPACE
 
template <class _Iter>
struct __value_type_type_definition_requirement_violation {
typedef typename __STD::iterator_traits<_Iter>::value_type value_type;
};
 
template <class _Iter>
struct __difference_type_type_definition_requirement_violation {
typedef typename __STD::iterator_traits<_Iter>::difference_type
difference_type;
};
 
template <class _Iter>
struct __reference_type_definition_requirement_violation {
typedef typename __STD::iterator_traits<_Iter>::reference reference;
};
 
template <class _Iter>
struct __pointer_type_definition_requirement_violation {
typedef typename __STD::iterator_traits<_Iter>::pointer pointer;
};
 
template <class _Iter>
struct __iterator_category_type_definition_requirement_violation {
typedef typename __STD::iterator_traits<_Iter>::iterator_category
iterator_category;
};
 
/* Assignable Requirements */
 
 
template <class _Type>
struct _Assignable_concept_specification {
static void _Assignable_requirement_violation(_Type __a) {
_STL_ERROR::__assignment_operator_requirement_violation(__a);
_STL_ERROR::__copy_constructor_requirement_violation(__a);
_STL_ERROR::__const_parameter_required_for_copy_constructor(__a,__a);
_STL_ERROR::__const_parameter_required_for_assignment_operator(__a,__a);
}
};
 
/* DefaultConstructible Requirements */
 
 
template <class _Type>
struct _DefaultConstructible_concept_specification {
static void _DefaultConstructible_requirement_violation(_Type __a) {
_STL_ERROR::__default_constructor_requirement_violation(__a);
}
};
 
/* EqualityComparable Requirements */
 
template <class _Type>
struct _EqualityComparable_concept_specification {
static void _EqualityComparable_requirement_violation(_Type __a) {
_STL_ERROR::__equality_comparable_requirement_violation(__a, __a);
}
};
 
/* LessThanComparable Requirements */
template <class _Type>
struct _LessThanComparable_concept_specification {
static void _LessThanComparable_requirement_violation(_Type __a) {
_STL_ERROR::__less_than_comparable_requirement_violation(__a, __a);
}
};
 
/* TrivialIterator Requirements */
 
template <class _TrivialIterator>
struct _TrivialIterator_concept_specification {
static void
_TrivialIterator_requirement_violation(_TrivialIterator __i) {
typedef typename
__value_type_type_definition_requirement_violation<_TrivialIterator>::
value_type __T;
// Refinement of Assignable
_Assignable_concept_specification<_TrivialIterator>::
_Assignable_requirement_violation(__i);
// Refinement of DefaultConstructible
_DefaultConstructible_concept_specification<_TrivialIterator>::
_DefaultConstructible_requirement_violation(__i);
// Refinement of EqualityComparable
_EqualityComparable_concept_specification<_TrivialIterator>::
_EqualityComparable_requirement_violation(__i);
// Valid Expressions
_STL_ERROR::__dereference_operator_requirement_violation(__i);
}
};
 
template <class _TrivialIterator>
struct _Mutable_TrivialIterator_concept_specification {
static void
_Mutable_TrivialIterator_requirement_violation(_TrivialIterator __i) {
_TrivialIterator_concept_specification<_TrivialIterator>::
_TrivialIterator_requirement_violation(__i);
// Valid Expressions
_STL_ERROR::__dereference_operator_and_assignment_requirement_violation(__i);
}
};
 
/* InputIterator Requirements */
 
template <class _InputIterator>
struct _InputIterator_concept_specification {
static void
_InputIterator_requirement_violation(_InputIterator __i) {
// Refinement of TrivialIterator
_TrivialIterator_concept_specification<_InputIterator>::
_TrivialIterator_requirement_violation(__i);
// Associated Types
__difference_type_type_definition_requirement_violation<_InputIterator>();
__reference_type_definition_requirement_violation<_InputIterator>();
__pointer_type_definition_requirement_violation<_InputIterator>();
__iterator_category_type_definition_requirement_violation<_InputIterator>();
// Valid Expressions
_STL_ERROR::__preincrement_operator_requirement_violation(__i);
_STL_ERROR::__postincrement_operator_requirement_violation(__i);
}
};
 
/* OutputIterator Requirements */
 
template <class _OutputIterator>
struct _OutputIterator_concept_specification {
static void
_OutputIterator_requirement_violation(_OutputIterator __i) {
// Refinement of Assignable
_Assignable_concept_specification<_OutputIterator>::
_Assignable_requirement_violation(__i);
// Associated Types
__iterator_category_type_definition_requirement_violation<_OutputIterator>();
// Valid Expressions
_STL_ERROR::__dereference_operator_requirement_violation(__i);
_STL_ERROR::__preincrement_operator_requirement_violation(__i);
_STL_ERROR::__postincrement_operator_requirement_violation(__i);
_STL_ERROR::
__postincrement_operator_and_assignment_requirement_violation(__i, *__i);
}
};
 
/* ForwardIterator Requirements */
 
template <class _ForwardIterator>
struct _ForwardIterator_concept_specification {
static void
_ForwardIterator_requirement_violation(_ForwardIterator __i) {
// Refinement of InputIterator
_InputIterator_concept_specification<_ForwardIterator>::
_InputIterator_requirement_violation(__i);
}
};
 
template <class _ForwardIterator>
struct _Mutable_ForwardIterator_concept_specification {
static void
_Mutable_ForwardIterator_requirement_violation(_ForwardIterator __i) {
_ForwardIterator_concept_specification<_ForwardIterator>::
_ForwardIterator_requirement_violation(__i);
// Refinement of OutputIterator
_OutputIterator_concept_specification<_ForwardIterator>::
_OutputIterator_requirement_violation(__i);
}
};
 
/* BidirectionalIterator Requirements */
 
template <class _BidirectionalIterator>
struct _BidirectionalIterator_concept_specification {
static void
_BidirectionalIterator_requirement_violation(_BidirectionalIterator __i) {
// Refinement of ForwardIterator
_ForwardIterator_concept_specification<_BidirectionalIterator>::
_ForwardIterator_requirement_violation(__i);
// Valid Expressions
_STL_ERROR::__predecrement_operator_requirement_violation(__i);
_STL_ERROR::__postdecrement_operator_requirement_violation(__i);
}
};
 
template <class _BidirectionalIterator>
struct _Mutable_BidirectionalIterator_concept_specification {
static void
_Mutable_BidirectionalIterator_requirement_violation(
_BidirectionalIterator __i)
{
_BidirectionalIterator_concept_specification<_BidirectionalIterator>::
_BidirectionalIterator_requirement_violation(__i);
// Refinement of mutable_ForwardIterator
_Mutable_ForwardIterator_concept_specification<_BidirectionalIterator>::
_Mutable_ForwardIterator_requirement_violation(__i);
typedef typename
__value_type_type_definition_requirement_violation<
_BidirectionalIterator>::value_type __T;
typename _Mutable_trait<__T>::_Type* __tmp_ptr = 0;
// Valid Expressions
_STL_ERROR::
__postincrement_operator_and_assignment_requirement_violation(__i,
*__tmp_ptr);
}
};
 
/* RandomAccessIterator Requirements */
 
template <class _RandAccIter>
struct _RandomAccessIterator_concept_specification {
static void
_RandomAccessIterator_requirement_violation(_RandAccIter __i) {
// Refinement of BidirectionalIterator
_BidirectionalIterator_concept_specification<_RandAccIter>::
_BidirectionalIterator_requirement_violation(__i);
// Refinement of LessThanComparable
_LessThanComparable_concept_specification<_RandAccIter>::
_LessThanComparable_requirement_violation(__i);
typedef typename
__value_type_type_definition_requirement_violation<_RandAccIter>
::value_type
value_type;
typedef typename
__difference_type_type_definition_requirement_violation<_RandAccIter>
::difference_type
_Dist;
typedef typename _Mutable_trait<_Dist>::_Type _MutDist;
 
// Valid Expressions
_STL_ERROR::__iterator_addition_assignment_requirement_violation(__i,
_MutDist());
_STL_ERROR::__iterator_addition_requirement_violation(__i,
_MutDist());
_STL_ERROR::
__iterator_subtraction_assignment_requirement_violation(__i,
_MutDist());
_STL_ERROR::__iterator_subtraction_requirement_violation(__i,
_MutDist());
_STL_ERROR::__difference_operator_requirement_violation(__i, __i,
_MutDist());
typename _Mutable_trait<value_type>::_Type* __dummy_ptr = 0;
_STL_ERROR::__element_access_operator_requirement_violation(__i,
__dummy_ptr,
_MutDist());
}
};
 
template <class _RandAccIter>
struct _Mutable_RandomAccessIterator_concept_specification {
static void
_Mutable_RandomAccessIterator_requirement_violation(_RandAccIter __i)
{
_RandomAccessIterator_concept_specification<_RandAccIter>::
_RandomAccessIterator_requirement_violation(__i);
// Refinement of mutable_BidirectionalIterator
_Mutable_BidirectionalIterator_concept_specification<_RandAccIter>::
_Mutable_BidirectionalIterator_requirement_violation(__i);
typedef typename
__value_type_type_definition_requirement_violation<_RandAccIter>
::value_type
value_type;
typedef typename
__difference_type_type_definition_requirement_violation<_RandAccIter>
::difference_type
_Dist;
 
typename _Mutable_trait<value_type>::_Type* __tmp_ptr = 0;
// Valid Expressions
_STL_ERROR::__element_assignment_operator_requirement_violation(__i,
__tmp_ptr, _Dist());
}
};
 
#define __STL_TYPEDEF_REQUIREMENT(__REQUIREMENT) \
template <class Type> \
struct __##__REQUIREMENT##__typedef_requirement_violation { \
typedef typename Type::__REQUIREMENT __REQUIREMENT; \
}
 
__STL_TYPEDEF_REQUIREMENT(value_type);
__STL_TYPEDEF_REQUIREMENT(difference_type);
__STL_TYPEDEF_REQUIREMENT(size_type);
__STL_TYPEDEF_REQUIREMENT(reference);
__STL_TYPEDEF_REQUIREMENT(const_reference);
__STL_TYPEDEF_REQUIREMENT(pointer);
__STL_TYPEDEF_REQUIREMENT(const_pointer);
 
 
template <class _Alloc>
struct _Allocator_concept_specification {
static void
_Allocator_requirement_violation(_Alloc __a) {
// Refinement of DefaultConstructible
_DefaultConstructible_concept_specification<_Alloc>::
_DefaultConstructible_requirement_violation(__a);
// Refinement of EqualityComparable
_EqualityComparable_concept_specification<_Alloc>::
_EqualityComparable_requirement_violation(__a);
// Associated Types
__value_type__typedef_requirement_violation<_Alloc>();
__difference_type__typedef_requirement_violation<_Alloc>();
__size_type__typedef_requirement_violation<_Alloc>();
__reference__typedef_requirement_violation<_Alloc>();
__const_reference__typedef_requirement_violation<_Alloc>();
__pointer__typedef_requirement_violation<_Alloc>();
__const_pointer__typedef_requirement_violation<_Alloc>();
typedef typename _Alloc::value_type _Tp;
//__STL_REQUIRES_SAME_TYPE(typename _Alloc::__STL_TEMPLATE rebind<_Tp>::other,
// _Alloc);
}
};
 
#endif /* __STL_USE_CONCEPT_CHECKS */
 
#endif /* __CONCEPT_CHECKS_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/container_concepts.h
0,0 → 1,244
/*
* Copyright (c) 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 __STL_CONTAINER_CONCEPTS_H
#define __STL_CONTAINER_CONCEPTS_H
 
 
#include <bits/concept_checks.h>
 
#ifdef __STL_USE_CONCEPT_CHECKS
 
 
// This file covers the following concepts:
// _Container
// _ForwardContainer
// _ReversibleContainer
// _const_ReversibleContainer
// _RandomAccessContainer
//
 
struct _ERROR_IN_STL_CONTAINER {
 
/* Container expresssions */
 
template <class _Container>
static void
__begin_iterator_accessor_requirement_violation(_Container __c) {
__c.begin();
}
template <class _Container>
static void
__const_begin_iterator_accessor_requirement_violation(const _Container& __c) {
__c.begin();
}
template <class _Container>
static void
__end_iterator_accessor_requirement_violation(_Container __c) {
__c.end();
}
template <class _Container>
static void
__const_end_iterator_accessor_requirement_violation(const _Container& __c) {
__c.end();
}
 
template <class _Container>
static void
__rbegin_iterator_accessor_requirement_violation(_Container __c) {
__c.rbegin();
}
template <class _Container>
static void
__const_rbegin_iterator_accessor_requirement_violation(const _Container& __c) {
__c.rbegin();
}
template <class _Container>
static void
__rend_iterator_accessor_requirement_violation(_Container __c) {
__c.rend();
}
template <class _Container>
static void
__const_rend_iterator_accessor_requirement_violation(const _Container& __c) {
__c.rend();
}
template <class _Container>
static void
__size_function_must_be_const(const _Container& __c) {
__c.size();
}
template <class _Container>
static void
__size_function_requirement_violation(_Container& __c) {
__c.size();
__size_function_must_be_const(__c);
}
template <class _Container>
static void
__max_size_function_must_be_const(const _Container& __c) {
__c.max_size();
}
template <class _Container>
static void
__max_size_function_requirement_violation(_Container& __c) {
__c.max_size();
__max_size_function_must_be_const(__c);
}
template <class _Container>
static void
__empty_function_must_be_const(const _Container& __c) {
__c.empty();
}
template <class _Container>
static void
__empty_function_requirement_violation(_Container& __c) {
__c.empty();
__empty_function_must_be_const(__c);
}
template <class _Container>
static void
__swap_function_requirement_violation(_Container& __c) {
__c.swap(__c);
}
 
};
 
 
__STL_TYPEDEF_REQUIREMENT(iterator);
__STL_TYPEDEF_REQUIREMENT(const_iterator);
 
/* Containers */
 
template <class _Container>
struct _Container_concept_specification {
static void
_Container_requirement_violation(_Container __c) {
// Refinement of Assignable
_Assignable_concept_specification<_Container>::_Assignable_requirement_violation(__c);
// Associated Types
__value_type__typedef_requirement_violation<_Container>();
__difference_type__typedef_requirement_violation<_Container>();
__size_type__typedef_requirement_violation<_Container>();
__reference__typedef_requirement_violation<_Container>();
__const_reference__typedef_requirement_violation<_Container>();
__pointer__typedef_requirement_violation<_Container>();
__const_pointer__typedef_requirement_violation<_Container>();
__iterator__typedef_requirement_violation<_Container>();
__const_iterator__typedef_requirement_violation<_Container>();
// Valid Expressions
_ERROR_IN_STL_CONTAINER::__const_begin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__const_end_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__begin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__end_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__size_function_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__max_size_function_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__empty_function_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__swap_function_requirement_violation(__c);
// Requirements on Iterators
typedef typename _Container::iterator iter;
typedef typename _Container::const_iterator const_iter;
_InputIterator_concept_specification<const_iter>::_InputIterator_requirement_violation(const_iter());
_InputIterator_concept_specification<iter>::_InputIterator_requirement_violation(iter());
}
};
 
template <class _ForwardContainer>
struct _ForwardContainer_concept_specification {
static void
_ForwardContainer_requirement_violation(_ForwardContainer __c) {
// Refinement of Container
_Container_concept_specification<_ForwardContainer>::_Container_requirement_violation(__c);
// Requirements on Iterators
typedef typename _ForwardContainer::iterator iter;
typedef typename _ForwardContainer::const_iterator const_iter;
_ForwardIterator_concept_specification<const_iter>::_ForwardIterator_requirement_violation(const_iter());
_Mutable_ForwardIterator_concept_specification<iter>::_Mutable_ForwardIterator_requirement_violation(iter());
}
};
 
 
__STL_TYPEDEF_REQUIREMENT(reverse_iterator);
__STL_TYPEDEF_REQUIREMENT(const_reverse_iterator);
 
template <class _ReversibleContainer>
struct _ReversibleContainer_concept_specification {
static void
_ReversibleContainer_requirement_violation(_ReversibleContainer __c) {
// Refinement of ForwardContainer
_ForwardContainer_concept_specification<_ReversibleContainer>::_ForwardContainer_requirement_violation(__c);
// Associated types
__reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
__const_reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
// Valid Expressions
_ERROR_IN_STL_CONTAINER::__const_rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__const_rend_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rend_iterator_accessor_requirement_violation(__c);
// Requirements on Iterators
typedef typename _ReversibleContainer::iterator iter;
typedef typename _ReversibleContainer::const_iterator const_iter;
_BidirectionalIterator_concept_specification<const_iter>::_BidirectionalIterator_requirement_violation(const_iter());
_Mutable_BidirectionalIterator_concept_specification<iter>::_Mutable_BidirectionalIterator_requirement_violation(iter());
}
};
 
template <class _ReversibleContainer>
struct _const_ReversibleContainer_concept_specification {
static void
_const_ReversibleContainer_requirement_violation(_ReversibleContainer __c) {
// Refinement of Container (JGS, not ForwardContainer)
_Container_concept_specification<_ReversibleContainer>::_Container_requirement_violation(__c);
// Associated types
__reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
__const_reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
// Valid Expressions
_ERROR_IN_STL_CONTAINER::__const_rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__const_rend_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rend_iterator_accessor_requirement_violation(__c);
// Requirements on Iterators
typedef typename _ReversibleContainer::iterator iter;
typedef typename _ReversibleContainer::const_iterator const_iter;
_BidirectionalIterator_concept_specification<const_iter>::_BidirectionalIterator_requirement_violation(const_iter());
}
};
 
 
template <class _RandomAccessContainer>
struct _RandomAccessContainer_concept_specification {
static void
_RandomAccessContainer_requirement_violation(_RandomAccessContainer __c) {
// Refinement of ReversibleContainer
_ReversibleContainer_concept_specification<_RandomAccessContainer>::_ReversibleContainer_requirement_violation(__c);
// Valid Expressions
typedef typename _RandomAccessContainer::value_type __T;
typedef typename _RandomAccessContainer::difference_type _Dist;
typedef typename _Mutable_trait<__T>::_Type Type;
typedef Type* _TypePtr;
typedef typename _Mutable_trait<_Dist>::_Type Dist;
_STL_ERROR::__element_access_operator_requirement_violation(__c,
_TypePtr(),
Dist());
// Requirements on Iterators
typedef typename _RandomAccessContainer::iterator iter;
typedef typename _RandomAccessContainer::const_iterator const_iter;
_RandomAccessIterator_concept_specification<const_iter>::_RandomAccessIterator_requirement_violation(const_iter());
_Mutable_RandomAccessIterator_concept_specification<iter>::_Mutable_RandomAccessIterator_requirement_violation(iter());
}
};
 
#endif /* if __STL_USE_CONCEPT_CHECKS */
 
#endif /* __STL_CONTAINER_CONCEPTS_H */
/contrib/media/updf/include/bits/cpp_type_traits.h
0,0 → 1,297
// The -*- C++ -*- type traits classes for internal use in libstdc++
 
// Copyright (C) 2000-2001 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
 
#pragma GCC system_header
 
//
// This file provides some compile-time information about various types.
// These representations 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 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 function templates)
// is highly costly in terms of compiler-resource. It is a Good Thing to
// keep these resource consumption as least as possible.
//
// See valarray_array.h for a case use.
//
// -- 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
/contrib/media/updf/include/bits/endian.h
0,0 → 1,7
/* i386 is little-endian. */
 
#ifndef _ENDIAN_H
# error "Never use <bits/endian.h> directly; include <endian.h> instead."
#endif
 
#define __BYTE_ORDER __LITTLE_ENDIAN
/contrib/media/updf/include/bits/fpos.h
0,0 → 1,121
// File position object and stream types
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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
 
#pragma GCC system_header
 
#include <bits/c++io.h>
#include <bits/std_cwchar.h> // For mbstate_t.
 
namespace std
{
// 27.4.1 Types
 
// 27.4.3 Template class fpos
template<typename _StateT>
class fpos
{
public:
// Types:
typedef _StateT __state_type;
 
private:
streamoff _M_off;
__state_type _M_st;
 
public:
__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_off(streamoff()), _M_st(__state_type()) { }
 
fpos(streamoff __off, __state_type __st = __state_type())
: _M_off(__off), _M_st(__st) { }
 
operator streamoff() const { return _M_off; }
 
fpos&
operator+=(streamoff __off) { _M_off += __off; return *this; }
 
fpos&
operator-=(streamoff __off) { _M_off -= __off; return *this; }
 
fpos
operator+(streamoff __off)
{
fpos __t(*this);
__t += __off;
return __t;
}
 
fpos
operator-(streamoff __off)
{
fpos __t(*this);
__t -= __off;
return __t;
}
 
bool
operator==(const fpos& __pos) const
{ return _M_off == __pos._M_off; }
 
bool
operator!=(const fpos& __pos) const
{ return _M_off != __pos._M_off; }
streamoff
_M_position() const { return _M_off; }
 
void
_M_position(streamoff __off) { _M_off = __off; }
};
 
// 27.2, paragraph 10 about fpos/char_traits circularity
typedef fpos<mbstate_t> streampos;
# ifdef _GLIBCPP_USE_WCHAR_T
typedef fpos<mbstate_t> wstreampos;
# endif
} // namespace std
 
#endif
 
 
 
/contrib/media/updf/include/bits/fstream.tcc
0,0 → 1,605
// File based streams -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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_allocate_file()
{
if (!_M_file)
{
_M_buf_unified = true; // Tie input to output for basic_filebuf.
try
{ _M_file = new __file_type(&_M_lock); }
catch(...)
{
delete _M_file;
__throw_exception_again;
}
}
}
 
template<typename _CharT, typename _Traits>
void
basic_filebuf<_CharT, _Traits>::
_M_allocate_internal_buffer()
{
if (!_M_buf && _M_buf_size_opt)
{
_M_buf_size = _M_buf_size_opt;
 
// Allocate internal buffer.
try { _M_buf = new char_type[_M_buf_size]; }
catch(...)
{
delete [] _M_buf;
__throw_exception_again;
}
_M_buf_allocated = true;
}
}
 
// Both close and setbuf need to deallocate internal buffers, if it exists.
template<typename _CharT, typename _Traits>
void
basic_filebuf<_CharT, _Traits>::
_M_destroy_internal_buffer()
{
if (_M_buf_allocated)
{
delete [] _M_buf;
_M_buf = NULL;
_M_buf_allocated = false;
this->setg(NULL, NULL, NULL);
this->setp(NULL, NULL);
}
}
 
template<typename _CharT, typename _Traits>
void
basic_filebuf<_CharT, _Traits>::
_M_allocate_pback_buffer()
{
if (!_M_pback && _M_pback_size)
{
// Allocate pback buffer.
try
{ _M_pback = new char_type[_M_pback_size]; }
catch(...)
{
delete [] _M_pback;
__throw_exception_again;
}
}
}
 
template<typename _CharT, typename _Traits>
basic_filebuf<_CharT, _Traits>::
basic_filebuf()
: __streambuf_type(), _M_file(NULL), _M_state_cur(__state_type()),
_M_state_beg(__state_type()), _M_buf_allocated(false),
_M_last_overflowed(false)
{ }
 
template<typename _CharT, typename _Traits>
basic_filebuf<_CharT, _Traits>::
basic_filebuf(__c_file_type* __f, ios_base::openmode __mode, int_type __s)
: __streambuf_type(), _M_file(NULL), _M_state_cur(__state_type()),
_M_state_beg(__state_type()), _M_buf_allocated(false),
_M_last_overflowed(false)
{
_M_allocate_file();
_M_file->sys_open(__f, __mode);
if (this->is_open())
{
_M_mode = __mode;
if (__s)
{
_M_buf_size_opt = __s;
_M_allocate_internal_buffer();
_M_set_indeterminate();
}
_M_allocate_pback_buffer();
}
}
 
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 *__ret = NULL;
if (!this->is_open())
{
_M_allocate_file();
_M_file->open(__s, __mode);
if (this->is_open())
{
_M_allocate_internal_buffer();
_M_allocate_pback_buffer();
_M_mode = __mode;
// 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();
__ret = this;
}
}
return __ret;
}
 
template<typename _CharT, typename _Traits>
basic_filebuf<_CharT, _Traits>::__filebuf_type*
basic_filebuf<_CharT, _Traits>::
close()
{
__filebuf_type *__ret = NULL;
if (this->is_open())
{
bool __testput = _M_out_cur && _M_out_beg < _M_out_end;
if (__testput)
_M_really_overflow(traits_type::eof());
 
// NB: Do this here so that re-opened filebufs will be cool...
_M_pback_destroy();
 
#if 0
// XXX not done
if (_M_last_overflowed)
{
_M_output_unshift();
_M_really_overflow(traits_type::eof());
}
#endif
 
_M_mode = ios_base::openmode(0);
_M_destroy_internal_buffer();
 
if (_M_pback)
{
delete [] _M_pback;
_M_pback = NULL;
}
__ret = this;
}
 
// Can actually allocate this file as part of an open and never
// have it be opened.....
if (_M_file)
{
delete _M_file;
_M_file = NULL;
}
_M_last_overflowed = false;
return __ret;
}
 
template<typename _CharT, typename _Traits>
streamsize
basic_filebuf<_CharT, _Traits>::
showmanyc()
{
streamsize __ret = -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)
__ret = _M_in_end - _M_in_cur;
}
_M_last_overflowed = false;
return __ret;
}
 
template<typename _CharT, typename _Traits>
basic_filebuf<_CharT, _Traits>::int_type
basic_filebuf<_CharT, _Traits>::
underflow()
{
int_type __ret = traits_type::eof();
bool __testin = _M_mode & ios_base::in;
bool __testout = _M_mode & ios_base::out;
 
// XXX Should re-enable codecvt bits disabled after 2.90.8.
if (__testin)
{
// Check for pback madness, and if so swich back to the
// normal buffers and jet outta here before expensive
// fileops happen...
if (_M_pback_init)
{
_M_pback_destroy();
if (_M_in_cur < _M_in_end)
return traits_type::to_int_type(*_M_in_cur);
}
 
bool __testget = _M_in_cur && _M_in_beg < _M_in_cur;
bool __testinit = _M_is_indeterminate();
// Sync internal and external buffers.
// NB: __testget -> __testput as _M_buf_unified here.
if (__testget)
{
if (__testout)
_M_really_overflow();
#if _GLIBCPP_AVOID_FSEEK
else if ((_M_in_cur - _M_in_beg) == 1)
_M_file->sys_getc();
#endif
else
_M_file->seekoff(_M_in_cur - _M_in_beg,
ios_base::cur, ios_base::in);
}
 
if (__testinit || __testget)
{
// Assume buffered case, need to refill internal buffers.
streamsize __size = _M_file->xsgetn(_M_in_beg, _M_buf_size);
if (0 < __size)
{
_M_set_determinate(__size);
if (__testout)
_M_out_cur = _M_in_cur;
__ret = traits_type::to_int_type(*_M_in_cur);
#if _GLIBCPP_AVOID_FSEEK
if (__size == 1)
_M_file->sys_ungetc(*_M_in_cur);
else
{
#endif
streamoff __p = _M_file->seekoff(0 - __size, ios_base::cur,
ios_base::in);
if (__p == -1)
{
// XXX Something is wrong, do error checking.
}
#if _GLIBCPP_AVOID_FSEEK
}
#endif
}
}
}
_M_last_overflowed = false;
return __ret;
}
template<typename _CharT, typename _Traits>
basic_filebuf<_CharT, _Traits>::int_type
basic_filebuf<_CharT, _Traits>::
pbackfail(int_type __i)
{
int_type __ret = traits_type::eof();
bool __testin = _M_mode & ios_base::in;
 
if (__testin)
{
bool __testpb = _M_in_beg < _M_in_cur;
char_type __c = traits_type::to_char_type(__i);
bool __testeof = traits_type::eq_int_type(__i, __ret);
 
if (__testpb)
{
bool __testout = _M_mode & ios_base::out;
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 && __testeq)
{
--_M_in_cur;
if (__testout)
--_M_out_cur;
__ret = __i;
}
else if (__testeof)
{
--_M_in_cur;
if (__testout)
--_M_out_cur;
__ret = traits_type::not_eof(__i);
}
else if (!__testeof)
{
--_M_in_cur;
if (__testout)
--_M_out_cur;
_M_pback_create();
*_M_in_cur = __c;
__ret = __i;
}
}
else
{
// At the beginning of the buffer, need to make a
// putback position available.
this->seekoff(-1, ios_base::cur);
this->underflow();
if (!__testeof)
{
if (!traits_type::eq(__c, *_M_in_cur))
{
_M_pback_create();
*_M_in_cur = __c;
}
__ret = __i;
}
else
__ret = traits_type::not_eof(__i);
}
}
_M_last_overflowed = false;
return __ret;
}
 
template<typename _CharT, typename _Traits>
basic_filebuf<_CharT, _Traits>::int_type
basic_filebuf<_CharT, _Traits>::
overflow(int_type __c)
{
int_type __ret = traits_type::eof();
bool __testput = _M_out_cur && _M_out_cur < _M_buf + _M_buf_size;
bool __testout = _M_mode & ios_base::out;
if (__testout)
{
if (__testput)
{
*_M_out_cur = traits_type::to_char_type(__c);
_M_out_cur_move(1);
__ret = traits_type::not_eof(__c);
}
else
__ret = this->_M_really_overflow(__c);
}
 
_M_last_overflowed = false; // Set in _M_really_overflow, below.
return __ret;
}
template<typename _CharT, typename _Traits>
basic_filebuf<_CharT, _Traits>::int_type
basic_filebuf<_CharT, _Traits>::
_M_really_overflow(int_type __c)
{
int_type __ret = traits_type::eof();
bool __testput = _M_out_cur && _M_out_beg < _M_out_end;
bool __testunbuffered = _M_file && !_M_buf_size;
 
if (__testput || __testunbuffered)
{
#if 1
int __plen = _M_out_end - _M_out_beg;
streamsize __len = 0;
 
if (__plen)
__len = _M_file->xsputn(_M_out_beg, __plen);
 
if (__c !=traits_type::eof())
{
char_type __pending = traits_type::to_char_type(__c);
__len += _M_file->xsputn(&__pending, 1);
++__plen;
}
 
// NB: Need this so that external byte sequence reflects
// internal buffer.
_M_file->sync();
if (__len == __plen)
{
_M_set_indeterminate();
__ret = traits_type::not_eof(__c);
}
#else
// 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 = static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __plen + 1));
traits_type::copy(__pbuf, this->pbase(), __plen);
if (!__testeof)
{
__pbuf[__plen] = traits_type::to_char_type(__c);
++__plen;
}
 
char_type* __pend;
char* __conv_buf = static_cast<char*>(__builtin_alloca(__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 __len = _M_file->xsputn(__conv_buf, __plen);
// NB: Need this so that external byte sequence reflects
// internal buffer.
_M_file->sync();
if (__len == __plen)
{
_M_set_indeterminate();
__ret = traits_type::not_eof(__c);
}
}
#endif
}
_M_last_overflowed = true;
return __ret;
}
 
template<typename _CharT, typename _Traits>
basic_filebuf<_CharT, _Traits>::__streambuf_type*
basic_filebuf<_CharT, _Traits>::
setbuf(char_type* __s, streamsize __n)
{
if (!this->is_open() && __s == 0 && __n == 0)
_M_buf_size_opt = 0;
else if (__s && __n)
{
// This is implementation-defined behavior, and assumes
// that an external char_type array of length (__s + __n)
// exists and has been pre-allocated. If this is not the
// case, things will quickly blow up.
// Step 1: Destroy the current internal array.
_M_destroy_internal_buffer();
// Step 2: Use the external array.
_M_buf = __s;
_M_buf_size_opt = _M_buf_size = __n;
_M_set_indeterminate();
// Step 3: Make sure a pback buffer is allocated.
_M_allocate_pback_buffer();
}
_M_last_overflowed = false;
return this;
}
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 __ret = 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;
 
// Should probably do has_facet checks here.
int __width = use_facet<__codecvt_type>(_M_buf_locale).encoding();
if (__width < 0)
__width = 0;
bool __testfail = __off != 0 && __width <= 0;
if (__testopen && !__testfail && (__testin || __testout))
{
// Ditch any pback buffers to avoid confusion.
_M_pback_destroy();
 
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;
__ret = _M_file->seekoff(__computed_off, __way, __mode);
_M_set_indeterminate();
}
// NB: Need to do this in case _M_file in indeterminate
// state, ie _M_file->_offset == -1
else
{
__ret = _M_file->seekoff(__off, ios_base::cur, __mode);
__ret += max(_M_out_cur, _M_in_cur) - _M_buf;
}
}
_M_last_overflowed = false;
return __ret;
}
 
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 __ret;
off_type __off = __pos;
 
__ret = this->seekoff(__off, ios_base::beg, __mode);
 
_M_last_overflowed = false;
return __ret;
}
 
template<typename _CharT, typename _Traits>
void
basic_filebuf<_CharT, _Traits>::
_M_output_unshift()
{ }
 
template<typename _CharT, typename _Traits>
void
basic_filebuf<_CharT, _Traits>::
imbue(const locale& __loc)
{
bool __testbeg = gptr() == eback() && pptr() == pbase();
 
if (__testbeg && _M_buf_locale != __loc)
{
_M_buf_locale = __loc;
_M_buf_locale_init = true;
}
 
// 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
 
 
/contrib/media/updf/include/bits/functexcept.h
0,0 → 1,85
// Function-Based Exception Support -*- C++ -*-
 
// Copyright (C) 2001 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.1 Exception classes
//
 
#include <exception_defines.h>
 
namespace std
{
// Helper for exception objects in <except>
void
__throw_bad_exception(void);
 
// Helper for exception objects in <new>
void
__throw_bad_alloc(void);
 
// Helper for exception objects in <typeinfo>
void
__throw_bad_cast(void);
 
void
__throw_bad_typeid(void);
 
// Helpers for exception objects in <stdexcept>
void
__throw_logic_error(const char* __s);
 
void
__throw_domain_error(const char* __s);
 
void
__throw_invalid_argument(const char* __s);
 
void
__throw_length_error(const char* __s);
 
void
__throw_out_of_range(const char* __s);
 
void
__throw_runtime_error(const char* __s);
 
void
__throw_range_error(const char* __s);
 
void
__throw_overflow_error(const char* __s);
 
void
__throw_underflow_error(const char* __s);
 
// Helpers for exception objects in basic_ios
void
__throw_ios_failure(const char* __s);
} // namespace std
 
/contrib/media/updf/include/bits/generic_shadow.h
0,0 → 1,59
// generic C header shadow file -*- C++ -*-
 
// Copyright (C) 1997-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.
 
// This file is included by all the standard C <foo.h> headers
// after defining _SHADOW_NAME.
 
#ifdef _IN_C_LEGACY_ /* sub-included by a C header */
 
// Get out of the "swamp."
} // Close extern "C"
} // Close namespace _C_legacy::
 
# undef _IN_C_LEGACY_
# include _SHADOW_NAME
 
// Dive back into the "swamp."
namespace _C_legacy {
extern "C" {
# define _IN_C_LEGACY_
#else /* not _IN_C_LEGACY_: 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_legacy::_C_shadow;
#endif /* _IN_C_LEGACY_ */
 
 
/contrib/media/updf/include/bits/gslice.h
0,0 → 1,119
// The template and inlines for the -*- C++ -*- gslice class.
 
// Copyright (C) 1997-2001 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 1
 
#pragma GCC system_header
 
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:
/contrib/media/updf/include/bits/gslice_array.h
0,0 → 1,171
// The template and inlines for the -*- C++ -*- gslice_array class.
 
// Copyright (C) 1997-2001 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
 
#pragma GCC system_header
 
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:
/contrib/media/updf/include/bits/indirect_array.h
0,0 → 1,162
// The template and inlines for the -*- C++ -*- indirect_array class.
 
// Copyright (C) 1997-2001 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 1
 
#pragma GCC system_header
 
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:
/contrib/media/updf/include/bits/ios_base.h
0,0 → 1,569
// Iostreams base classes -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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
 
#pragma GCC system_header
 
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 { _M_ios_fmtflags_end = 1L << 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 { _M_ios_openmode_end = 1L << 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 { _M_ios_iostate_end = 1L << 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 { _M_ios_seekdir_end = 1L << 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) throw();
 
virtual
~failure() throw();
 
virtual const char*
what() const throw();
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_DEPRECATED
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_ios_locale;
 
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();
static void
_S_ios_create(bool __sync);
static void
_S_ios_destroy();
 
private:
static int _S_ios_base_init;
static bool _S_synced_with_stdio;
};
 
// 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_ios_locale; }
 
// 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 */
 
/contrib/media/updf/include/bits/istream.tcc
0,0 → 1,1239
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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>
#include <bits/std_ostream.h> // for flush()
 
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();
const __ctype_type* __ctype = __in._M_get_fctype_ios();
__streambuf_type* __sb = __in.rdbuf();
__int_type __c = __sb->sgetc();
while (__c != __eof && __ctype->is(ctype_base::space, __c))
__c = __sb->snextc();
 
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
//195. Should basic_istream::sentry's constructor ever set eofbit?
if (__c == __eof)
__in.setstate(ios_base::eofbit);
#endif
}
}
 
if (__in.good())
_M_ok = true;
else
{
_M_ok = false;
__in.setstate(ios_base::failbit);
}
}
 
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
operator>>(__istream_type& (*__pf)(__istream_type&))
{
__pf(*this);
return *this;
}
 
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
operator>>(__ios_type& (*__pf)(__ios_type&))
{
__pf(*this);
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
operator>>(ios_base& (*__pf)(ios_base&))
{
__pf(*this);
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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
{
ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
if (_M_check_facet(_M_fnumget))
_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_exception_again;
}
}
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 = __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_exception_again;
}
}
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)
{
try
{
const int_type __eof = traits_type::eof();
int_type __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_exception_again;
}
}
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
{
const int_type __idelim = traits_type::to_int_type(__delim);
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sbumpc();
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_exception_again;
}
}
*__s = char_type();
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)
{
int_type __c;
__streambuf_type* __this_sb = this->rdbuf();
try
{
const int_type __idelim = traits_type::to_int_type(__delim);
const int_type __eof = traits_type::eof();
__c = __this_sb->sbumpc();
bool __testdelim = __c == __idelim;
bool __testeof = __c == __eof;
bool __testput = true;
while (!__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
{
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sbumpc();
++_M_gcount;
const int_type __idelim = traits_type::to_int_type(__delim);
const int_type __eof = traits_type::eof();
bool __testdelim = __c == __idelim;
bool __testeof = __c == __eof;
while (_M_gcount < __n && !__testeof && !__testdelim)
{
*__s++ = traits_type::to_char_type(__c);
__c = __sb->sbumpc();
++_M_gcount;
__testeof = __c == __eof;
__testdelim = __c == __idelim;
}
if (__testeof)
{
--_M_gcount;
this->setstate(ios_base::eofbit);
}
else if (!__testdelim)
{
--_M_gcount;
__sb->sputbackc(traits_type::to_char_type(__c));
this->setstate(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_exception_again;
}
}
*__s = char_type();
if (!_M_gcount)
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
{
const int_type __idelim = traits_type::to_int_type(__delim);
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sbumpc();
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_exception_again;
}
}
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_exception_again;
}
}
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
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sbumpc();
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_exception_again;
}
}
}
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_exception_again;
}
}
}
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_exception_again;
}
}
else
this->setstate(ios_base::failbit);
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
unget(void)
{
_M_gcount = 0;
sentry __cerb(*this, true);
if (__cerb)
{
try
{
const int_type __eof = traits_type::eof();
__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_exception_again;
}
}
else
this->setstate(ios_base::failbit);
return *this;
}
template<typename _CharT, typename _Traits>
int
basic_istream<_CharT, _Traits>::
sync(void)
{
int __ret = traits_type::eof();
_M_gcount = 0;
sentry __cerb(*this, true);
if (__cerb)
{
try
{
__streambuf_type* __sb = this->rdbuf();
if (!__sb || __ret == __sb->pubsync())
this->setstate(ios_base::badbit);
else
__ret = 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_exception_again;
}
}
return __ret;
}
template<typename _CharT, typename _Traits>
typename basic_istream<_CharT, _Traits>::pos_type
basic_istream<_CharT, _Traits>::
tellg(void)
{
pos_type __ret = pos_type(-1);
_M_gcount = 0;
sentry __cerb(*this, true);
if (__cerb)
{
try
{
__ret = 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_exception_again;
}
}
return __ret;
}
 
 
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?
pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::in);
 
// 129. Need error indication from seekp() and seekg()
if (__err == pos_type(off_type(-1)))
this->setstate(failbit);
#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_exception_again;
}
}
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?
pos_type __err = this->rdbuf()->pubseekoff(__off, __dir,
ios_base::in);
 
// 129. Need error indication from seekp() and seekg()
if (__err == pos_type(off_type(-1)))
this->setstate(failbit);
#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_exception_again;
}
}
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;
typename __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_exception_again;
}
}
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;
streamsize __extracted = 0;
 
typename __istream_type::sentry __cerb(__in, false);
if (__cerb)
{
try
{
// Figure out how many characters to extract.
streamsize __num = __in.width();
if (__num == 0)
__num = numeric_limits<streamsize>::max();
__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_exception_again;
}
}
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.9 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;
__size_type __extracted = 0;
 
typename __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;
typename __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:
 
/contrib/media/updf/include/bits/limits_generic.h
0,0 → 1,788
// The template and inlines for the -*- C++ -*- numeric_limits classes.
 
// Copyright (C) 2000-2001 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
 
#pragma GCC system_header
 
#include <bits/c++config.h>
#include <bits/std_cfloat.h>
#include <bits/std_climits.h>
#if defined( _GLIBCPP_USE_WCHAR_T)
#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 = 1;
static const int digits10 = 0;
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 = 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<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)
template<> struct numeric_limits<wchar_t> {
static const bool is_specialized = true;
 
static wchar_t min() throw()
{ return WCHAR_MIN; }
static wchar_t max() throw()
{ return WCHAR_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
/contrib/media/updf/include/bits/locale_facets.h
0,0 → 1,1601
// Locale support -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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
 
#pragma GCC system_header
 
#include <bits/std_ctime.h> // For struct tm
#include <bits/std_ios.h> // For ios_base
#ifdef _GLIBCPP_USE_WCHAR_T
# include <langinfo.h> // For codecvt
# include <bits/std_cwctype.h> // For wctype_t
# include <iconv.h> // For codecvt using iconv, iconv_t
#endif
 
namespace std
{
// 22.2.1.1 Template class ctype
// Include host-specific ctype enums for ctype_base.
#include <bits/ctype_base.h>
 
// __ctype_abstract_base is the common base for ctype<_CharT>.
template<typename _CharT>
class __ctype_abstract_base : public locale::facet, public ctype_base
{
public:
// Types:
typedef _CharT char_type;
 
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); }
 
char_type
toupper(char_type __c) const
{ return this->do_toupper(__c); }
 
const char_type*
toupper(char_type *__lo, const char_type* __hi) const
{ return this->do_toupper(__lo, __hi); }
 
char_type
tolower(char_type __c) const
{ return this->do_tolower(__c); }
 
const char_type*
tolower(char_type* __lo, const char_type* __hi) const
{ return this->do_tolower(__lo, __hi); }
 
char_type
widen(char __c) const
{ return this->do_widen(__c); }
 
const char*
widen(const char* __lo, const char* __hi, char_type* __to) const
{ return this->do_widen(__lo, __hi, __to); }
 
char
narrow(char_type __c, char __dfault) const
{ return this->do_narrow(__c, __dfault); }
 
const char_type*
narrow(const char_type* __lo, const char_type* __hi,
char __dfault, char *__to) const
{ return this->do_narrow(__lo, __hi, __dfault, __to); }
 
protected:
explicit
__ctype_abstract_base(size_t __refs = 0): locale::facet(__refs) { }
 
virtual
~__ctype_abstract_base() { }
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;
 
virtual char_type
do_toupper(char_type) const = 0;
 
virtual const char_type*
do_toupper(char_type* __lo, const char_type* __hi) const = 0;
 
virtual char_type
do_tolower(char_type) const = 0;
 
virtual const char_type*
do_tolower(char_type* __lo, const char_type* __hi) const = 0;
virtual char_type
do_widen(char) const = 0;
 
virtual const char*
do_widen(const char* __lo, const char* __hi,
char_type* __dest) const = 0;
 
virtual char
do_narrow(char_type, char __dfault) const = 0;
 
virtual const char_type*
do_narrow(const char_type* __lo, const char_type* __hi,
char __dfault, char* __dest) const = 0;
};
 
// NB: Generic, mostly useless implementation.
template<typename _CharT>
class ctype : public __ctype_abstract_base<_CharT>
{
public:
// Types:
typedef _CharT char_type;
typedef typename ctype::mask mask;
 
explicit
ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { }
 
static locale::id id;
 
protected:
virtual
~ctype() { }
 
virtual bool
do_is(mask __m, char_type __c) const
{ return false; }
 
virtual const char_type*
do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const
{ return __hi; }
 
virtual const char_type*
do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
{ return __hi; }
 
virtual const char_type*
do_scan_not(mask __m, const char_type* __lo,
const char_type* __hi) const
{ return __hi; }
 
virtual char_type
do_toupper(char_type __c) const
{ return __c; }
 
virtual const char_type*
do_toupper(char_type* __lo, const char_type* __hi) const
{ return __hi; }
 
virtual char_type
do_tolower(char_type __c) const
{ return __c; }
 
virtual const char_type*
do_tolower(char_type* __lo, const char_type* __hi) const
{ return __hi; }
virtual char_type
do_widen(char __c) const
{ return char_type(); }
 
virtual const char*
do_widen(const char* __lo, const char* __hi, char_type* __dest) const
{ return __hi; }
 
virtual char
do_narrow(char_type, char __dfault) const
{ return __dfault; }
 
virtual const char_type*
do_narrow(const char_type* __lo, const char_type* __hi,
char __dfault, char* __dest) const
{ return __hi; }
};
 
template<typename _CharT>
locale::id ctype<_CharT>::id;
 
// 22.2.1.3 ctype specializations
template<>
class ctype<char> : public __ctype_abstract_base<char>
{
public:
// Types:
typedef char char_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 size_t table_size = 1 + static_cast<unsigned char>(-1);
 
explicit
ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0);
 
inline bool
is(mask __m, char __c) const;
inline const char*
is(const char* __lo, const char* __hi, mask* __vec) const;
inline const char*
scan_is(mask __m, const char* __lo, const char* __hi) const;
 
inline const char*
scan_not(mask __m, const char* __lo, const char* __hi) const;
protected:
virtual
~ctype();
 
const mask*
table() const throw()
{ return _M_table; }
 
const mask*
classic_table() throw()
{ return _M_ctable; }
 
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* __lo, const char_type* __hi) const;
 
virtual char_type
do_tolower(char_type) const;
 
virtual const char_type*
do_tolower(char_type* __lo, const char_type* __hi) const;
virtual char_type
do_widen(char) const;
 
virtual const char*
do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
 
virtual char
do_narrow(char_type, char __dfault) const;
 
virtual const char_type*
do_narrow(const char_type* __lo, const char_type* __hi,
char __dfault, char* __dest) const;
};
template<>
const ctype<char>&
use_facet<ctype<char> >(const locale& __loc);
 
#ifdef _GLIBCPP_USE_WCHAR_T
// ctype<wchar_t> specialization
template<>
class ctype<wchar_t> : public __ctype_abstract_base<wchar_t>
{
public:
// Types:
typedef wchar_t char_type;
typedef wctype_t __wmask_type;
 
// Data Members:
static locale::id id;
 
explicit
ctype(size_t __refs = 0);
 
protected:
__wmask_type
_M_convert_to_wmask(const mask __m) const;
 
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* __lo, const char_type* __hi) const;
 
virtual char_type
do_tolower(char_type) const;
 
virtual const char_type*
do_tolower(char_type* __lo, const char_type* __hi) const;
virtual char_type
do_widen(char) const;
 
virtual const char*
do_widen(const char* __lo, const char* __hi, char_type* __dest) const;
 
virtual char
do_narrow(char_type, char __dfault) const;
 
virtual const char_type*
do_narrow(const char_type* __lo, const char_type* __hi,
char __dfault, char* __dest) const;
 
};
 
template<>
const ctype<wchar_t>&
use_facet<ctype<wchar_t> >(const locale& __loc);
#endif //_GLIBCPP_USE_WCHAR_T
 
// Include host-specific ctype inlines.
#include <bits/ctype_inline.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 specialization
template<>
ctype_byname<char>::ctype_byname(const char*, size_t refs);
 
 
// 22.2.1.5 Template class codecvt
#include <bits/codecvt.h>
 
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 typename 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_x,
_S_X,
_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<typename _CharT>
int _Format_cache<_CharT>::_S_pword_ix;
 
template<typename _CharT>
const char _Format_cache<_CharT>::
_S_literals[] = "-+xX0123456789abcdef0123456789ABCDEF";
 
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;
 
static locale::id id;
 
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); }
 
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;
};
 
template<typename _CharT, typename _InIter>
locale::id num_get<_CharT, _InIter>::id;
 
// 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;
 
static locale::id id;
 
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); }
 
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, typename _OutIter>
locale::id num_put<_CharT, _OutIter>::id;
 
template<typename _CharT>
class numpunct : public locale::facet
{
public:
// Types:
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
 
static locale::id id;
 
private:
char_type _M_decimal_point;
char_type _M_thousands_sep;
string _M_grouping;
string_type _M_truename;
string_type _M_falsename;
 
public:
explicit
numpunct(size_t __refs = 0) : locale::facet(__refs)
{ _M_initialize_numpunct(); }
 
explicit
numpunct(__c_locale __cloc, size_t __refs = 0) : locale::facet(__refs)
{ _M_initialize_numpunct(__cloc); }
 
char_type
decimal_point() const
{ return do_decimal_point(); }
 
char_type
thousands_sep() const
{ return do_thousands_sep(); }
 
string
grouping() const
{ return do_grouping(); }
 
string_type
truename() const
{ return do_truename(); }
 
string_type
falsename() const
{ return do_falsename(); }
 
protected:
virtual
~numpunct() { }
 
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; }
 
virtual string_type
do_truename() const
{ return _M_truename; }
 
virtual string_type
do_falsename() const
{ return _M_falsename; }
 
// For use at construction time only.
void
_M_initialize_numpunct(__c_locale __cloc = NULL);
};
 
template<typename _CharT>
locale::id numpunct<_CharT>::id;
 
template<typename _CharT>
void
numpunct<_CharT>::_M_initialize_numpunct(__c_locale /*__cloc*/)
{
// NB: Cannot be made generic.
}
 
template<>
void
numpunct<char>::_M_initialize_numpunct(__c_locale __cloc);
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
void
numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc);
#endif
 
 
template<typename _CharT>
class numpunct_byname : public numpunct<_CharT>
{
__c_locale _M_c_locale_numpunct;
public:
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
 
explicit
numpunct_byname(const char* __s, size_t __refs = 0)
: numpunct<_CharT>(__refs)
{
_S_create_c_locale(_M_c_locale_numpunct, __s);
_M_initialize_numpunct(_M_c_locale_numpunct);
}
 
protected:
virtual
~numpunct_byname()
{ _S_destroy_c_locale(_M_c_locale_numpunct); }
};
 
 
template<typename _CharT>
class collate : public locale::facet
{
public:
// Types:
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
 
static locale::id id;
 
explicit
collate(size_t __refs = 0) : locale::facet(__refs) { }
 
int
compare(const _CharT* __lo1, const _CharT* __hi1,
const _CharT* __lo2, const _CharT* __hi2) const
{ return this->do_compare(__lo1, __hi1, __lo2, __hi2); }
 
string_type
transform(const _CharT* __lo, const _CharT* __hi) const
{ return this->do_transform(__lo, __hi); }
 
long
hash(const _CharT* __lo, const _CharT* __hi) const
{ return this->do_hash(__lo, __hi); }
protected:
~collate() { } // virtual
 
virtual int
do_compare(const _CharT* __lo1, const _CharT* __hi1,
const _CharT* __lo2, const _CharT* __hi2) const;
 
virtual string_type
do_transform(const _CharT* __lo, const _CharT* __hi) const;
 
virtual long
do_hash(const _CharT* __lo, const _CharT* __hi) const;
};
 
template<typename _CharT>
locale::id collate<_CharT>::id;
 
// Required specializations.
template<>
int
collate<char>::do_compare(const char* __lo1, const char* __hi1,
const char* __lo2, const char* __hi2) const;
 
template<>
string
collate<char>::do_transform(const char* __lo, const char* __hi) const;
 
template<>
long
collate<char>::do_hash(const char* __lo, const char* __hi) const;
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
int
collate<wchar_t>::do_compare(const wchar_t* __lo1, const wchar_t* __hi1,
const wchar_t* __lo2,
const wchar_t* __hi2) const;
 
template<>
wstring
collate<wchar_t>::do_transform(const wchar_t* __lo,
const wchar_t* __hi) const;
 
template<>
long
collate<wchar_t>::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;
 
static locale::id id;
 
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); }
 
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>
locale::id time_get<_CharT, _InIter>::id;
 
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;
 
static locale::id id;
 
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); }
 
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>
locale::id time_put<_CharT, _OutIter>::id;
 
template<typename _CharT, typename _OutIter>
class time_put_byname : public 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;
 
static locale::id id;
 
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); }
 
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 _InIter>
locale::id money_get<_CharT, _InIter>::id;
 
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;
 
static locale::id id;
 
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); }
 
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; }
};
 
template<typename _CharT, typename _OutIter>
locale::id money_put<_CharT, _OutIter>::id;
 
struct money_base
{
enum part { none, space, symbol, sign, value };
struct pattern { char field[4]; };
 
static const pattern _S_default_pattern;
 
// Construct and return valid pattern consisting of some combination of:
// space none symbol sign value
static pattern
_S_construct_pattern(char __preceeds, char __space, char __posn);
};
 
template<typename _CharT, bool _Intl>
class moneypunct : public locale::facet, public money_base
{
public:
// Types:
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
 
static const bool intl = _Intl;
static locale::id id;
 
private:
char_type _M_decimal_point;
char_type _M_thousands_sep;
string _M_grouping;
string_type _M_curr_symbol;
string_type _M_positive_sign;
string_type _M_negative_sign;
int _M_frac_digits;
pattern _M_pos_format;
pattern _M_neg_format;
 
public:
explicit
moneypunct(size_t __refs = 0) : locale::facet(__refs)
{ _M_initialize_moneypunct(); }
 
explicit
moneypunct(__c_locale __cloc, size_t __refs = 0) : locale::facet(__refs)
{ _M_initialize_moneypunct(__cloc); }
 
char_type
decimal_point() const
{ return this->do_decimal_point(); }
char_type
thousands_sep() const
{ return this->do_thousands_sep(); }
string
grouping() const
{ return this->do_grouping(); }
 
string_type
curr_symbol() const
{ return this->do_curr_symbol(); }
 
string_type
positive_sign() const
{ return this->do_positive_sign(); }
 
string_type
negative_sign() const
{ return this->do_negative_sign(); }
 
int
frac_digits() const
{ return this->do_frac_digits(); }
 
pattern
pos_format() const
{ return this->do_pos_format(); }
 
pattern
neg_format() const
{ return this->do_neg_format(); }
 
protected:
virtual
~moneypunct() { }
 
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; }
 
virtual string_type
do_curr_symbol() const
{ return _M_curr_symbol; }
 
virtual string_type
do_positive_sign() const
{ return _M_positive_sign; }
 
virtual string_type
do_negative_sign() const
{ return _M_negative_sign; }
 
virtual int
do_frac_digits() const
{ return _M_frac_digits; }
 
virtual pattern
do_pos_format() const
{ return _M_pos_format; }
 
virtual pattern
do_neg_format() const
{ return _M_neg_format; }
 
// For use at construction time only.
void
_M_initialize_moneypunct(__c_locale __cloc = NULL);
};
 
template<typename _CharT, bool _Intl>
locale::id moneypunct<_CharT, _Intl>::id;
 
template<typename _CharT, bool _Intl>
const bool moneypunct<_CharT, _Intl>::intl;
 
template<typename _CharT, bool _Intl>
void
moneypunct<_CharT, _Intl>::_M_initialize_moneypunct(__c_locale /*__cloc*/)
{
// NB: Cannot be made generic.
}
 
template<>
void
moneypunct<char>::_M_initialize_moneypunct(__c_locale __cloc);
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
void
moneypunct<wchar_t>::_M_initialize_moneypunct(__c_locale __cloc);
#endif
 
template<typename _CharT, bool _Intl>
class moneypunct_byname : public moneypunct<_CharT, _Intl>
{
__c_locale _M_c_locale_moneypunct;
public:
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
 
static const bool intl = _Intl;
 
explicit
moneypunct_byname(const char* __s, size_t __refs = 0)
: moneypunct<_CharT, _Intl>(__refs)
{
_S_create_c_locale(_M_c_locale_moneypunct, __s);
_M_initialize_moneypunct(_M_c_locale_moneypunct);
}
 
protected:
virtual
~moneypunct_byname()
{ _S_destroy_c_locale(_M_c_locale_moneypunct); }
};
 
template<typename _CharT, bool _Intl>
const bool moneypunct_byname<_CharT, _Intl>::intl;
 
 
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;
 
static locale::id id;
 
explicit
messages(size_t __refs = 0) : locale::facet(__refs) { }
 
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:
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>
locale::id messages<_CharT>::id;
 
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:
/contrib/media/updf/include/bits/locale_facets.tcc
0,0 → 1,1227
// Locale support -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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_clocale.h> // For localeconv
#include <bits/std_cstdlib.h> // For strof, strtold
#include <bits/std_limits.h> // For numeric_limits
#include <bits/std_memory.h> // For auto_ptr
#include <bits/sbuf_iter.h> // For streambuf_iterators
#include <bits/std_cctype.h> // For isspace
#include <typeinfo> // For bad_cast
#include <bits/std_vector.h>
 
 
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);
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
{
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)
{
typedef locale::_Impl::__vec_facet __vec_facet;
size_t __i = _Facet::id._M_index;
__vec_facet* __facet = __loc._M_impl->_M_facets;
const locale::facet* __fp = (*__facet)[__i];
if (__fp == 0 || __i >= __facet->size())
__throw_bad_cast();
return static_cast<const _Facet&>(*__fp);
}
 
template<typename _Facet>
bool
has_facet(const locale& __loc) throw()
{
typedef locale::_Impl::__vec_facet __vec_facet;
size_t __i = _Facet::id._M_index;
__vec_facet* __facet = __loc._M_impl->_M_facets;
return (__i < __facet->size() && (*__facet)[__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;
while (__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 __ti2 = 0; __ti2 < __remain; )
{
const __string_type& __target = __targets[__matches[__ti2]];
if (__pos < __target.size())
{
if (__eof || __target[__pos] != *__s)
{
__matches[__ti2] = __matches[--__remain];
continue;
}
__matched = true;
}
++__ti2;
}
if (__matched)
{
++__s;
++__pos;
}
for (int __ti3 = 0; __ti3 < __remain;)
{
if (__pos > __targets[__matches[__ti3]].size())
{
__matches[__ti3] = __matches[--__remain];
continue;
}
++__ti3;
}
}
while (__remain);
return __s;
}
 
template<typename _CharT>
_Format_cache<_CharT>::_Format_cache()
: _M_valid(true), _M_use_grouping(false)
{ }
 
template<>
_Format_cache<char>::_Format_cache();
 
template<>
_Format_cache<wchar_t>::_Format_cache();
 
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;
}
 
// 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(_InIter /*__beg*/, _InIter /*__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;
 
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// NB: This is an unresolved library defect #17
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;
}
#endif
 
#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_USE_C99
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_USE_C99) && !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<typename __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;
}
 
// __pad is specialized for ostreambuf_iterator, random access iterator.
template <typename _CharT, typename _OutIter>
inline _OutIter
__pad(_OutIter __s, _CharT __fill, int __padding);
 
template <typename _CharT, typename _RaIter>
_RaIter
__pad(_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
__pad(_OutIter __s, _CharT __fill, int __padding, _Tag)
{
while (--__padding >= 0) { *__s = __fill; ++__s; }
return __s;
}
 
template <typename _CharT, typename _OutIter>
inline _OutIter
__pad(_OutIter __s, _CharT __fill, int __padding)
{
return __pad(__s, __fill, __padding,
typename iterator_traits<_OutIter>::iterator_category());
}
 
template <typename _CharT, typename _OutIter>
_OutIter
__pad_numeric(_OutIter __s, ios_base::fmtflags /*__flags*/,
_CharT /*__fill*/, int /*__width*/,
_CharT const* /*__first*/, _CharT const* /*__middle*/,
_CharT const* /*__last*/)
{
// XXX Not currently done: non streambuf_iterator
return __s;
}
 
// Partial specialization for ostreambuf_iterator.
template <typename _CharT>
ostreambuf_iterator<_CharT>
__pad_numeric(ostreambuf_iterator<_CharT> __s, ios_base::fmtflags __flags,
_CharT __fill, int __width, _CharT const* __first,
_CharT const* __middle, _CharT const* __last)
{
typedef ostreambuf_iterator<_CharT> __out_iter;
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)
{
__pad(__s, __fill, __padding);
__padding = 0;
}
copy(__first, __middle, __s);
}
__out_iter __s2 = __s;
 
if (__padding && __aflags != ios_base::left)
{
__pad(__s2, __fill, __padding);
__padding = 0;
}
__out_iter __s3 = copy(__middle, __last, __s2);
if (__padding)
__pad(__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 __output_integer(__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;
}
 
// __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*
__group_digits(_CharT* __s, _CharT __grsep, char const* __grouping,
char const* __grend, _CharT const* __first,
_CharT const* __last)
{
if (__last - __first > *__grouping)
{
__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
__output_integer(_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_x +
((__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 __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 = __group_digits(__p, __fmt->_M_thousands_sep, __gr,
__gr + __fmt->_M_grouping.size(), __sign_end, __digits + _M_room);
return __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 __output_integer(__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 __output_integer(__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 __output_integer(__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 __output_integer(__s, __io, __fill, false, __v); }
#endif
 
// Generic helper function
template<typename _CharT, typename _Traits, typename _OutIter>
_OutIter
__output_float(_OutIter __s, ios_base& __io, _CharT __fill,
const char* __sptr, size_t __slen)
{
// XXX Not currently done: non streambuf_iterator
return __s;
}
 
// Partial specialization for ostreambuf_iterator.
template<typename _CharT, typename _Traits>
ostreambuf_iterator<_CharT, _Traits>
__output_float(ostreambuf_iterator<_CharT, _Traits> __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 = __pad(__s, __fill, __padding);
__padding = 0;
}
else if (__adjfield != ios_base::left)
{
__s = __pad(__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)
__pad(__s, __fill, __padding);
__io.width(0);
return __s;
}
 
bool
__build_float_format(ios_base& __io, char* __fptr, char __modifier,
streamsize __prec);
 
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 (__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 __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 (__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 __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 = __output_integer(__s, __io, __fill, false,
reinterpret_cast<unsigned long>(__v));
__io.flags(__fmt);
return __s2;
}
catch (...) {
__io.flags(__fmt);
__throw_exception_again;
}
}
 
// 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>
_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;
}
} // std::
 
#endif /* _CPP_BITS_LOCFACETS_TCC */
 
// Local Variables:
// mode:c++
// End:
/contrib/media/updf/include/bits/localefwd.h
0,0 → 1,459
// Locale support -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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
 
#pragma GCC system_header
 
#include <bits/c++config.h>
#include <bits/c++locale.h> // Defines __c_locale.
#include <bits/std_climits.h> // For CHAR_BIT
#include <bits/std_string.h> // For string
#include <bits/std_cctype.h> // For isspace, etc.
#include <bits/functexcept.h>
 
namespace std
{
// NB: Don't instantiate required wchar_t facets if no wchar_t support.
#ifdef _GLIBCPP_USE_WCHAR_T
# define _GLIBCPP_NUM_FACETS 26
#else
# define _GLIBCPP_NUM_FACETS 13
#endif
 
// 22.1.1 Locale
template<typename _Tp, typename _Alloc>
class vector;
class locale;
 
// 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 locale_facets.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;
 
// 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<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
{
public:
// Types:
typedef unsigned int category;
 
// Forward decls and friends:
class facet;
class id;
class _Impl;
 
friend class facet;
friend class _Impl;
 
template<typename _Facet>
friend const _Facet&
use_facet(const locale&);
template<typename _Facet>
friend bool
has_facet(const locale&) throw();
// Category values:
// NB: Order must match _S_facet_categories definition in locale.cc
static const category none = 0;
static const category ctype = 1L << 0;
static const category numeric = 1L << 1;
static const category collate = 1L << 2;
static const category time = 1L << 3;
static const category monetary = 1L << 4;
static const category messages = 1L << 5;
static const category all = (collate | ctype | monetary |
numeric | time | messages);
 
// Construct/copy/destroy:
locale() throw();
 
locale(const locale& __other) throw();
 
explicit
locale(const char* __std_name);
 
locale(const locale& __base, const char* __s, category __cat);
 
locale(const locale& __base, const locale& __add, category __cat);
 
template<typename _Facet>
locale(const locale& __other, _Facet* __f);
 
~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 !(this->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:
// The (shared) implementation
_Impl* _M_impl;
 
// The "C" reference locale
static _Impl* _S_classic;
 
// Current global reference locale
static _Impl* _S_global;
 
static const size_t _S_num_categories = 6;
static const size_t _S_num_facets = _GLIBCPP_NUM_FACETS;
 
explicit
locale(_Impl*) throw();
 
static inline void
_S_initialize()
{ if (!_S_classic) classic(); }
 
static category
_S_normalize_category(category);
 
void
_M_coalesce(const locale& __base, const locale& __add, category __cat);
};
 
 
// locale implementation object
class locale::_Impl
{
public:
// Types.
typedef vector<facet*, allocator<facet*> > __vec_facet;
 
// Friends.
friend class locale;
friend class locale::facet;
 
template<typename _Facet>
friend const _Facet&
use_facet(const locale&);
 
template<typename _Facet>
friend bool
has_facet(const locale&) throw();
 
private:
// Data Members.
size_t _M_references;
__vec_facet* _M_facets;
string _M_names[_S_num_categories];
__c_locale _M_c_locale;
static const locale::id* const _S_id_ctype[];
static const locale::id* const _S_id_numeric[];
static const locale::id* const _S_id_collate[];
static const locale::id* const _S_id_time[];
static const locale::id* const _S_id_monetary[];
static const locale::id* const _S_id_messages[];
static const locale::id* const* const _S_facet_categories[];
 
inline void
_M_add_reference() throw()
{ ++_M_references; } // XXX MT
 
inline void
_M_remove_reference() throw()
{
if (_M_references-- == 0) // XXX MT
{
try
{ delete this; }
catch(...)
{ }
}
}
 
_Impl(const _Impl&, size_t);
_Impl(string __name, size_t);
~_Impl() throw();
 
bool
_M_check_same_name()
{
bool __ret = true;
for (size_t i = 0; i < _S_num_categories - 1; ++i)
__ret &= _M_names[i] == _M_names[i + 1];
return __ret;
}
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); }
};
 
template<typename _Facet>
locale::locale(const locale& __other, _Facet* __f)
{
_M_impl = new _Impl(*__other._M_impl, 1);
_M_impl->_M_install_facet(&_Facet::id, __f);
for (size_t __i = 0; __i < _S_num_categories; ++__i)
_M_impl->_M_names[__i] = "*";
}
 
// 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() { };
 
static void
_S_create_c_locale(__c_locale& __cloc, const char* __s);
 
static void
_S_destroy_c_locale(__c_locale& __cloc);
 
private:
size_t _M_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
{
private:
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 ();
 
// 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;
 
// Last id number assigned
static size_t _S_highwater;
 
void
operator=(const id&); // not defined
 
id(const id&); // not defined
 
public:
// NB: This class is always a static data member, and thus can be
// counted on to be zero-initialized.
// XXX id() : _M_index(0) { }
id() { }
};
 
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:
 
/contrib/media/updf/include/bits/mask_array.h
0,0 → 1,162
// The template and inlines for the -*- C++ -*- mask_array class.
 
// Copyright (C) 1997-2001 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
 
#pragma GCC system_header
 
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:
/contrib/media/updf/include/bits/ostream.tcc
0,0 → 1,755
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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_exception_again;
}
}
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_exception_again;
}
}
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_exception_again;
}
}
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_check_facet(_M_fnumput))
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_exception_again;
}
}
return *this;
}
 
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(long __n)
{
sentry __cerb(*this);
if (__cerb)
{
try
{
char_type __c = this->fill();
ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
if (_M_check_facet(_M_fnumput))
{
bool __b = false;
if (__fmt & ios_base::oct || __fmt & ios_base::hex)
{
unsigned long __l = static_cast<unsigned long>(__n);
__b = _M_fnumput->put(*this, *this, __c, __l).failed();
}
else
__b = _M_fnumput->put(*this, *this, __c, __n).failed();
if (__b)
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_exception_again;
}
}
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_check_facet(_M_fnumput))
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_exception_again;
}
}
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
{
char_type __c = this->fill();
ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
if (_M_check_facet(_M_fnumput))
{
bool __b = false;
if (__fmt & ios_base::oct || __fmt & ios_base::hex)
{
unsigned long long __l;
__l = static_cast<unsigned long long>(__n);
__b = _M_fnumput->put(*this, *this, __c, __l).failed();
}
else
__b = _M_fnumput->put(*this, *this, __c, __n).failed();
if (__b)
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_exception_again;
}
}
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_check_facet(_M_fnumput))
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_exception_again;
}
}
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_check_facet(_M_fnumput))
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_exception_again;
}
}
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_check_facet(_M_fnumput))
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_exception_again;
}
}
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_check_facet(_M_fnumput))
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_exception_again;
}
}
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 = __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 __ret = pos_type(-1);
bool __testok = this->fail() != true;
if (__testok)
__ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
return __ret;
}
 
 
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?
pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::out);
 
// 129. Need error indication from seekp() and seekg()
if (__err == pos_type(off_type(-1)))
this->setstate(failbit);
#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?
pos_type __err = this->rdbuf()->pubseekoff(__off, __d,
ios_base::out);
 
// 129. Need error indication from seekp() and seekg()
if (__err == pos_type(off_type(-1)))
this->setstate(failbit);
}
#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 __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>
void
__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 = static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __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;
typename __ostream_type::sentry __cerb(__out);
if (__cerb)
{
try
{
streamsize __w = __out.width();
_CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
__pads[0] = __c;
streamsize __len = 1;
if (__w > __len)
{
__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_exception_again;
}
}
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;
typename __ostream_type::sentry __cerb(__out);
if (__cerb)
{
try
{
streamsize __w = __out.width();
char* __pads = static_cast<char*>(__builtin_alloca(__w + 1));
__pads[0] = __c;
streamsize __len = 1;
if (__w > __len)
{
__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_exception_again;
}
}
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;
typename __ostream_type::sentry __cerb(__out);
if (__cerb)
{
try
{
streamsize __w = __out.width();
_CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
streamsize __len = static_cast<streamsize>(_Traits::length(__s));
if (__w > __len)
{
__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_exception_again;
}
}
return __out;
}
 
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
{
typedef basic_ostream<_CharT, _Traits> __ostream_type;
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 167. Improper use of traits_type::length()
typedef char_traits<char> __ctraits_type;
#endif
typename __ostream_type::sentry __cerb(__out);
if (__cerb)
{
size_t __clen = __ctraits_type::length(__s);
_CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1)));
for (size_t __i = 0; __i <= __clen; ++__i)
__ws[__i] = __out.widen(__s[__i]);
_CharT* __str = __ws;
try
{
streamsize __len = static_cast<streamsize>(__clen);
streamsize __w = __out.width();
_CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
if (__w > __len)
{
__pad_char(__out, __pads, __ws, __w, __len);
__str = __pads;
__len = __w;
}
__out.write(__str, __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_exception_again;
}
}
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;
typename __ostream_type::sentry __cerb(__out);
if (__cerb)
{
try
{
streamsize __w = __out.width();
char* __pads = static_cast<char*>(__builtin_alloca(__w));
streamsize __len = static_cast<streamsize>(_Traits::length(__s));
if (__w > __len)
{
__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_exception_again;
}
}
return __out;
}
 
// 21.3.7.9 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>& __str)
{
typedef basic_ostream<_CharT, _Traits> __ostream_type;
typename __ostream_type::sentry __cerb(__out);
if (__cerb)
{
const _CharT* __s = __str.data();
streamsize __w = __out.width();
_CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
streamsize __len = static_cast<streamsize>(__str.size());
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 25. String operator<< uses width() value wrong
#endif
if (__w > __len)
{
__pad_char(__out, __pads, __s, __w, __len);
__s = __pads;
__len = __w;
}
streamsize __res = __out.rdbuf()->sputn(__s, __len);
__out.width(0);
if (__res != __len)
__out.setstate(ios_base::failbit);
}
return __out;
}
} // namespace std
// Local Variables:
// mode:C++
// End:
 
/contrib/media/updf/include/bits/poll.h
0,0 → 1,50
/* Copyright (C) 1997, 2001, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
 
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
 
The GNU C 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
Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
 
#ifndef _SYS_POLL_H
# error "Never use <bits/poll.h> directly; include <sys/poll.h> instead."
#endif
 
/* Event types that can be polled for. These bits may be set in `events'
to indicate the interesting event types; they will appear in `revents'
to indicate the status of the file descriptor. */
#define POLLIN 0x001 /* There is data to read. */
#define POLLPRI 0x002 /* There is urgent data to read. */
#define POLLOUT 0x004 /* Writing now will not block. */
 
#ifdef __USE_XOPEN
/* These values are defined in XPG4.2. */
# define POLLRDNORM 0x040 /* Normal data may be read. */
# define POLLRDBAND 0x080 /* Priority data may be read. */
# define POLLWRNORM 0x100 /* Writing now will not block. */
# define POLLWRBAND 0x200 /* Priority data may be written. */
#endif
 
#ifdef __USE_GNU
/* These are extensions for Linux. */
# define POLLMSG 0x400
# define POLLREMOVE 0x1000
# define POLLRDHUP 0x2000
#endif
 
/* Event types always implicitly polled for. These bits need not be set in
`events', but they will appear in `revents' to indicate the status of
the file descriptor. */
#define POLLERR 0x008 /* Error condition. */
#define POLLHUP 0x010 /* Hung up. */
#define POLLNVAL 0x020 /* Invalid polling request. */
/contrib/media/updf/include/bits/pthread_allocimpl.h
0,0 → 1,491
/*
* 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/c++config.h>
#include <bits/std_cerrno.h>
#include <bits/stl_alloc.h>
#ifndef __RESTRICT
# define __RESTRICT
#endif
 
#include <new>
 
namespace std
{
 
#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)) {
std::__throw_bad_alloc(); // defined in funcexcept.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) {
std::__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;
 
 
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;
};
 
 
} // namespace std
 
#endif /* _CPP_BITS_PTHREAD_ALLOCIMPL_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/sbuf_iter.h
0,0 → 1,203
// Streambuf iterators
 
// Copyright (C) 1997-2001 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
 
#pragma GCC system_header
 
namespace std
{
template<typename _CharT, typename _Traits>
class ostreambuf_iterator
: public iterator<output_iterator_tag, void, void, void, void>
{
public:
// Types:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_ostream<_CharT, _Traits> ostream_type;
 
private:
streambuf_type* _M_sbuf;
bool _M_failed;
 
public:
inline
ostreambuf_iterator(ostream_type& __s) throw ()
: _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
ostreambuf_iterator(streambuf_type* __s) throw ()
: _M_sbuf(__s), _M_failed(!_M_sbuf) { }
 
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; }
};
 
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;
}
 
 
// 24.5.3 Template class istreambuf_iterator
template<typename _CharT, typename _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;
 
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_sbuf;
int_type _M_c;
 
public:
istreambuf_iterator() throw()
: _M_sbuf(NULL), _M_c(-2) { }
istreambuf_iterator(istream_type& __s) throw()
: _M_sbuf(__s.rdbuf()), _M_c(-2) { }
 
istreambuf_iterator(streambuf_type* __s) throw()
: _M_sbuf(__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 __ret;
if (_M_sbuf && _M_c != static_cast<int_type>(-2))
__ret = _M_c;
else if (_M_sbuf)
__ret = traits_type::to_char_type(_M_sbuf->sgetc());
else
__ret = static_cast<char_type>(traits_type::eof());
return __ret;
}
__istreambufiter_type&
operator++()
{
if (_M_sbuf)
_M_sbuf->sbumpc();
_M_c = -2;
return *this;
}
 
__istreambufiter_type
operator++(int)
{
__istreambufiter_type __old = *this;
if (_M_sbuf)
__old._M_c = _M_sbuf->sbumpc();
_M_c = -2;
return __old;
}
 
bool
equal(const __istreambufiter_type& __b)
{
int_type __eof = traits_type::eof();
bool __thiseof = !_M_sbuf || _M_sbuf->sgetc() == __eof;
bool __beof = !__b._M_sbuf
|| __b._M_sbuf->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_sbuf || _M_sbuf->sgetc() == __eof;
bool __beof = !__b._M_sbuf
|| __b._M_sbuf->sgetc() == __eof;
return (__thiseof && __beof || (!__thiseof && !__beof));
}
#endif
};
 
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); }
} // namespace std
#endif
/contrib/media/updf/include/bits/sequence_concepts.h
0,0 → 1,206
/*
* Copyright (c) 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 _STL_SEQUENCE_CONCEPTS_H
#define _STL_SEQUENCE_CONCEPTS_H 1
 
#pragma GCC system_header
 
#include <bits/container_concepts.h>
 
#ifdef __STL_USE_CONCEPT_CHECKS
 
// This file covers the following concepts:
// _Sequence
// _FrontInsertionSequence
// _BackInsertionSequence
 
struct _ERROR_IN_STL_SEQ {
 
template <class _XX>
static void
__fill_constructor_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
typename _XX::difference_type __n = typename _XX::difference_type();
_XX __x(__n, __t);
__sink_unused_warning(__x);
}
template <class _XX>
static void
__fill_default_constructor_requirement_violation(_XX& __s) {
_STL_ERROR::__default_constructor_requirement_violation(*__s.begin());
typename _XX::difference_type __n = typename _XX::difference_type();
_XX __x(__n);
__sink_unused_warning(__x);
}
template <class _XX>
static void
__range_constructor_requirement_violation(_XX& __s) {
_XX __x(__s.begin(), __s.end());
__sink_unused_warning(__x);
}
template <class _XX>
static void
__insert_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
typename _XX::iterator __p = typename _XX::iterator();
__p = __s.insert(__p, __t);
}
template <class _XX>
static void
__fill_insert_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
typename _XX::iterator __p = typename _XX::iterator();
typename _XX::difference_type __n = typename _XX::difference_type();
__s.insert(__p, __n, __t);
}
template <class _XX>
static void
__range_insert_function_requirement_violation(_XX& __s) {
typename _XX::iterator __p = typename _XX::iterator();
typename _XX::iterator __i = typename _XX::iterator();
typename _XX::iterator __j = typename _XX::iterator();
__s.insert(__p, __i, __j);
}
template <class _XX>
static void
__insert_element_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
std::pair<typename _XX::iterator, bool> __r;
__r = __s.insert(__t);
__sink_unused_warning(__r);
}
template <class _XX>
static void
__unconditional_insert_element_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
typename _XX::iterator __p;
__p = __s.insert(__t);
__sink_unused_warning(__p);
}
template <class _XX>
static void
__erase_function_requirement_violation(_XX& __s) {
typename _XX::iterator __p = typename _XX::iterator();
__p = __s.erase(__p);
}
template <class _XX>
static void
__range_erase_function_requirement_violation(_XX& __s) {
typename _XX::iterator __p = typename _XX::iterator();
typename _XX::iterator __q = typename _XX::iterator();
__p = __s.erase(__p, __q);
}
template <class _XX>
static void
__const_front_function_requirement_violation(const _XX& __s) {
typename _XX::const_reference __t = __s.front();
__sink_unused_warning(__t);
}
template <class _XX>
static void
__front_function_requirement_violation(_XX& __s) {
typename _XX::reference __t = __s.front();
__const_front_function_requirement_violation(__s);
__sink_unused_warning(__t);
}
template <class _XX>
static void
__const_back_function_requirement_violation(const _XX& __s) {
typename _XX::const_reference __t = __s.back();
__sink_unused_warning(__t);
}
template <class _XX>
static void
__back_function_requirement_violation(_XX& __s) {
typename _XX::reference __t = __s.back();
__const_back_function_requirement_violation(__s);
__sink_unused_warning(__t);
}
template <class _XX>
static void
__push_front_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
__s.push_front(__t);
}
template <class _XX>
static void
__pop_front_function_requirement_violation(_XX& __s) {
__s.pop_front();
}
template <class _XX>
static void
__push_back_function_requirement_violation(_XX& __s) {
typename _XX::value_type __t = typename _XX::value_type();
__s.push_back(__t);
}
template <class _XX>
static void
__pop_back_function_requirement_violation(_XX& __s) {
__s.pop_back();
}
 
};
 
/* Sequence Containers */
 
template <class _Sequence>
struct _Sequence_concept_specification {
static void
_Sequence_requirement_violation(_Sequence __s) {
// Refinement of ForwardContainer
_ForwardContainer_concept_specification<_Sequence>::_ForwardContainer_requirement_violation(__s);
// Refinement of DefaultConstructible
_DefaultConstructible_concept_specification<_Sequence>::_DefaultConstructible_requirement_violation(__s);
// Valid Expressions
_ERROR_IN_STL_SEQ::__fill_constructor_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__fill_default_constructor_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__range_constructor_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__insert_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__fill_insert_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__range_insert_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__erase_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__range_erase_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__front_function_requirement_violation(__s);
}
};
 
template <class _FrontInsertionSequence>
struct _FrontInsertionSequence_concept_specification {
static void
_FrontInsertionSequence_requirement_violation(_FrontInsertionSequence __s) {
// Refinement of Sequence
_Sequence_concept_specification<_FrontInsertionSequence>::_Sequence_requirement_violation(__s);
// Valid Expressions
_ERROR_IN_STL_SEQ::__push_front_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__pop_front_function_requirement_violation(__s);
}
};
 
template <class _BackInsertionSequence>
struct _BackInsertionSequence_concept_specification {
static void
_BackInsertionSequence_requirement_violation(_BackInsertionSequence __s) {
// Refinement of Sequence
_Sequence_concept_specification<_BackInsertionSequence>::_Sequence_requirement_violation(__s);
// Valid Expressions
_ERROR_IN_STL_SEQ::__back_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__push_back_function_requirement_violation(__s);
_ERROR_IN_STL_SEQ::__pop_back_function_requirement_violation(__s);
}
};
 
#endif /* if __STL_USE_CONCEPT_CHECKS */
 
 
#endif /* _STL_SEQUENCE_CONCEPTS_H */
/contrib/media/updf/include/bits/slice.h
0,0 → 1,80
// The template and inlines for the -*- C++ -*- slice class.
 
// Copyright (C) 1997-1999, 2001 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 1
 
#pragma GCC system_header
 
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:
/contrib/media/updf/include/bits/slice_array.h
0,0 → 1,164
// The template and inlines for the -*- C++ -*- slice_array class.
 
// Copyright (C) 1997-1999, 2000, 2001 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
 
#pragma GCC system_header
 
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:
/contrib/media/updf/include/bits/sstream.tcc
0,0 → 1,213
// String based streams -*- C++ -*-
 
// Copyright (C) 1997-1999, 2001 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 __ret = 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 (__testpos)
{
if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])
&& !__testeof)
{
--_M_in_cur;
__ret = __c;
}
else if (!__testeof)
{
--_M_in_cur;
*_M_in_cur = traits_type::to_char_type(__c);
__ret = __c;
}
else if (__testeof)
{
--_M_in_cur;
__ret = traits_type::not_eof(__c);
}
}
return __ret;
}
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 __ret = traits_type::eof();
bool __testeof = traits_type::eq_int_type(__c, __ret);
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)
{
__size_type __len = max(_M_buf_size, _M_buf_size_opt);
__len *= 2;
 
if (__testwrite)
__ret = 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_out_cur_move(1);
__ret = __c;
}
}
else
__ret = traits_type::not_eof(__c);
}
return __ret;
}
 
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 __ret = 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;
__ret = pos_type(__newoffi);
}
if (__testout
&& __newoffo + __off >= 0 && __endo - __beg >= __newoffo + __off)
{
_M_out_cur_move(__newoffo + __off - (_M_out_cur - __beg));
__ret = pos_type(__newoffo);
}
}
return __ret;
}
 
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 __ret = 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_out_cur_move((__pos) - (_M_out_cur - __beg));
__ret = pos_type(off_type(__pos));
}
return __ret;
}
 
} // namespace std
 
#endif /* _CPP_BITS_SSTREAM_TCC */
 
/contrib/media/updf/include/bits/std_algorithm.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,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
 
#pragma GCC system_header
 
#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:
/contrib/media/updf/include/bits/std_bitset.h
0,0 → 1,782
/*
* 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 __SGI_STL_BITSET
#define __SGI_STL_BITSET
 
#pragma GCC system_header
 
// A bitset of size N has N % (sizeof(unsigned long) * 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_cstring.h> // for memset
#include <bits/std_string.h>
#include <bits/std_stdexcept.h> // for invalid_argument, out_of_range,
// overflow_error
 
#include <bits/std_ostream.h> // for ostream (operator<<)
#include <bits/std_istream.h> // for istream (operator>>)
 
#define _GLIBCPP_BITSET_BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
#define __BITSET_WORDS(__n) \
((__n) < 1 ? 1 : ((__n) + _GLIBCPP_BITSET_BITS_PER_WORD - 1)/_GLIBCPP_BITSET_BITS_PER_WORD)
 
namespace std
{
 
// 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>
struct _Base_bitset {
typedef unsigned long _WordT;
 
_WordT _M_w[_Nw]; // 0 is the least significant word.
 
_Base_bitset( void ) { _M_do_reset(); }
_Base_bitset(unsigned long __val) {
_M_do_reset();
_M_w[0] = __val;
}
 
static size_t _S_whichword( size_t __pos )
{ return __pos / _GLIBCPP_BITSET_BITS_PER_WORD; }
static size_t _S_whichbyte( size_t __pos )
{ return (__pos % _GLIBCPP_BITSET_BITS_PER_WORD) / CHAR_BIT; }
static size_t _S_whichbit( size_t __pos )
{ return __pos % _GLIBCPP_BITSET_BITS_PER_WORD; }
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>& __x) {
for ( size_t __i = 0; __i < _Nw; __i++ ) {
_M_w[__i] &= __x._M_w[__i];
}
}
 
void _M_do_or(const _Base_bitset<_Nw>& __x) {
for ( size_t __i = 0; __i < _Nw; __i++ ) {
_M_w[__i] |= __x._M_w[__i];
}
}
 
void _M_do_xor(const _Base_bitset<_Nw>& __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() { memset(_M_w, 0, _Nw * sizeof(_WordT)); }
 
bool _M_is_equal(const _Base_bitset<_Nw>& __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 < _Nw; __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>
void _Base_bitset<_Nw>::_M_do_left_shift(size_t __shift)
{
if (__shift != 0) {
const size_t __wshift = __shift / _GLIBCPP_BITSET_BITS_PER_WORD;
const size_t __offset = __shift % _GLIBCPP_BITSET_BITS_PER_WORD;
 
if (__offset == 0)
for (size_t __n = _Nw - 1; __n >= __wshift; --__n)
_M_w[__n] = _M_w[__n - __wshift];
 
else {
const size_t __sub_offset = _GLIBCPP_BITSET_BITS_PER_WORD - __offset;
for (size_t __n = _Nw - 1; __n > __wshift; --__n)
_M_w[__n] = (_M_w[__n - __wshift] << __offset) |
(_M_w[__n - __wshift - 1] >> __sub_offset);
_M_w[__wshift] = _M_w[0] << __offset;
}
 
fill(_M_w + 0, _M_w + __wshift, static_cast<_WordT>(0));
}
}
 
template<size_t _Nw>
void _Base_bitset<_Nw>::_M_do_right_shift(size_t __shift)
{
if (__shift != 0) {
const size_t __wshift = __shift / _GLIBCPP_BITSET_BITS_PER_WORD;
const size_t __offset = __shift % _GLIBCPP_BITSET_BITS_PER_WORD;
const size_t __limit = _Nw - __wshift - 1;
 
if (__offset == 0)
for (size_t __n = 0; __n <= __limit; ++__n)
_M_w[__n] = _M_w[__n + __wshift];
 
else {
const size_t __sub_offset = _GLIBCPP_BITSET_BITS_PER_WORD - __offset;
for (size_t __n = 0; __n < __limit; ++__n)
_M_w[__n] = (_M_w[__n + __wshift] >> __offset) |
(_M_w[__n + __wshift + 1] << __sub_offset);
_M_w[__limit] = _M_w[_Nw-1] >> __offset;
}
 
fill(_M_w + __limit + 1, _M_w + _Nw, static_cast<_WordT>(0));
}
}
 
template<size_t _Nw>
unsigned long _Base_bitset<_Nw>::_M_do_to_ulong() const
{
for (size_t __i = 1; __i < _Nw; ++__i)
if (_M_w[__i])
__STL_THROW(overflow_error("bitset"));
return _M_w[0];
}
 
template<size_t _Nw>
size_t _Base_bitset<_Nw>::_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*_GLIBCPP_BITSET_BITS_PER_WORD + __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>
size_t
_Base_bitset<_Nw>::_M_do_find_next(size_t __prev, size_t __not_found) const
{
// make bound inclusive
++__prev;
 
// check out of bounds
if ( __prev >= _Nw * _GLIBCPP_BITSET_BITS_PER_WORD )
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*_GLIBCPP_BITSET_BITS_PER_WORD + __j*CHAR_BIT +
_First_one<true>::_S_first_one[__this_byte];
 
__thisword >>= CHAR_BIT;
}
}
 
// check subsequent words
__i++;
for ( ; __i < _Nw; __i++ ) {
__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*_GLIBCPP_BITSET_BITS_PER_WORD + __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.
//
 
template<> struct _Base_bitset<1> {
typedef unsigned long _WordT;
_WordT _M_w;
 
_Base_bitset( void ) : _M_w(0) {}
_Base_bitset(unsigned long __val) : _M_w(__val) {}
 
static size_t _S_whichword( size_t __pos )
{ return __pos / _GLIBCPP_BITSET_BITS_PER_WORD; }
static size_t _S_whichbyte( size_t __pos )
{ return (__pos % _GLIBCPP_BITSET_BITS_PER_WORD) / CHAR_BIT; }
static size_t _S_whichbit( size_t __pos )
{ return __pos % _GLIBCPP_BITSET_BITS_PER_WORD; }
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>& __x) { _M_w &= __x._M_w; }
void _M_do_or(const _Base_bitset<1>& __x) { _M_w |= __x._M_w; }
void _M_do_xor(const _Base_bitset<1>& __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>& __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 { return _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;
 
};
 
 
// ------------------------------------------------------------
// Helper class to zero out the unused high-order bits in the highest word.
 
template <size_t _Extrabits> struct _Sanitize {
static void _M_do_sanitize(unsigned long& __val)
{ __val &= ~((~static_cast<unsigned long>(0)) << _Extrabits); }
};
 
template<> struct _Sanitize<0> {
static void _M_do_sanitize(unsigned long) {}
};
 
 
 
// ------------------------------------------------------------
// Class bitset.
// _Nb may be any nonzero number of type size_t.
 
template<size_t _Nb>
class bitset : private _Base_bitset<__BITSET_WORDS(_Nb)>
{
private:
typedef _Base_bitset<__BITSET_WORDS(_Nb)> _Base;
typedef unsigned long _WordT;
 
private:
void _M_do_sanitize() {
_Sanitize<_Nb%_GLIBCPP_BITSET_BITS_PER_WORD>::_M_do_sanitize(this->_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 = _Base::_S_whichbit(__pos);
}
 
~reference() {}
 
// for b[i] = __x;
reference& operator=(bool __x) {
if ( __x )
*_M_wp |= _Base::_S_maskbit(_M_bpos);
else
*_M_wp &= ~_Base::_S_maskbit(_M_bpos);
 
return *this;
}
 
// for b[i] = b[__j];
reference& operator=(const reference& __j) {
if ( (*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)) )
*_M_wp |= _Base::_S_maskbit(_M_bpos);
else
*_M_wp &= ~_Base::_S_maskbit(_M_bpos);
 
return *this;
}
 
// flips the bit
bool operator~() const
{ return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
 
// for __x = b[i];
operator bool() const
{ return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
 
// for b[i].flip();
reference& flip() {
*_M_wp ^= _Base::_S_maskbit(_M_bpos);
return *this;
}
};
 
// 23.3.5.1 constructors:
bitset() {}
bitset(unsigned long __val) : _Base_bitset<__BITSET_WORDS(_Nb)>(__val)
{ _M_do_sanitize(); }
 
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);
}
 
// 23.3.5.2 bitset operations:
bitset<_Nb>& operator&=(const bitset<_Nb>& __rhs) {
this->_M_do_and(__rhs);
return *this;
}
 
bitset<_Nb>& operator|=(const bitset<_Nb>& __rhs) {
this->_M_do_or(__rhs);
return *this;
}
 
bitset<_Nb>& operator^=(const bitset<_Nb>& __rhs) {
this->_M_do_xor(__rhs);
return *this;
}
 
bitset<_Nb>& operator<<=(size_t __pos) {
this->_M_do_left_shift(__pos);
this->_M_do_sanitize();
return *this;
}
 
bitset<_Nb>& operator>>=(size_t __pos) {
this->_M_do_right_shift(__pos);
this->_M_do_sanitize();
return *this;
}
 
//
// Extension:
// Versions of single-bit set, reset, flip, test with no range checking.
//
 
bitset<_Nb>& _Unchecked_set(size_t __pos) {
this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
return *this;
}
 
bitset<_Nb>& _Unchecked_set(size_t __pos, int __val) {
if (__val)
this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
else
this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
 
return *this;
}
 
bitset<_Nb>& _Unchecked_reset(size_t __pos) {
this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
return *this;
}
 
bitset<_Nb>& _Unchecked_flip(size_t __pos) {
this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
return *this;
}
 
bool _Unchecked_test(size_t __pos) const {
return (this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
!= static_cast<_WordT>(0);
}
 
// Set, reset, and flip.
 
bitset<_Nb>& set() {
this->_M_do_set();
this->_M_do_sanitize();
return *this;
}
 
bitset<_Nb>& set(size_t __pos, bool __val = true) {
if (__pos >= _Nb)
__STL_THROW(out_of_range("bitset"));
 
return _Unchecked_set(__pos, __val);
}
 
bitset<_Nb>& reset() {
this->_M_do_reset();
return *this;
}
 
bitset<_Nb>& reset(size_t __pos) {
if (__pos >= _Nb)
__STL_THROW(out_of_range("bitset"));
 
return _Unchecked_reset(__pos);
}
 
bitset<_Nb>& flip() {
this->_M_do_flip();
this->_M_do_sanitize();
return *this;
}
 
bitset<_Nb>& flip(size_t __pos) {
if (__pos >= _Nb)
__STL_THROW(out_of_range("bitset"));
 
return _Unchecked_flip(__pos);
}
 
bitset<_Nb> operator~() const {
return bitset<_Nb>(*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 this->_M_do_to_ulong(); }
 
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;
}
 
// Helper functions for string operations.
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;
 
size_t count() const { return this->_M_do_count(); }
 
size_t size() const { return _Nb; }
 
bool operator==(const bitset<_Nb>& __rhs) const {
return this->_M_is_equal(__rhs);
}
bool operator!=(const bitset<_Nb>& __rhs) const {
return !this->_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 this->_M_is_any(); }
bool none() const { return !this->_M_is_any(); }
 
bitset<_Nb> operator<<(size_t __pos) const
{ return bitset<_Nb>(*this) <<= __pos; }
bitset<_Nb> operator>>(size_t __pos) const
{ return bitset<_Nb>(*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 this->_M_do_find_first(_Nb); }
 
// find the index of the next "on" bit after prev
size_t _Find_next( size_t __prev ) const
{ return this->_M_do_find_next(__prev, _Nb); }
 
};
 
//
// Definitions of non-inline member functions.
//
 
template <size_t _Nb>
template<class _CharT, class _Traits, class _Alloc>
void bitset<_Nb>
::_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>
template <class _CharT, class _Traits, class _Alloc>
void bitset<_Nb>
::_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';
}
 
// ------------------------------------------------------------
 
//
// 23.3.5.3 bitset operations:
//
 
template <size_t _Nb>
inline bitset<_Nb> operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) {
bitset<_Nb> __result(__x);
__result &= __y;
return __result;
}
 
 
template <size_t _Nb>
inline bitset<_Nb> operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) {
bitset<_Nb> __result(__x);
__result |= __y;
return __result;
}
 
template <size_t _Nb>
inline bitset<_Nb> operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) {
bitset<_Nb> __result(__x);
__result ^= __y;
return __result;
}
 
template <class _CharT, class _Traits, size_t _Nb>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x)
{
typedef typename _Traits::char_type char_type;
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 typename _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_type __c2 = _Traits::to_char_type(__c1);
char_type __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>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Nb>& __x)
{
basic_string<_CharT, _Traits> __tmp;
__x._M_copy_to_string(__tmp);
return __os << __tmp;
}
 
} // namespace std
 
#undef __BITSET_WORDS
 
#endif /* __SGI_STL_BITSET */
 
 
// Local Variables:
// mode:C++
// End:
 
/contrib/media/updf/include/bits/std_complex.h
0,0 → 1,1025
// The template and inlines for the -*- C++ -*- complex number classes.
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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.2 Complex Numbers
// 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
 
#pragma GCC system_header
 
#include <bits/c++config.h>
#include <bits/std_cmath.h>
#include <bits/std_sstream.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> _Tp norm(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; }
 
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()) { }
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)
{
const _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)
{
const _Tp __r = _M_real * __z.real() + _M_imag * __z.imag();
const _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() == _Tp(); }
 
template<typename _Tp>
inline bool
operator==(const _Tp& __x, const complex<_Tp>& __y)
{ return __x == __y.real() && _Tp() == __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() != _Tp(); }
 
template<typename _Tp>
inline bool
operator!=(const _Tp& __x, const complex<_Tp>& __y)
{ return __x != __y.real() || _Tp() != __y.imag(); }
 
template<typename _Tp, typename _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
{
_Tp __re_x, __im_x;
_CharT __ch;
__is >> __ch;
if (__ch == '(')
{
__is >> __re_x >> __ch;
if (__ch == ',')
{
__is >> __im_x >> __ch;
if (__ch == ')')
__x = complex<_Tp>(__re_x, __im_x);
else
__is.setstate(ios_base::failbit);
}
else if (__ch == ')')
__x = complex<_Tp>(__re_x, _Tp(0));
else
__is.setstate(ios_base::failbit);
}
else
{
__is.putback(__ch);
__is >> __re_x;
__x = complex<_Tp>(__re_x, _Tp(0));
}
return __is;
}
 
template<typename _Tp, typename _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)
{
basic_ostringstream<_CharT, _Traits> __s;
__s.flags(__os.flags());
__s.imbue(__os.getloc());
__s.precision(__os.precision());
__s << '(' << __x.real() << "," << __x.imag() << ')';
return __os << __s.str();
}
 
// 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(); }
 
template<typename _Tp>
inline _Tp
abs(const complex<_Tp>& __z)
{
_Tp __x = __z.real();
_Tp __y = __z.imag();
const _Tp __s = abs(__x) + abs(__y);
if (__s == _Tp()) // well ...
return __s;
__x /= __s;
__y /= __s;
return __s * sqrt(__x * __x + __y * __y);
}
 
template<typename _Tp>
inline _Tp
arg(const complex<_Tp>& __z)
{ return atan2(__z.imag(), __z.real()); }
 
template<typename _Tp>
inline _Tp
norm(const complex<_Tp>& __z)
{
_Tp __res = abs(__z);
return __res * __res;
}
 
template<typename _Tp>
inline complex<_Tp>
polar(const _Tp& __rho, const _Tp& __theta)
{ return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta)); }
 
template<typename _Tp>
inline complex<_Tp>
conj(const complex<_Tp>& __z)
{ return complex<_Tp>(__z.real(), -__z.imag()); }
// Transcendentals
template<typename _Tp>
inline complex<_Tp>
cos(const complex<_Tp>& __z)
{
const _Tp __x = __z.real();
const _Tp __y = __z.imag();
return complex<_Tp>(cos(__x) * cosh(__y), -sin(__x) * sinh(__y));
}
 
template<typename _Tp>
inline complex<_Tp>
cosh(const complex<_Tp>& __z)
{
const _Tp __x = __z.real();
const _Tp __y = __z.imag();
return complex<_Tp>(cosh(__x) * cos(__y), sinh(__x) * sin(__y));
}
 
template<typename _Tp>
inline complex<_Tp>
exp(const complex<_Tp>& __z)
{ return polar(exp(__z.real()), __z.imag()); }
 
template<typename _Tp>
inline complex<_Tp>
log(const complex<_Tp>& __z)
{ return complex<_Tp>(log(abs(__z)), arg(__z)); }
 
template<typename _Tp>
inline complex<_Tp>
log10(const complex<_Tp>& __z)
{ return log(__z) / log(_Tp(10.0)); }
 
template<typename _Tp>
inline complex<_Tp>
sin(const complex<_Tp>& __z)
{
const _Tp __x = __z.real();
const _Tp __y = __z.imag();
return complex<_Tp>(sin(__x) * cosh(__y), cos(__x) * sinh(__y));
}
 
template<typename _Tp>
inline complex<_Tp>
sinh(const complex<_Tp>& __z)
{
const _Tp __x = __z.real();
const _Tp __y = __z.imag();
return complex<_Tp>(sinh(__x) * cos(__y), cosh(__x) * sin(__y));
}
 
template<typename _Tp>
complex<_Tp>
sqrt(const complex<_Tp>& __z)
{
_Tp __x = __z.real();
_Tp __y = __z.imag();
 
if (__x == _Tp())
{
_Tp __t = sqrt(abs(__y) / 2);
return complex<_Tp>(__t, __y < _Tp() ? -__t : __t);
}
else
{
_Tp __t = sqrt(2 * (abs(__z) + abs(__x)));
_Tp __u = __t / 2;
return __x > _Tp()
? complex<_Tp>(__u, __y / __t)
: complex<_Tp>(abs(__y) / __t, __y < _Tp() ? -__u : __u);
}
}
 
template<typename _Tp>
inline complex<_Tp>
tan(const complex<_Tp>& __z)
{
return sin(__z) / cos(__z);
}
 
template<typename _Tp>
inline complex<_Tp>
tanh(const complex<_Tp>& __z)
{
return sinh(__z) / cosh(__z);
}
 
template<typename _Tp>
inline complex<_Tp>
pow(const complex<_Tp>& __z, int __n)
{
return __pow_helper(__z, __n);
}
 
template<typename _Tp>
inline complex<_Tp>
pow(const complex<_Tp>& __x, const _Tp& __y)
{
return exp(__y * log(__x));
}
 
template<typename _Tp>
inline complex<_Tp>
pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
{
return exp(__y * log(__x));
}
 
template<typename _Tp>
inline complex<_Tp>
pow(const _Tp& __x, const complex<_Tp>& __y)
{
return exp(__y * log(__x));
}
 
// 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>;
};
 
inline float
complex<float>::real() const
{ return __real__ _M_value; }
 
inline float
complex<float>::imag() const
{ return __imag__ _M_value; }
 
inline
complex<float>::complex(float r, float i)
{
__real__ _M_value = r;
__imag__ _M_value = i;
}
 
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.imag();
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;
}
 
// 26.2.3 complex specializations
// 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>;
};
 
inline double
complex<double>::real() const
{ return __real__ _M_value; }
 
inline double
complex<double>::imag() const
{ return __imag__ _M_value; }
 
inline
complex<double>::complex(double __r, double __i)
{
__real__ _M_value = __r;
__imag__ _M_value = __i;
}
 
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;
}
 
// 26.2.3 complex specializations
// 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>;
};
 
inline
complex<long double>::complex(long double __r, long double __i)
{
__real__ _M_value = __r;
__imag__ _M_value = __i;
}
 
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;
}
 
// These bits have to be at the end of this file, so that the
// specializations have all been defined.
// ??? No, they have to be there because of compiler limitation at
// inlining. It suffices that class specializations be defined.
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<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<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)) { }
} // namespace std
 
#endif /* _CPP_COMPLEX */
/contrib/media/updf/include/bits/std_deque.h
0,0 → 1,43
/*
*
* 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
 
#pragma GCC system_header
 
#include <bits/functexcept.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:
/contrib/media/updf/include/bits/std_fstream.h
0,0 → 1,425
// File based streams -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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
 
#pragma GCC system_header
 
#include <bits/std_istream.h>
#include <bits/std_ostream.h>
#include <bits/basic_file.h>
#include <bits/std_locale.h> // For codecvt
#include <bits/gthr.h>
 
namespace std
{
template<typename _CharT, typename _Traits>
class basic_filebuf : public basic_streambuf<_CharT, _Traits>
{
public:
// Types:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
// Non-standard Types:
typedef basic_streambuf<char_type, traits_type> __streambuf_type;
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
typedef __basic_file<char_type> __file_type;
typedef typename traits_type::state_type __state_type;
typedef codecvt<char_type, char, __state_type> __codecvt_type;
typedef typename __codecvt_type::result __res_type;
typedef ctype<char_type> __ctype_type;
 
friend class ios_base; // For sync_with_stdio.
 
private:
// Data Members:
// External buffer.
__file_type* _M_file;
 
// Current and beginning state type for codecvt.
__state_type _M_state_cur;
__state_type _M_state_beg;
 
// MT lock inherited from libio or other low-level io library.
__c_lock _M_lock;
 
// Set iff _M_buf is allocated memory from _M_allocate_internal_buffer..
bool _M_buf_allocated;
 
// XXX Needed?
bool _M_last_overflowed;
public:
// Constructors/destructor:
basic_filebuf();
 
// Non-standard ctor:
basic_filebuf(__c_file_type* __f, ios_base::openmode __mode,
int_type __s = static_cast<int_type>(BUFSIZ));
virtual
~basic_filebuf()
{
this->close();
_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:
void
_M_allocate_internal_buffer();
 
void
_M_destroy_internal_buffer();
 
void
_M_allocate_pback_buffer();
 
// Create __file_type object and initialize it properly.
void
_M_allocate_file();
 
// 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);
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)
streamoff __cur = _M_file->seekoff(0, ios_base::cur);
off_type __off = _M_out_cur - _M_out_beg;
_M_really_overflow();
_M_file->seekpos(__cur + __off);
}
_M_last_overflowed = false;
return 0;
}
virtual void
imbue(const locale& __loc);
 
virtual streamsize
xsgetn(char_type* __s, streamsize __n)
{
streamsize __ret = 0;
// Clear out pback buffer before going on to the real deal...
if (_M_pback_init)
{
while (__ret < __n && _M_in_cur < _M_in_end)
{
*__s = *_M_in_cur;
++__ret;
++__s;
++_M_in_cur;
}
_M_pback_destroy();
}
if (__ret < __n)
__ret += __streambuf_type::xsgetn(__s, __n - __ret);
return __ret;
}
virtual streamsize
xsputn(const char_type* __s, streamsize __n)
{
_M_pback_destroy();
return __streambuf_type::xsputn(__s, __n);
}
void
_M_output_unshift();
};
 
 
// 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 _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
 
// Non-standard types:
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
typedef basic_istream<char_type, traits_type> __istream_type;
private:
__filebuf_type _M_filebuf;
 
public:
// Constructors/Destructors:
basic_ifstream()
: __istream_type(NULL), _M_filebuf()
{ this->init(&_M_filebuf); }
 
explicit
basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
: __istream_type(NULL), _M_filebuf()
{
this->init(&_M_filebuf);
this->open(__s, __mode);
}
~basic_ifstream()
{ }
 
// Members:
__filebuf_type*
rdbuf() const
{ return const_cast<__filebuf_type*>(&_M_filebuf); }
 
bool
is_open(void) { return _M_filebuf.is_open(); }
 
void
open(const char* __s, ios_base::openmode __mode = ios_base::in)
{
if (_M_filebuf.open(__s, __mode | ios_base::in) == NULL)
this->setstate(ios_base::failbit);
}
 
void
close(void)
{
if (!_M_filebuf.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 _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
 
// Non-standard types:
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
typedef basic_ostream<char_type, traits_type> __ostream_type;
private:
__filebuf_type _M_filebuf;
 
public:
// Constructors:
basic_ofstream()
: __ostream_type(NULL), _M_filebuf()
{ this->init(&_M_filebuf); }
explicit
basic_ofstream(const char* __s,
ios_base::openmode __mode = ios_base::out|ios_base::trunc)
: __ostream_type(NULL), _M_filebuf()
{
this->init(&_M_filebuf);
this->open(__s, __mode);
}
 
~basic_ofstream()
{ }
 
// Members:
__filebuf_type*
rdbuf(void) const
{ return const_cast<__filebuf_type*>(&_M_filebuf); }
bool
is_open(void) { return _M_filebuf.is_open(); }
 
void
open(const char* __s,
ios_base::openmode __mode = ios_base::out | ios_base::trunc)
{
if (!_M_filebuf.open(__s, __mode | ios_base::out))
this->setstate(ios_base::failbit);
}
 
void
close(void)
{
if (!_M_filebuf.close())
setstate(ios_base::failbit);
}
};
 
 
// 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 _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
 
// Non-standard types:
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
typedef basic_ios<char_type, traits_type> __ios_type;
typedef basic_iostream<char_type, traits_type> __iostream_type;
 
private:
__filebuf_type _M_filebuf;
public:
// Constructors/destructor:
basic_fstream()
: __iostream_type(NULL), _M_filebuf()
{ this->init(&_M_filebuf); }
 
explicit
basic_fstream(const char* __s,
ios_base::openmode __mode = ios_base::in | ios_base::out)
: __iostream_type(NULL), _M_filebuf()
{
this->init(&_M_filebuf);
this->open(__s, __mode);
}
~basic_fstream()
{ }
// Members:
__filebuf_type*
rdbuf(void) const
{ return const_cast<__filebuf_type*>(&_M_filebuf); }
 
bool
is_open(void) { return _M_filebuf.is_open(); }
 
void
open(const char* __s,
ios_base::openmode __mode = ios_base::in | ios_base::out)
{
if (!_M_filebuf.open(__s, __mode))
setstate(ios_base::failbit);
}
 
void
close(void)
{
if (!_M_filebuf.close())
setstate(ios_base::failbit);
}
};
} // namespace std
 
 
#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
# define export
#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
# include <bits/fstream.tcc>
#endif
#endif
 
#endif
 
/contrib/media/updf/include/bits/std_functional.h
0,0 → 1,28
/*
* 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 1
 
#pragma GCC system_header
#include <bits/c++config.h>
#include <bits/std_cstddef.h>
#include <bits/stl_function.h>
 
#endif /* _CPP_FUNCTIONAL */
 
// Local Variables:
// mode:C++
// End:
 
/contrib/media/updf/include/bits/std_iomanip.h
0,0 → 1,218
// Standard stream manipulators -*- C++ -*-
 
// Copyright (C) 1997-1999, 2001 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
 
#pragma GCC system_header
 
#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 */
 
/contrib/media/updf/include/bits/std_ios.h
0,0 → 1,49
// Iostreams base classes -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2001 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
 
#pragma GCC system_header
 
#include <bits/std_iosfwd.h>
#include <exception> // For ios_base::failure
#include <bits/char_traits.h> // For char_traits, streamoff, streamsize, fpos
#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 */
 
/contrib/media/updf/include/bits/std_iosfwd.h
0,0 → 1,136
// Forwarding declarations -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2001 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
 
#pragma GCC system_header
 
#include <bits/c++config.h>
#include <bits/stringfwd.h> // For string forward declarations.
#include <bits/fpos.h>
#include <bits/functexcept.h>
 
namespace std
{
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
 
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
 
 
 
 
 
/contrib/media/updf/include/bits/std_iostream.h
0,0 → 1,62
// Standard iostream objects -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2001 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
 
#pragma GCC system_header
 
#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
 
 
/contrib/media/updf/include/bits/std_istream.h
0,0 → 1,295
// Input streams -*- C++ -*-
 
// Copyright (C) 1997-1999, 2001 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
 
#pragma GCC system_header
 
#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, _Traits> __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); }
 
// 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 >> reinterpret_cast<char&>(__c)); }
 
template<class _Traits>
basic_istream<char, _Traits>&
operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
{ return (__in >> reinterpret_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 */
 
/contrib/media/updf/include/bits/std_iterator.h
0,0 → 1,43
/*
*
* 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
 
#pragma GCC system_header
#include <bits/c++config.h>
#include <bits/std_cstddef.h>
#include <bits/std_iosfwd.h>
#include <bits/stl_iterator_base_types.h>
#include <bits/stl_iterator_base_funcs.h>
#include <bits/stl_iterator.h>
 
#endif /* _CPP_ITERATOR */
 
// Local Variables:
// mode:C++
// End:
 
/contrib/media/updf/include/bits/std_list.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,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
 
#pragma GCC system_header
 
#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:
/contrib/media/updf/include/bits/std_locale.h
0,0 → 1,47
// 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
 
#pragma GCC system_header
 
#include <bits/localefwd.h>
#include <bits/locale_facets.h>
#include <bits/locale_facets.tcc>
 
#endif
 
// Local Variables:
// mode:c++
// End:
/contrib/media/updf/include/bits/std_map.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,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
 
#pragma GCC system_header
 
#ifndef _CPP_BITS_STL_TREE_H
#include <bits/stl_tree.h>
#endif
#include <bits/stl_map.h>
#include <bits/stl_multimap.h>
 
#endif /* _CPP_MAP */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/std_memory.h
0,0 → 1,116
/*
* 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
 
#pragma GCC system_header
 
#include <bits/stl_algobase.h>
#include <bits/stl_alloc.h>
#include <bits/stl_construct.h>
#include <bits/stl_iterator_base_types.h> //for iterator_traits
#include <bits/stl_tempbuf.h>
#include <bits/stl_uninitialized.h>
#include <bits/stl_raw_storage_iter.h>
 
namespace std
{
 
template<class _Tp1> struct auto_ptr_ref {
_Tp1* _M_ptr;
auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
};
 
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()) {}
 
template <class _Tp1> auto_ptr(auto_ptr<_Tp1>& __a) __STL_NOTHROW
: _M_ptr(__a.release()) {}
 
auto_ptr& operator=(auto_ptr& __a) __STL_NOTHROW {
reset(__a.release());
return *this;
}
 
template <class _Tp1>
auto_ptr& operator=(auto_ptr<_Tp1>& __a) __STL_NOTHROW {
reset(__a.release());
return *this;
}
// Note: The C++ standard says there is supposed to be an empty throw
// specification here, but omitting it is standard conforming. Its
// presence can be detected only if _Tp::~_Tp() throws, but (17.4.3.6/2)
// this is prohibited.
~auto_ptr() { 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.
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()); }
};
 
} // namespace std
 
#endif /* _CPP_MEMORY */
 
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/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
 
#pragma GCC system_header
#include <bits/c++config.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:
/contrib/media/updf/include/bits/std_ostream.h
0,0 → 1,283
// Output streams -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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
 
#pragma GCC system_header
 
#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, _Traits> __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() { }
 
// 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(_CharT()); }
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 */
 
/contrib/media/updf/include/bits/std_queue.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_QUEUE
#define _CPP_QUEUE 1
 
#pragma GCC system_header
#include <bits/c++config.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 <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:
/contrib/media/updf/include/bits/std_set.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,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
 
#pragma GCC system_header
 
#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:
/contrib/media/updf/include/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
 
#pragma GCC system_header
 
#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 _Traits traits_type;
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 251. basic_stringbuf missing allocator_type
typedef _Alloc allocator_type;
#endif
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
 
// Non-standard Types:
typedef basic_streambuf<char_type, traits_type> __streambuf_type;
typedef basic_string<char_type, _Traits, _Alloc> __string_type;
typedef typename __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_stringbuf_init(__mode); }
 
explicit
basic_stringbuf(const __string_type& __str,
ios_base::openmode __mode = ios_base::in | ios_base::out)
: __streambuf_type(), _M_string(__str.c_str())
{ _M_stringbuf_init(__mode); }
 
// Get and set:
__string_type
str() const
{
if (_M_mode & ios_base::out)
{
// 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);
}
else
return _M_string;
}
 
void
str(const __string_type& __s)
{
_M_string = __s;
_M_stringbuf_init(_M_mode);
}
 
protected:
// Common initialization code for both ctors goes here.
void
_M_stringbuf_init(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();
 
// 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.
_M_buf_size_opt = 512;
_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 (__s && __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;
}
};
 
 
// 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 _Traits traits_type;
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 251. basic_stringbuf missing allocator_type
typedef _Alloc allocator_type;
#endif
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
 
// Non-standard types:
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
typedef basic_istream<char_type, traits_type> __istream_type;
 
private:
__stringbuf_type _M_stringbuf;
 
public:
// Constructors:
explicit
basic_istringstream(ios_base::openmode __mode = ios_base::in)
: __istream_type(NULL), _M_stringbuf(__mode | ios_base::in)
{ this->init(&_M_stringbuf); }
 
explicit
basic_istringstream(const __string_type& __str,
ios_base::openmode __mode = ios_base::in)
: __istream_type(NULL), _M_stringbuf(__str, __mode | ios_base::in)
{ this->init(&_M_stringbuf); }
 
~basic_istringstream()
{ }
 
// Members:
__stringbuf_type*
rdbuf() const
{ return const_cast<__stringbuf_type*>(&_M_stringbuf); }
 
__string_type
str() const
{ return _M_stringbuf.str(); }
void
str(const __string_type& __s)
{ _M_stringbuf.str(__s); }
};
 
 
// 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 _Traits traits_type;
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 251. basic_stringbuf missing allocator_type
typedef _Alloc allocator_type;
#endif
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
 
// Non-standard types:
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
typedef basic_ostream<char_type, traits_type> __ostream_type;
 
private:
__stringbuf_type _M_stringbuf;
 
public:
// Constructors/destructor:
explicit
basic_ostringstream(ios_base::openmode __mode = ios_base::out)
: __ostream_type(NULL), _M_stringbuf(__mode | ios_base::out)
{ this->init(&_M_stringbuf); }
 
explicit
basic_ostringstream(const __string_type __str,
ios_base::openmode __mode = ios_base::out)
: __ostream_type(NULL), _M_stringbuf(__str, __mode | ios_base::out)
{ this->init(&_M_stringbuf); }
 
~basic_ostringstream()
{ }
 
// Members:
__stringbuf_type*
rdbuf() const
{ return const_cast<__stringbuf_type*>(&_M_stringbuf); }
 
__string_type
str() const
{ return _M_stringbuf.str(); }
void
str(const __string_type& __s)
{ _M_stringbuf.str(__s); }
};
// 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 _Traits traits_type;
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 251. basic_stringbuf missing allocator_type
typedef _Alloc allocator_type;
#endif
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
 
// Non-standard Types:
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
typedef basic_iostream<char_type, traits_type> __iostream_type;
 
private:
__stringbuf_type _M_stringbuf;
 
public:
// Constructors/destructors
explicit
basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in)
: __iostream_type(NULL), _M_stringbuf(__m)
{ this->init(&_M_stringbuf); }
 
explicit
basic_stringstream(const __string_type& __str,
ios_base::openmode __m = ios_base::out | ios_base::in)
: __iostream_type(NULL), _M_stringbuf(__str, __m)
{ this->init(&_M_stringbuf); }
 
~basic_stringstream()
{ }
 
// Members:
__stringbuf_type*
rdbuf() const
{ return const_cast<__stringbuf_type*>(&_M_stringbuf); }
 
__string_type
str() const
{ return _M_stringbuf.str(); }
 
void
str(const __string_type& __s)
{ _M_stringbuf.str(__s); }
};
} // namespace std
 
 
 
#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
# define export
#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
# include <bits/sstream.tcc>
#endif
#endif
 
#endif // _CPP_SSTREAM
/contrib/media/updf/include/bits/std_stack.h
0,0 → 1,43
/*
*
* 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
 
#pragma GCC system_header
 
#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:
/contrib/media/updf/include/bits/std_stdexcept.h
0,0 → 1,117
// Standard exception classes -*- C++ -*-
 
// Copyright (C) 2001 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++ 19.1 Exception classes
//
 
#ifndef _CPP_STDEXCEPT
#define _CPP_STDEXCEPT 1
 
#pragma GCC system_header
 
#include <exception>
#include <string>
 
namespace std
{
class logic_error : public exception
{
string _M_msg;
 
public:
explicit
logic_error(const string& __arg);
 
virtual
~logic_error() throw();
 
virtual const char*
what() const throw();
};
 
class domain_error : public logic_error
{
public:
explicit domain_error(const string& __arg);
};
 
class invalid_argument : public logic_error
{
public:
explicit invalid_argument(const string& __arg);
};
 
class length_error : public logic_error
{
public:
explicit length_error(const string& __arg);
};
 
class out_of_range : public logic_error
{
public:
explicit out_of_range(const string& __arg);
};
 
class runtime_error : public exception
{
string _M_msg;
 
public:
explicit
runtime_error(const string& __arg);
 
virtual
~runtime_error() throw();
 
virtual const char*
what() const throw();
};
 
class range_error : public runtime_error
{
public:
explicit range_error(const string& __arg);
};
 
class overflow_error : public runtime_error
{
public:
explicit overflow_error(const string& __arg);
};
 
class underflow_error : public runtime_error
{
public:
explicit underflow_error(const string& __arg);
};
} // namespace std
 
#endif // _CPP_STDEXCEPT
/contrib/media/updf/include/bits/std_streambuf.h
0,0 → 1,534
// Stream buffer classes -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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
 
#pragma GCC system_header
 
#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>
streamsize
__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 _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
 
// Non-standard Types:
typedef ctype<char_type> __ctype_type;
typedef basic_streambuf<char_type, traits_type> __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
__copy_streambufs<>(basic_ios<char_type, traits_type>& __ios,
__streambuf_type* __sbin,__streambuf_type* __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;
 
// Actual size of allocated internal buffer, in bytes.
int_type _M_buf_size;
 
// Optimal or preferred size of internal buffer, in bytes.
int_type _M_buf_size_opt;
 
// 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_beg; // Start of get area.
char_type* _M_in_cur; // Current read area.
char_type* _M_in_end; // End of get area.
char_type* _M_out_beg; // Start of put area.
char_type* _M_out_cur; // Current 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_buf_locale;
 
// True iff locale is initialized.
bool _M_buf_locale_init;
 
// Necessary bits for putback buffer management. Only used in
// the basic_filebuf class, as necessary for the standard
// requirements. The only basic_streambuf member function that
// needs access to these data members is in_avail...
// NB: pbacks of over one character are not currently supported.
int_type _M_pback_size;
char_type* _M_pback;
char_type* _M_pback_cur_save;
char_type* _M_pback_end_save;
bool _M_pback_init;
 
// Initializes pback buffers, and moves normal buffers to safety.
// Assumptions:
// _M_in_cur has already been moved back
void
_M_pback_create()
{
if (!_M_pback_init)
{
int_type __dist = _M_in_end - _M_in_cur;
int_type __len = min(_M_pback_size, __dist);
traits_type::copy(_M_pback, _M_in_cur, __len);
_M_pback_cur_save = _M_in_cur;
_M_pback_end_save = _M_in_end;
this->setg(_M_pback, _M_pback, _M_pback + __len);
_M_pback_init = true;
}
}
 
// Deactivates pback buffer contents, and restores normal buffer.
// Assumptions:
// The pback buffer has only moved forward.
void
_M_pback_destroy()
{
if (_M_pback_init)
{
// Length _M_in_cur moved in the pback buffer.
int_type __off_cur = _M_in_cur - _M_pback;
// For in | out buffers, the end can be pushed back...
int_type __off_end = 0;
int_type __pback_len = _M_in_end - _M_pback;
int_type __save_len = _M_pback_end_save - _M_buf;
if (__pback_len > __save_len)
__off_end = __pback_len - __save_len;
 
this->setg(_M_buf, _M_pback_cur_save + __off_cur,
_M_pback_end_save + __off_end);
_M_pback_cur_save = NULL;
_M_pback_end_save = NULL;
_M_pback_init = false;
}
}
 
// Correctly sets the _M_in_cur pointer, and bumps the
// _M_out_cur pointer as well if necessary.
void
_M_in_cur_move(off_type __n) // argument needs to be +-
{
bool __testout = _M_out_cur;
_M_in_cur += __n;
if (__testout && _M_buf_unified)
_M_out_cur += __n;
}
 
// 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_out_cur_move(off_type __n) // argument needs to be +-
{
bool __testin = _M_in_cur;
 
_M_out_cur += __n;
if (__testin && _M_buf_unified)
_M_in_cur += __n;
if (_M_out_cur > _M_out_end)
{
_M_out_end = _M_out_cur;
// NB: in | out buffers drag the _M_in_end pointer along...
if (__testin)
_M_in_end += __n;
}
}
 
// Return the size of the output buffer. This depends on the
// buffer in use: allocated buffers have a stored size in
// _M_buf_size and setbuf() buffers don't.
off_type
_M_out_buf_size()
{
off_type __ret = 0;
if (_M_out_cur)
{
// Using allocated buffer.
if (_M_out_beg == _M_buf)
__ret = _M_out_beg + _M_buf_size - _M_out_cur;
// Using non-allocated buffer.
else
__ret = _M_out_end - _M_out_cur;
}
return __ret;
}
 
// These three functions are used to clarify internal buffer
// maintenance. 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)
this->setp(_M_buf, _M_buf + __off);
}
 
bool
_M_is_indeterminate(void)
{
bool __ret = false;
// Don't return true if unbuffered.
if (_M_buf)
{
if (_M_mode & ios_base::in)
__ret = _M_in_beg == _M_in_cur && _M_in_cur == _M_in_end;
if (_M_mode & ios_base::out)
__ret = _M_out_beg == _M_out_cur && _M_out_cur == _M_out_end;
}
return __ret;
}
 
public:
virtual
~basic_streambuf()
{
_M_buf_unified = false;
_M_buf_size = 0;
_M_buf_size_opt = 0;
_M_mode = ios_base::openmode(0);
_M_buf_locale_init = false;
}
 
// Locales:
locale
pubimbue(const locale &__loc)
{
locale __tmp(this->getloc());
this->imbue(__loc);
return __tmp;
}
 
locale
getloc() const
{
if (_M_buf_locale_init)
return _M_buf_locale;
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 __ret;
if (_M_in_cur && _M_in_cur < _M_in_end)
{
if (_M_pback_init)
{
int_type __save_len = _M_pback_end_save - _M_pback_cur_save;
int_type __pback_len = _M_in_cur - _M_pback;
__ret = __save_len - __pback_len;
}
else
__ret = this->egptr() - this->gptr();
}
else
__ret = this->showmanyc();
return __ret;
}
 
int_type
snextc()
{
int_type __eof = traits_type::eof();
return (this->sbumpc() == __eof ? __eof : this->sgetc());
}
 
int_type
sbumpc();
 
int_type
sgetc()
{
int_type __ret;
if (_M_in_cur && _M_in_cur < _M_in_end)
__ret = traits_type::to_int_type(*(this->gptr()));
else
__ret = this->underflow();
return __ret;
}
 
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_size_opt(static_cast<int_type>(BUFSIZ)), _M_buf_unified(false),
_M_in_beg(0), _M_in_cur(0), _M_in_end(0), _M_out_beg(0), _M_out_cur(0),
_M_out_end(0), _M_mode(ios_base::openmode(0)), _M_buf_locale(locale()),
_M_buf_locale_init(false), _M_pback_size(1), _M_pback(NULL),
_M_pback_cur_save(NULL), _M_pback_end_save(NULL), _M_pback_init(false)
{ }
 
// 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;
}
 
// Virtual functions:
// Locales:
virtual void
imbue(const locale& __loc)
{
_M_buf_locale_init = true;
if (_M_buf_locale != __loc)
_M_buf_locale = __loc;
}
 
// 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 __ret = traits_type::eof();
bool __testeof = this->underflow() == __ret;
bool __testpending = _M_in_cur && _M_in_cur < _M_in_end;
if (!__testeof && __testpending)
{
__ret = traits_type::to_int_type(*_M_in_cur);
++_M_in_cur;
if (_M_buf_unified && _M_mode & ios_base::out)
++_M_out_cur;
}
return __ret;
}
 
// 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_DEPRECATED
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
};
 
} // namespace std
 
#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
# define export
#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
#include <bits/streambuf.tcc>
#endif
#endif
 
#endif /* _CPP_STREAMBUF */
 
/contrib/media/updf/include/bits/std_string.h
0,0 → 1,54
// Components for manipulating sequences of characters -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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
 
#pragma GCC system_header
 
#include <bits/c++config.h>
#include <bits/stringfwd.h>
#include <bits/char_traits.h>
#include <bits/std_iterator.h>
#include <bits/std_memory.h> // For allocator.
#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/basic_string.tcc>
#endif
 
#endif /* _CPP_STRING */
 
/contrib/media/updf/include/bits/std_utility.h
0,0 → 1,39
/*
*
* 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
 
#pragma GCC system_header
#include <bits/c++config.h>
#include <bits/stl_relops.h>
#include <bits/stl_pair.h>
 
#endif /* _CPP_UTILITY */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/std_valarray.h
0,0 → 1,737
// The template and inlines for the -*- C++ -*- valarray class.
 
// Copyright (C) 1997-1999, 2000, 2001 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
 
#pragma GCC system_header
 
#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
 
} // namespace std
 
#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:
// XXX: LWG to be resolved.
const _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 const _Tp&
valarray<_Tp>::operator[] (size_t __i) const
{ return _M_data[__i]; }
 
template<typename _Tp>
inline _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(__valarray_get_storage<_Tp>(__n))
{ __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(__valarray_get_storage<_Tp>(__n))
{ __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(__valarray_get_storage<_Tp>(__n))
{ __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(__valarray_get_storage<_Tp>(__v._M_size))
{ __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(__valarray_get_storage<_Tp>(__sa._M_sz))
{
__valarray_copy
(__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(__valarray_get_storage<_Tp>(_M_size))
{
__valarray_copy
(__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(__valarray_get_storage<_Tp>(__ma._M_sz))
{
__valarray_copy
(__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(__valarray_get_storage<_Tp>(__ia._M_sz))
{
__valarray_copy
(__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(__valarray_get_storage<_Tp>(_M_size))
{ __valarray_copy (__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 == 0) // no shift
__valarray_copy_construct(_M_data, _M_data + _M_size, __a);
else if (__n > 0) // __n > 0: shift left
{
if (size_t(__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 == 0) // no cshift
__valarray_copy_construct(_M_data, _M_data + _M_size, __a);
else if (__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 // 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)
{
// This complication is so to make valarray<valarray<T> > work
// even though it is not required by the standard. Nobody should
// be saying valarray<valarray<T> > anyway. See the specs.
__valarray_destroy_elements(_M_data, _M_data + _M_size);
if (_M_size != __n)
{
__valarray_release_memory(_M_data);
_M_size = __n;
_M_data = __valarray_get_storage<_Tp>(__n);
}
__valarray_fill_construct(_M_data, _M_data + __n, __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_LOGICAL_OPERATOR
 
} // namespace std
 
#endif // _CPP_VALARRAY
 
// Local Variables:
// mode:c++
// End:
/contrib/media/updf/include/bits/std_vector.h
0,0 → 1,44
/*
*
* 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
 
#pragma GCC system_header
 
#include <bits/functexcept.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 <bits/stl_bvector.h>
 
#endif /* _CPP_VECTOR */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stdio.h
0,0 → 1,16
#ifndef __BITS_STDIO_H
#define __BITS_STDIO_H
 
struct file_stream_ops {
int (* s_putc)(struct __FILE *,int);
int (* s_getc)(struct __FILE *,int *);
int (* s_read)(struct __FILE *,void *,int);
int (* s_write)(struct __FILE *,void *,int);
int (* s_seek)(struct __FILE *,int,int);
int (* s_flush)(struct __FILE *);
};
 
#define STM_OP(x,n) \
(x)->std_ops->s_##n
 
#endif
/contrib/media/updf/include/bits/stl_algo.h
0,0 → 1,3643
/*
*
* 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>
 
// See concept_check.h for the __glibcpp_*_requires macros.
 
namespace std
{
 
// __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)
{
// concept requirements
__glibcpp_function_requires(_LessThanComparableConcept<_Tp>);
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)
{
// concept requirements
__glibcpp_function_requires(_BinaryFunctionConcept<_Compare, bool, _Tp, _Tp>);
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
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;
}
 
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;
}
}
 
template <class _InputIter, class _Tp>
inline _InputIter find(_InputIter __first, _InputIter __last,
const _Tp& __val)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_EqualOpConcept<
typename iterator_traits<_InputIter>::value_type, _Tp>);
return find(__first, __last, __val, __iterator_category(__first));
}
 
template <class _InputIter, class _Predicate>
inline _InputIter find_if(_InputIter __first, _InputIter __last,
_Predicate __pred)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_UnaryPredicateConcept<_Predicate,
typename iterator_traits<_InputIter>::value_type>);
return find_if(__first, __last, __pred, __iterator_category(__first));
}
 
// adjacent_find.
 
template <class _ForwardIter>
_ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_EqualityComparableConcept<
typename iterator_traits<_ForwardIter>::value_type>);
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type>);
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_EqualityComparableConcept<
typename iterator_traits<_InputIter>::value_type >);
__glibcpp_function_requires(_EqualityComparableConcept<_Tp>);
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_UnaryPredicateConcept<_Predicate,
typename iterator_traits<_InputIter>::value_type>);
for ( ; __first != __last; ++__first)
if (__pred(*__first))
++__n;
}
 
template <class _InputIter, class _Tp>
typename iterator_traits<_InputIter>::difference_type
count(_InputIter __first, _InputIter __last, const _Tp& __value)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_EqualityComparableConcept<
typename iterator_traits<_InputIter>::value_type >);
__glibcpp_function_requires(_EqualityComparableConcept<_Tp>);
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_UnaryPredicateConcept<_Predicate,
typename iterator_traits<_InputIter>::value_type>);
typename iterator_traits<_InputIter>::difference_type __n = 0;
for ( ; __first != __last; ++__first)
if (__pred(*__first))
++__n;
return __n;
}
 
 
// search.
 
template <class _ForwardIter1, class _ForwardIter2>
_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter1>);
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter2>);
__glibcpp_function_requires(_EqualOpConcept<
typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type>);
 
// 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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter1>);
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter2>);
__glibcpp_function_requires(_BinaryPredicateConcept<_BinaryPred,
typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type>);
 
// 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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_EqualityComparableConcept<
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_EqualityComparableConcept<_Tp>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_BinaryPred,
typename iterator_traits<_ForwardIter>::value_type, _Tp>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter1>);
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter2>);
__glibcpp_function_requires(_ConvertibleConcept<
typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type>);
__glibcpp_function_requires(_ConvertibleConcept<
typename iterator_traits<_ForwardIter2>::value_type,
typename iterator_traits<_ForwardIter1>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
/* XXX
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
// should be "the type returned by _UnaryOperation"
typename iterator_traits<_InputIter>::value_type>);
*/
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
/* XXX
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
// should be "the type returned by _BinaryOperation"
typename iterator_traits<_InputIter1>::value_type>);
*/
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_EqualOpConcept<
typename iterator_traits<_ForwardIter>::value_type, _Tp>);
__glibcpp_function_requires(_ConvertibleConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_ConvertibleConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_UnaryPredicateConcept<_Predicate,
typename iterator_traits<_ForwardIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter>::value_type>);
__glibcpp_function_requires(_EqualOpConcept<
typename iterator_traits<_InputIter>::value_type, _Tp>);
 
for ( ; __first != __last; ++__first, ++__result)
*__result = *__first == __old_value ? __new_value : *__first;
return __result;
}
 
template <class _InputIter, class _OutputIter, class _Predicate, class _Tp>
_OutputIter replace_copy_if(_InputIter __first, _InputIter __last,
_OutputIter __result,
_Predicate __pred, const _Tp& __new_value)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter>::value_type>);
__glibcpp_function_requires(_UnaryPredicateConcept<_Predicate,
typename iterator_traits<_InputIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_GeneratorConcept<_Generator,
typename iterator_traits<_ForwardIter>::value_type>);
 
for ( ; __first != __last; ++__first)
*__first = __gen();
}
 
template <class _OutputIter, class _Size, class _Generator>
_OutputIter generate_n(_OutputIter __first, _Size __n, _Generator __gen)
{
/*
// XXX concept requirements
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
"the return type of _Generator" ?? >);
*/
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter>::value_type>);
__glibcpp_function_requires(_EqualOpConcept<
typename iterator_traits<_InputIter>::value_type, _Tp>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter>::value_type>);
__glibcpp_function_requires(_UnaryPredicateConcept<_Predicate,
typename iterator_traits<_InputIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_ConvertibleConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_EqualOpConcept<
typename iterator_traits<_ForwardIter>::value_type, _Tp>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_UnaryPredicateConcept<_Predicate,
typename iterator_traits<_ForwardIter>::value_type>);
 
__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*)
{
// concept requirements -- taken care of in dispatching function
_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)
{
// concept requirements -- taken care of in dispatching function
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)
{
// concept requirements -- taken care of in dispatching function
*__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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter>::value_type>);
__glibcpp_function_requires(_EqualityComparableConcept<
typename iterator_traits<_InputIter>::value_type>);
 
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*)
{
// concept requirements -- iterators already checked
__glibcpp_function_requires(_BinaryPredicateConcept<_BinaryPredicate, _Tp, _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)
{
// concept requirements -- taken care of in dispatching function
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)
{
// concept requirements -- iterators already checked
__glibcpp_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_InputIter>::value_type>);
 
*__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)
{
// concept requirements -- predicates checked later
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_EqualityComparableConcept<
typename iterator_traits<_ForwardIter>::value_type>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_BidirectionalIteratorConcept<
_BidirectionalIter>);
__reverse(__first, __last, __iterator_category(__first));
}
 
template <class _BidirectionalIter, class _OutputIter>
_OutputIter reverse_copy(_BidirectionalIter __first,
_BidirectionalIter __last,
_OutputIter __result)
{
// concept requirements
__glibcpp_function_requires(_BidirectionalIteratorConcept<_BidirectionalIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_BidirectionalIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_BidirectionalIteratorConcept<
_BidirectionalIter>);
 
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 *)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
 
_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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_ForwardIter>::value_type>);
 
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 _GLIBCPP_HAVE_DRAND48
return lrand48() % __n;
#else
return rand() % __n;
#endif
}
 
// random_shuffle
 
template <class _RandomAccessIter>
inline void random_shuffle(_RandomAccessIter __first,
_RandomAccessIter __last)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_ForwardIter>::value_type>);
 
_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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_UnaryFunctionConcept<
_RandomNumberGenerator, _Distance, _Distance>);
 
_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)
{
// concept requirements
__glibcpp_function_requires(_UnaryFunctionConcept<
_RandomNumberGenerator, _Distance, _Distance>);
 
_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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_UnaryPredicateConcept<_Predicate,
typename iterator_traits<_ForwardIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_UnaryPredicateConcept<_Predicate,
typename iterator_traits<_ForwardIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_RandomAccessIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_RandomAccessIter>::value_type>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_RandomAccessIter>::value_type>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_ConvertibleConcept<
typename iterator_traits<_InputIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_RandomAccessIter>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
__glibcpp_function_requires(_ConvertibleConcept<
typename iterator_traits<_InputIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_RandomAccessIter>::value_type>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_SameTypeConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<_Tp>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_SameTypeConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare, _Tp, _Tp>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_SameTypeConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<_Tp>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_SameTypeConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare, _Tp, _Tp>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_SameTypeConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<_Tp>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_SameTypeConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare, _Tp, _Tp>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_SameTypeConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<_Tp>);
 
_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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_SameTypeConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare, _Tp, _Tp>);
 
_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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIter1>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_BidirectionalIteratorConcept<
_BidirectionalIter>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_BidirectionalIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_BidirectionalIteratorConcept<
_BidirectionalIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_BidirectionalIter>::value_type,
typename iterator_traits<_BidirectionalIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIter1>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIter1>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIter1>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIter1>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIter1>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_ForwardIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_ForwardIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_BidirectionalIteratorConcept<_BidirectionalIter>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_BidirectionalIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_BidirectionalIteratorConcept<_BidirectionalIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_BidirectionalIter>::value_type,
typename iterator_traits<_BidirectionalIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_BidirectionalIteratorConcept<_BidirectionalIter>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_BidirectionalIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_BidirectionalIteratorConcept<_BidirectionalIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_BidirectionalIter>::value_type,
typename iterator_traits<_BidirectionalIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_EqualOpConcept<
typename iterator_traits<_InputIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_EqualOpConcept<
typename iterator_traits<_InputIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type>);
__glibcpp_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
typename iterator_traits<_InputIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type>);
 
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.
template <class _BidirectionalIter1, class _BidirectionalIter2>
_BidirectionalIter1
__find_end(_BidirectionalIter1 __first1, _BidirectionalIter1 __last1,
_BidirectionalIter2 __first2, _BidirectionalIter2 __last2,
bidirectional_iterator_tag, bidirectional_iterator_tag)
{
// concept requirements
__glibcpp_function_requires(_BidirectionalIteratorConcept<_BidirectionalIter1>);
__glibcpp_function_requires(_BidirectionalIteratorConcept<_BidirectionalIter2>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_BidirectionalIteratorConcept<_BidirectionalIter1>);
__glibcpp_function_requires(_BidirectionalIteratorConcept<_BidirectionalIter2>);
 
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;
}
}
 
// Dispatching functions for find_end.
 
template <class _ForwardIter1, class _ForwardIter2>
inline _ForwardIter1
find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter1>);
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter2>);
__glibcpp_function_requires(_EqualOpConcept<
typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter1>);
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter2>);
__glibcpp_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_RandomAccessIteratorConcept<_RandomAccessIter>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_RandomAccessIter>::value_type>);
 
return __is_heap(__first, __last - __first);
}
 
 
template <class _RandomAccessIter, class _StrictWeakOrdering>
inline bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last,
_StrictWeakOrdering __comp)
{
// concept requirements
__glibcpp_function_requires(_RandomAccessIteratorConcept<_RandomAccessIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_StrictWeakOrdering,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_ForwardIter>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_BinaryPredicateConcept<_StrictWeakOrdering,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type>);
 
if (__first == __last)
return true;
 
_ForwardIter __next = __first;
for (++__next; __next != __last; __first = __next, ++__next) {
if (__comp(*__next, *__first))
return false;
}
 
return true;
}
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_ALGO_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_algobase.h
0,0 → 1,706
/*
*
* 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/c++config.h>
#ifndef __SGI_STL_INTERNAL_PAIR_H
#include <bits/stl_pair.h>
#endif
#ifndef _CPP_BITS_TYPE_TRAITS_H
#include <bits/type_traits.h>
#endif
#include <bits/std_cstring.h>
#include <bits/std_climits.h>
#include <bits/std_cstdlib.h>
#include <bits/std_cstddef.h>
#include <new>
 
#include <bits/std_iosfwd.h>
#include <bits/stl_iterator_base_types.h>
#include <bits/stl_iterator_base_funcs.h>
#include <bits/stl_iterator.h>
#include <bits/concept_check.h>
 
namespace std
{
 
// 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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter1>);
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter2>);
__glibcpp_function_requires(_ConvertibleConcept<
typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type>);
__glibcpp_function_requires(_ConvertibleConcept<
typename iterator_traits<_ForwardIter2>::value_type,
typename iterator_traits<_ForwardIter1>::value_type>);
 
__iter_swap(__a, __b, __value_type(__a));
}
 
template <class _Tp>
inline void swap(_Tp& __a, _Tp& __b)
{
// concept requirements
__glibcpp_function_requires(_SGIAssignableConcept<_Tp>);
 
_Tp __tmp = __a;
__a = __b;
__b = __tmp;
}
 
//--------------------------------------------------
// min and max
 
#undef min
#undef max
 
template <class _Tp>
inline const _Tp& min(const _Tp& __a, const _Tp& __b) {
// concept requirements
__glibcpp_function_requires(_LessThanComparableConcept<_Tp>);
//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) {
// concept requirements
__glibcpp_function_requires(_LessThanComparableConcept<_Tp>);
//return __a < __b ? __b : __a;
if (__a < __b) return __b; return __a;
}
 
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);
}
 
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter>::value_type>);
 
typedef typename _Is_normal_iterator<_InputIter>::_Normal __Normal;
return __copy_ni1(__first, __last, __result, __Normal());
}
 
//--------------------------------------------------
// 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;
}
 
 
// 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)
{
// concept requirements
__glibcpp_function_requires(_BidirectionalIteratorConcept<_BI1>);
__glibcpp_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>);
__glibcpp_function_requires(_ConvertibleConcept<
typename iterator_traits<_BI1>::value_type,
typename iterator_traits<_BI2>::value_type>);
 
typedef typename _Is_normal_iterator<_BI1>::_Normal __Normal;
return __copy_backward_input_normal_iterator(__first, __last, __result,
__Normal());
}
 
//--------------------------------------------------
// 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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,
typename iterator_traits<_InputIter>::value_type>);
 
return __copy_n(__first, __count, __result);
}
 
//--------------------------------------------------
// fill and fill_n
 
 
template <class _ForwardIter, class _Tp>
void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __value)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>);
 
for ( ; __first != __last; ++__first)
*__first = __value;
}
 
template <class _OutputIter, class _Size, class _Tp>
_OutputIter fill_n(_OutputIter __first, _Size __n, const _Tp& __value)
{
// concept requirements
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIter,_Tp>);
 
for ( ; __n > 0; --__n, ++__first)
*__first = __value;
return __first;
}
 
// Specialization: for one-byte types we can use memset.
 
inline void fill(unsigned char* __first, unsigned char* __last,
const unsigned char& __c)
{
unsigned char __tmp = __c;
memset(__first, __tmp, __last - __first);
}
 
inline void fill(signed char* __first, signed char* __last,
const signed char& __c)
{
signed char __tmp = __c;
memset(__first, static_cast<unsigned char>(__tmp), __last - __first);
}
 
inline void fill(char* __first, char* __last, const char& __c)
{
char __tmp = __c;
memset(__first, static_cast<unsigned char>(__tmp), __last - __first);
}
 
template <class _Size>
inline unsigned char* fill_n(unsigned char* __first, _Size __n,
const unsigned char& __c)
{
fill(__first, __first + __n, __c);
return __first + __n;
}
 
template <class _Size>
inline signed char* fill_n(char* __first, _Size __n,
const signed char& __c)
{
fill(__first, __first + __n, __c);
return __first + __n;
}
 
template <class _Size>
inline char* fill_n(char* __first, _Size __n, const char& __c)
{
fill(__first, __first + __n, __c);
return __first + __n;
}
 
 
//--------------------------------------------------
// equal and mismatch
 
template <class _InputIter1, class _InputIter2>
pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
_InputIter1 __last1,
_InputIter2 __first2)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_EqualityComparableConcept<
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_EqualityComparableConcept<
typename iterator_traits<_InputIter2>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_EqualOpConcept<
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIter2>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIter2>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIter1>::value_type>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIter2>::value_type>);
 
return __lexicographical_compare_3way(__first1, __last1, __first2, __last2);
}
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_ALGOBASE_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_alloc.h
0,0 → 1,822
/*
* 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
 
// 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.
 
#include <bits/functexcept.h> // for __throw_bad_alloc
#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
 
namespace std
{
 
// Malloc-based allocator. Typically slower than default alloc below.
// Typically thread-safe and more storage efficient.
template <int __inst>
class __malloc_alloc_template {
 
private:
 
static void* _S_oom_malloc(size_t);
static void* _S_oom_realloc(void*, size_t);
static void (* __malloc_alloc_oom_handler)();
 
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
 
template <int __inst>
void (* __malloc_alloc_template<__inst>::__malloc_alloc_oom_handler)() = 0;
 
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) { std::__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) { std::__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.
 
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.
enum {_ALIGN = 8};
enum {_MAX_BYTES = 128};
enum {_NFREELISTS = 16}; // _MAX_BYTES/_ALIGN
static size_t
_S_round_up(size_t __bytes)
{ return (((__bytes) + (size_t) _ALIGN-1) & ~((size_t) _ALIGN - 1)); }
 
union _Obj {
union _Obj* _M_free_list_link;
char _M_client_data[1]; /* The client sees this. */
};
 
static _Obj* __STL_VOLATILE _S_free_list[];
// Specifying a size results in duplicate def for 4.1
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;
 
template <bool __threads, int __inst>
inline bool operator==(const __default_alloc_template<__threads, __inst>&,
const __default_alloc_template<__threads, __inst>&)
{
return true;
}
 
template <bool __threads, int __inst>
inline bool operator!=(const __default_alloc_template<__threads, __inst>&,
const __default_alloc_template<__threads, __inst>&)
{
return false;
}
 
 
 
/* 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>
typename __default_alloc_template<__threads, __inst>::_Obj* __STL_VOLATILE
__default_alloc_template<__threads, __inst> ::_S_free_list[
__default_alloc_template<__threads, __inst>::_NFREELISTS
] = {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.
 
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;
}
 
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;
}
 
// 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;
}
 
template <int __inst>
inline bool operator!=(const __malloc_alloc_template<__inst>&,
const __malloc_alloc_template<__inst>&)
{
return false;
}
 
template <class _Alloc>
inline bool operator==(const debug_alloc<_Alloc>&,
const debug_alloc<_Alloc>&) {
return true;
}
 
template <class _Alloc>
inline bool operator!=(const debug_alloc<_Alloc>&,
const debug_alloc<_Alloc>&) {
return false;
}
 
// 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::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;
};
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_ALLOC_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_bvector.h
0,0 → 1,698
/*
*
* 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-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.
*/
 
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
 
#ifndef __SGI_STL_INTERNAL_BVECTOR_H
#define __SGI_STL_INTERNAL_BVECTOR_H
 
namespace std
{
 
static const int __WORD_BIT = int(CHAR_BIT*sizeof(unsigned int));
 
struct _Bit_reference {
unsigned int* _M_p;
unsigned int _M_mask;
_Bit_reference(unsigned int* __x, unsigned int __y)
: _M_p(__x), _M_mask(__y) {}
 
public:
_Bit_reference() : _M_p(0), _M_mask(0) {}
operator bool() const { return !(!(*_M_p & _M_mask)); }
_Bit_reference& operator=(bool __x)
{
if (__x) *_M_p |= _M_mask;
else *_M_p &= ~_M_mask;
return *this;
}
_Bit_reference& operator=(const _Bit_reference& __x)
{ return *this = bool(__x); }
bool operator==(const _Bit_reference& __x) const
{ return bool(*this) == bool(__x); }
bool operator<(const _Bit_reference& __x) const {
return !bool(*this) && bool(__x);
}
void flip() { *_M_p ^= _M_mask; }
};
 
inline void swap(_Bit_reference __x, _Bit_reference __y)
{
bool __tmp = __x;
__x = __y;
__y = __tmp;
}
 
struct _Bit_iterator_base : public random_access_iterator<bool, ptrdiff_t>
{
unsigned int* _M_p;
unsigned int _M_offset;
 
_Bit_iterator_base(unsigned int* __x, unsigned int __y)
: _M_p(__x), _M_offset(__y) {}
 
void _M_bump_up() {
if (_M_offset++ == __WORD_BIT - 1) {
_M_offset = 0;
++_M_p;
}
}
void _M_bump_down() {
if (_M_offset-- == 0) {
_M_offset = __WORD_BIT - 1;
--_M_p;
}
}
 
void _M_incr(ptrdiff_t __i) {
difference_type __n = __i + _M_offset;
_M_p += __n / __WORD_BIT;
__n = __n % __WORD_BIT;
if (__n < 0) {
_M_offset = (unsigned int) __n + __WORD_BIT;
--_M_p;
} else
_M_offset = (unsigned int) __n;
}
 
bool operator==(const _Bit_iterator_base& __i) const {
return _M_p == __i._M_p && _M_offset == __i._M_offset;
}
bool operator<(const _Bit_iterator_base& __i) const {
return _M_p < __i._M_p || (_M_p == __i._M_p && _M_offset < __i._M_offset);
}
bool operator!=(const _Bit_iterator_base& __i) const {
return !(*this == __i);
}
bool operator>(const _Bit_iterator_base& __i) const {
return __i < *this;
}
bool operator<=(const _Bit_iterator_base& __i) const {
return !(__i < *this);
}
bool operator>=(const _Bit_iterator_base& __i) const {
return !(*this < __i);
}
};
 
inline ptrdiff_t
operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
return __WORD_BIT * (__x._M_p - __y._M_p) + __x._M_offset - __y._M_offset;
}
 
 
struct _Bit_iterator : public _Bit_iterator_base
{
typedef _Bit_reference reference;
typedef _Bit_reference* pointer;
typedef _Bit_iterator iterator;
 
_Bit_iterator() : _Bit_iterator_base(0, 0) {}
_Bit_iterator(unsigned int* __x, unsigned int __y)
: _Bit_iterator_base(__x, __y) {}
 
reference operator*() const { return reference(_M_p, 1U << _M_offset); }
iterator& operator++() {
_M_bump_up();
return *this;
}
iterator operator++(int) {
iterator __tmp = *this;
_M_bump_up();
return __tmp;
}
iterator& operator--() {
_M_bump_down();
return *this;
}
iterator operator--(int) {
iterator __tmp = *this;
_M_bump_down();
return __tmp;
}
iterator& operator+=(difference_type __i) {
_M_incr(__i);
return *this;
}
iterator& operator-=(difference_type __i) {
*this += -__i;
return *this;
}
iterator operator+(difference_type __i) const {
iterator __tmp = *this;
return __tmp += __i;
}
iterator operator-(difference_type __i) const {
iterator __tmp = *this;
return __tmp -= __i;
}
 
reference operator[](difference_type __i) { return *(*this + __i); }
};
 
inline _Bit_iterator
operator+(ptrdiff_t __n, const _Bit_iterator& __x) { return __x + __n; }
 
 
struct _Bit_const_iterator : public _Bit_iterator_base
{
typedef bool reference;
typedef bool const_reference;
typedef const bool* pointer;
typedef _Bit_const_iterator const_iterator;
 
_Bit_const_iterator() : _Bit_iterator_base(0, 0) {}
_Bit_const_iterator(unsigned int* __x, unsigned int __y)
: _Bit_iterator_base(__x, __y) {}
_Bit_const_iterator(const _Bit_iterator& __x)
: _Bit_iterator_base(__x._M_p, __x._M_offset) {}
 
const_reference operator*() const {
return _Bit_reference(_M_p, 1U << _M_offset);
}
const_iterator& operator++() {
_M_bump_up();
return *this;
}
const_iterator operator++(int) {
const_iterator __tmp = *this;
_M_bump_up();
return __tmp;
}
const_iterator& operator--() {
_M_bump_down();
return *this;
}
const_iterator operator--(int) {
const_iterator __tmp = *this;
_M_bump_down();
return __tmp;
}
const_iterator& operator+=(difference_type __i) {
_M_incr(__i);
return *this;
}
const_iterator& operator-=(difference_type __i) {
*this += -__i;
return *this;
}
const_iterator operator+(difference_type __i) const {
const_iterator __tmp = *this;
return __tmp += __i;
}
const_iterator operator-(difference_type __i) const {
const_iterator __tmp = *this;
return __tmp -= __i;
}
const_reference operator[](difference_type __i) {
return *(*this + __i);
}
};
 
inline _Bit_const_iterator
operator+(ptrdiff_t __n, const _Bit_const_iterator& __x) { return __x + __n; }
 
 
// Bit-vector base class, which encapsulates the difference between
// old SGI-style allocators and standard-conforming allocators.
 
// Base class for ordinary allocators.
template <class _Allocator, bool __is_static>
class _Bvector_alloc_base {
public:
typedef typename _Alloc_traits<bool, _Allocator>::allocator_type
allocator_type;
allocator_type get_allocator() const { return _M_data_allocator; }
 
_Bvector_alloc_base(const allocator_type& __a)
: _M_data_allocator(__a), _M_start(), _M_finish(), _M_end_of_storage(0) {}
 
protected:
unsigned int* _M_bit_alloc(size_t __n)
{ return _M_data_allocator.allocate((__n + __WORD_BIT - 1)/__WORD_BIT); }
void _M_deallocate() {
if (_M_start._M_p)
_M_data_allocator.deallocate(_M_start._M_p,
_M_end_of_storage - _M_start._M_p);
}
 
typename _Alloc_traits<unsigned int, _Allocator>::allocator_type
_M_data_allocator;
_Bit_iterator _M_start;
_Bit_iterator _M_finish;
unsigned int* _M_end_of_storage;
};
 
// Specialization for instanceless allocators.
template <class _Allocator>
class _Bvector_alloc_base<_Allocator, true> {
public:
typedef typename _Alloc_traits<bool, _Allocator>::allocator_type
allocator_type;
allocator_type get_allocator() const { return allocator_type(); }
 
_Bvector_alloc_base(const allocator_type&)
: _M_start(), _M_finish(), _M_end_of_storage(0) {}
 
protected:
typedef typename _Alloc_traits<unsigned int, _Allocator>::_Alloc_type
_Alloc_type;
unsigned int* _M_bit_alloc(size_t __n)
{ return _Alloc_type::allocate((__n + __WORD_BIT - 1)/__WORD_BIT); }
void _M_deallocate() {
if (_M_start._M_p)
_Alloc_type::deallocate(_M_start._M_p,
_M_end_of_storage - _M_start._M_p);
}
 
_Bit_iterator _M_start;
_Bit_iterator _M_finish;
unsigned int* _M_end_of_storage;
};
 
template <class _Alloc>
class _Bvector_base
: public _Bvector_alloc_base<_Alloc,
_Alloc_traits<bool, _Alloc>::_S_instanceless>
{
typedef _Bvector_alloc_base<_Alloc,
_Alloc_traits<bool, _Alloc>::_S_instanceless>
_Base;
public:
typedef typename _Base::allocator_type allocator_type;
 
_Bvector_base(const allocator_type& __a) : _Base(__a) {}
~_Bvector_base() { _Base::_M_deallocate(); }
};
 
} // namespace std
 
// Declare a partial specialization of vector<T, Alloc>.
#include <bits/stl_vector.h>
namespace std
{
 
template <typename _Alloc>
class vector<bool, _Alloc> : public _Bvector_base<_Alloc>
{
public:
typedef bool value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Bit_reference reference;
typedef bool const_reference;
typedef _Bit_reference* pointer;
typedef const bool* const_pointer;
typedef _Bit_iterator iterator;
typedef _Bit_const_iterator const_iterator;
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
typedef typename _Bvector_base<_Alloc>::allocator_type allocator_type;
allocator_type get_allocator() const {
return _Bvector_base<_Alloc>::get_allocator();
}
protected:
using _Bvector_base<_Alloc>::_M_bit_alloc;
using _Bvector_base<_Alloc>::_M_deallocate;
using _Bvector_base<_Alloc>::_M_start;
using _Bvector_base<_Alloc>::_M_finish;
using _Bvector_base<_Alloc>::_M_end_of_storage;
protected:
void _M_initialize(size_type __n) {
unsigned int* __q = _M_bit_alloc(__n);
_M_end_of_storage = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
_M_start = iterator(__q, 0);
_M_finish = _M_start + difference_type(__n);
}
void _M_insert_aux(iterator __position, bool __x) {
if (_M_finish._M_p != _M_end_of_storage) {
copy_backward(__position, _M_finish, _M_finish + 1);
*__position = __x;
++_M_finish;
}
else {
size_type __len = size() ? 2 * size() : __WORD_BIT;
unsigned int* __q = _M_bit_alloc(__len);
iterator __i = copy(begin(), __position, iterator(__q, 0));
*__i++ = __x;
_M_finish = copy(__position, end(), __i);
_M_deallocate();
_M_end_of_storage = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
_M_start = iterator(__q, 0);
}
}
template <class _InputIterator>
void _M_initialize_range(_InputIterator __first, _InputIterator __last,
input_iterator_tag) {
_M_start = iterator();
_M_finish = iterator();
_M_end_of_storage = 0;
for ( ; __first != __last; ++__first)
push_back(*__first);
}
template <class _ForwardIterator>
void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
forward_iterator_tag) {
size_type __n = 0;
distance(__first, __last, __n);
_M_initialize(__n);
copy(__first, __last, _M_start);
}
template <class _InputIterator>
void _M_insert_range(iterator __pos,
_InputIterator __first, _InputIterator __last,
input_iterator_tag) {
for ( ; __first != __last; ++__first) {
__pos = insert(__pos, *__first);
++__pos;
}
}
template <class _ForwardIterator>
void _M_insert_range(iterator __position,
_ForwardIterator __first, _ForwardIterator __last,
forward_iterator_tag) {
if (__first != __last) {
size_type __n = 0;
distance(__first, __last, __n);
if (capacity() - size() >= __n) {
copy_backward(__position, end(), _M_finish + difference_type(__n));
copy(__first, __last, __position);
_M_finish += difference_type(__n);
}
else {
size_type __len = size() + max(size(), __n);
unsigned int* __q = _M_bit_alloc(__len);
iterator __i = copy(begin(), __position, iterator(__q, 0));
__i = copy(__first, __last, __i);
_M_finish = copy(__position, end(), __i);
_M_deallocate();
_M_end_of_storage = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
_M_start = iterator(__q, 0);
}
}
}
public:
iterator begin() { return _M_start; }
const_iterator begin() const { return _M_start; }
iterator end() { return _M_finish; }
const_iterator end() const { return _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); }
size_type capacity() const {
return size_type(const_iterator(_M_end_of_storage, 0) - begin());
}
bool empty() const { return begin() == end(); }
reference operator[](size_type __n)
{ return *(begin() + difference_type(__n)); }
const_reference operator[](size_type __n) const
{ return *(begin() + difference_type(__n)); }
void _M_range_check(size_type __n) const {
if (__n >= this->size())
__throw_range_error("vector<bool>");
}
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]; }
explicit vector(const allocator_type& __a = allocator_type())
: _Bvector_base<_Alloc>(__a) {}
vector(size_type __n, bool __value,
const allocator_type& __a = allocator_type())
: _Bvector_base<_Alloc>(__a)
{
_M_initialize(__n);
fill(_M_start._M_p, _M_end_of_storage, __value ? ~0 : 0);
}
explicit vector(size_type __n)
: _Bvector_base<_Alloc>(allocator_type())
{
_M_initialize(__n);
fill(_M_start._M_p, _M_end_of_storage, 0);
}
vector(const vector& __x) : _Bvector_base<_Alloc>(__x.get_allocator()) {
_M_initialize(__x.size());
copy(__x.begin(), __x.end(), _M_start);
}
// Check whether it's an integral type. If so, it's not an iterator.
template <class _Integer>
void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) {
_M_initialize(__n);
fill(_M_start._M_p, _M_end_of_storage, __x ? ~0 : 0);
}
template <class _InputIterator>
void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
__false_type) {
_M_initialize_range(__first, __last, __iterator_category(__first));
}
template <class _InputIterator>
vector(_InputIterator __first, _InputIterator __last,
const allocator_type& __a = allocator_type())
: _Bvector_base<_Alloc>(__a)
{
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_initialize_dispatch(__first, __last, _Integral());
}
~vector() { }
vector& operator=(const vector& __x) {
if (&__x == this) return *this;
if (__x.size() > capacity()) {
_M_deallocate();
_M_initialize(__x.size());
}
copy(__x.begin(), __x.end(), begin());
_M_finish = begin() + difference_type(__x.size());
return *this;
}
// 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_t __n, bool __x) {
if (__n > size()) {
fill(_M_start._M_p, _M_end_of_storage, __x ? ~0 : 0);
insert(end(), __n - size(), __x);
}
else {
erase(begin() + __n, end());
fill(_M_start._M_p, _M_end_of_storage, __x ? ~0 : 0);
}
}
void assign(size_t __n, bool __x) { _M_fill_assign(__n, __x); }
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_t) __n, (bool) __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) {
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 _ForwardIterator>
void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
forward_iterator_tag) {
size_type __len = 0;
distance(__first, __last, __len);
if (__len < size())
erase(copy(__first, __last, begin()), end());
else {
_ForwardIterator __mid = __first;
advance(__mid, size());
copy(__first, __mid, begin());
insert(end(), __mid, __last);
}
}
void reserve(size_type __n) {
if (capacity() < __n) {
unsigned int* __q = _M_bit_alloc(__n);
_M_finish = copy(begin(), end(), iterator(__q, 0));
_M_deallocate();
_M_start = iterator(__q, 0);
_M_end_of_storage = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
}
}
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(bool __x) {
if (_M_finish._M_p != _M_end_of_storage)
*_M_finish++ = __x;
else
_M_insert_aux(end(), __x);
}
void swap(vector<bool, _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, bool __x = bool()) {
difference_type __n = __position - begin();
if (_M_finish._M_p != _M_end_of_storage && __position == end())
*_M_finish++ = __x;
else
_M_insert_aux(__position, __x);
return begin() + __n;
}
// 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, __n, __x);
}
template <class _InputIterator>
void _M_insert_dispatch(iterator __pos,
_InputIterator __first, _InputIterator __last,
__false_type) {
_M_insert_range(__pos, __first, __last, __iterator_category(__first));
}
template <class _InputIterator>
void insert(iterator __position,
_InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_insert_dispatch(__position, __first, __last, _Integral());
}
void _M_fill_insert(iterator __position, size_type __n, bool __x) {
if (__n == 0) return;
if (capacity() - size() >= __n) {
copy_backward(__position, end(), _M_finish + difference_type(__n));
fill(__position, __position + difference_type(__n), __x);
_M_finish += difference_type(__n);
}
else {
size_type __len = size() + max(size(), __n);
unsigned int* __q = _M_bit_alloc(__len);
iterator __i = copy(begin(), __position, iterator(__q, 0));
fill_n(__i, __n, __x);
_M_finish = copy(__position, end(), __i + difference_type(__n));
_M_deallocate();
_M_end_of_storage = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
_M_start = iterator(__q, 0);
}
}
void insert(iterator __position, size_type __n, bool __x) {
_M_fill_insert(__position, __n, __x);
}
void pop_back() { --_M_finish; }
iterator erase(iterator __position) {
if (__position + 1 != end())
copy(__position + 1, end(), __position);
--_M_finish;
return __position;
}
iterator erase(iterator __first, iterator __last) {
_M_finish = copy(__last, end(), __first);
return __first;
}
void resize(size_type __new_size, bool __x = bool()) {
if (__new_size < size())
erase(begin() + difference_type(__new_size), end());
else
insert(end(), __new_size - size(), __x);
}
void flip() {
for (unsigned int* __p = _M_start._M_p; __p != _M_end_of_storage; ++__p)
*__p = ~*__p;
}
void clear() { erase(begin(), end()); }
};
 
// This typedef is non-standard. It is provided for backward compatibility.
typedef vector<bool, alloc> bit_vector;
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_BVECTOR_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_config.h
0,0 → 1,573
/*
*
* 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_TEMPLATE_FRIENDS: defined if the compiler supports templatized
// friend declarations.
// * __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 included
// in the C99 standard.)
// * __STL_THREADS is defined if thread safety is needed.
// * __STL_VOLATILE is defined to be "volatile" if threads are being
// used, and the empty string otherwise.
// * __STL_USE_CONCEPT_CHECKS enables some extra compile-time error
// checking to make sure that user-defined template arguments satisfy
// all of the appropriate requirements. This may result in more
// comprehensible error messages. It incurs no runtime overhead. This
// feature requires member templates and partial specialization.
// * __STL_NO_USING_CLAUSE_IN_CLASS: The compiler does not handle "using"
// clauses inside of class definitions.
// * __STL_NO_FRIEND_TEMPLATE_CLASS: The compiler does not handle friend
// declaractions where the friend is a template class.
// * __STL_NO_FUNCTION_PTR_IN_CLASS_TEMPLATE: The compiler does not
// support the use of a function pointer type as the argument
// for a template.
// * __STL_MEMBER_TEMPLATE_KEYWORD: standard C++ requires the template
// keyword in a few new places (14.2.4). This flag is set for
// compilers that support (and require) this usage.
 
 
// 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_NO_CONCEPT_CHECKS: if defined, disables the error checking that
// we get from __STL_USE_CONCEPT_CHECKS.
// * __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_TEMPLATE_FRIENDS
# 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 COMPILER_VERSION < 720 || (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) || \
!defined(__STL_HAS_NAMESPACES) || defined(__STL_NO_NAMESPACES)
# 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_TEMPLATE_FRIENDS
# 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
# ifdef __EXCEPTIONS
# define __STL_USE_EXCEPTIONS
# endif
# define __STL_THROW_RANGE_ERRORS
# 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
# if (__GNUC__ < 2) || (__GNUC__ == 2 && __GNUC_MINOR__ < 95)
# define __STL_NO_FUNCTION_PTR_IN_CLASS_TEMPLATE
# 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_TEMPLATE_FRIENDS
# 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_TEMPLATE_FRIENDS
# 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, GCC compiler using the Microsoft C runtime
# if defined(__MINGW32__)
# define __STL_NO_DRAND48
# ifdef _MT
# define __STL_WIN32THREADS
# endif
# endif
 
// Cygwin32, GCC compiler on MS Windows
# if defined(__CYGWIN__)
# define __STL_NO_DRAND48
# endif
 
 
 
// Microsoft compiler.
# if defined(_MSC_VER) && !defined(__ICL) && !defined(__MWERKS__)
# define __STL_NO_DRAND48
# define __STL_STATIC_CONST_INIT_BUG
# define __STL_NEED_TYPENAME
# define __STL_NO_USING_CLAUSE_IN_CLASS
# define __STL_NO_FRIEND_TEMPLATE_CLASS
# 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
# define __STL_NO_BAD_ALLOC
# 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_CAN_THROW_RANGE_ERRORS
# define NOMINMAX
# undef min
# undef max
// disable warning 'initializers put in unrecognized initialization area'
# pragma warning ( disable : 4075 )
// disable warning 'empty controlled statement found'
# pragma warning ( disable : 4390 )
// disable warning 'debug symbol greater than 255 chars'
# pragma warning ( disable : 4786 )
# 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_DEFAULT_CONSTRUCTOR_BUG
# if __BORLANDC__ >= 0x540 /* C++ Builder 4.0 */
# define __STL_CLASS_PARTIAL_SPECIALIZATION
# define __STL_FUNCTION_TMPL_PARTIAL_ORDER
# define __STL_EXPLICIT_FUNCTION_TMPL_ARGS
# define __STL_MEMBER_TEMPLATES
# define __STL_TEMPLATE_FRIENDS
# else
# define __STL_NEED_TYPENAME
# define __STL_LIMITED_DEFAULT_TEMPLATES
# define __SGI_STL_NO_ARROW_OPERATOR
# define __STL_NON_TYPE_TMPL_PARAM_BUG
# endif
# 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_LIMITED_DEFAULT_TEMPLATES
# define __STL_DEPENDENT_DEFAULT_TMPL(_Tp)
# else
# define __STL_DEPENDENT_DEFAULT_TMPL(_Tp) = _Tp
# 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
 
# ifndef __STL_DEFAULT_ALLOCATOR
# ifdef __STL_USE_STD_ALLOCATORS
# define __STL_DEFAULT_ALLOCATOR(T) allocator< T >
# else
# define __STL_DEFAULT_ALLOCATOR(T) alloc
# endif
# 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
 
// Because concept-checks do not presently work correctly, they
// are disabled.
#if 0
#if defined(__STL_CLASS_PARTIAL_SPECIALIZATION) \
&& defined(__STL_MEMBER_TEMPLATES) \
&& !defined(_STL_NO_CONCEPT_CHECKS)
# define __STL_USE_CONCEPT_CHECKS
#endif
#endif
 
#endif /* __STL_CONFIG_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_construct.h
0,0 → 1,123
/*
*
* 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 <new>
 
namespace std
{
 
// construct and destroy. These functions are not part of the C++ standard,
// and are provided for backward compatibility with the HP STL. We also
// provide internal names _Construct and _Destroy that can be used within
// the library, so that standard-conforming pieces don't have to rely on
// non-standard extensions.
 
// Internal names
 
template <class _T1, class _T2>
inline void _Construct(_T1* __p, const _T2& __value) {
new ((void*) __p) _T1(__value);
}
template <class _T1>
inline void _Construct(_T1* __p) {
new ((void*) __p) _T1();
}
 
template <class _Tp>
inline void _Destroy(_Tp* __pointer) {
__pointer->~_Tp();
}
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(int*, int*) {}
inline void _Destroy(long*, long*) {}
inline void _Destroy(float*, float*) {}
inline void _Destroy(double*, double*) {}
inline void _Destroy(wchar_t*, wchar_t*) {}
 
// --------------------------------------------------
// Old names from the HP STL.
 
template <class _T1, class _T2>
inline void construct(_T1* __p, const _T2& __value) {
_Construct(__p, __value);
}
 
template <class _T1>
inline void construct(_T1* __p) {
_Construct(__p);
}
 
template <class _Tp>
inline void destroy(_Tp* __pointer) {
_Destroy(__pointer);
}
 
template <class _ForwardIterator>
inline void destroy(_ForwardIterator __first, _ForwardIterator __last) {
_Destroy(__first, __last);
}
 
} // namespace std
 
#endif /* _CPP_BITS_STL_CONSTRUCT_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_deque.h
0,0 → 1,1322
/*
*
* 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.
*/
 
#include <bits/concept_check.h>
#include <bits/stl_iterator_base_types.h>
#include <bits/stl_iterator_base_funcs.h>
 
#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, there was an extra template
* parameter so users could control the node size. This extension
* turns out to violate the C++ standard (it can be detected using
* template template parameters), and it has been removed.
*/
 
namespace std
{
 
// 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 __size) {
return __size < 512 ? size_t(512 / __size) : size_t(1);
}
 
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(sizeof(_Tp)); }
 
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; }
pointer operator->() const { return _M_cur; }
 
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());
}
};
 
template <class _Tp, class _Ref, class _Ptr>
inline _Deque_iterator<_Tp, _Ref, _Ptr>
operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
{
return __x + __n;
}
 
 
// 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.
 
// Base class for ordinary allocators.
template <class _Tp, class _Alloc, 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(sizeof(_Tp)));
}
void _M_deallocate_node(_Tp* __p) {
_M_node_allocator.deallocate(__p, __deque_buf_size(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>
class _Deque_alloc_base<_Tp, _Alloc, 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(sizeof(_Tp)));
}
void _M_deallocate_node(_Tp* __p) {
_Node_alloc_type::deallocate(__p, __deque_buf_size(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>
class _Deque_base
: public _Deque_alloc_base<_Tp,_Alloc,
_Alloc_traits<_Tp, _Alloc>::_S_instanceless>
{
public:
typedef _Deque_alloc_base<_Tp,_Alloc,
_Alloc_traits<_Tp, _Alloc>::_S_instanceless>
_Base;
typedef typename _Base::allocator_type allocator_type;
typedef _Deque_iterator<_Tp,_Tp&,_Tp*> iterator;
typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*> 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;
};
 
// Non-inline member functions from _Deque_base.
 
template <class _Tp, class _Alloc>
_Deque_base<_Tp,_Alloc>::~_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>
void
_Deque_base<_Tp,_Alloc>::_M_initialize_map(size_t __num_elements)
{
size_t __num_nodes =
__num_elements / __deque_buf_size(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(sizeof(_Tp));
}
 
template <class _Tp, class _Alloc>
void _Deque_base<_Tp,_Alloc>::_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>
void
_Deque_base<_Tp,_Alloc>::_M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish)
{
for (_Tp** __n = __nstart; __n < __nfinish; ++__n)
_M_deallocate_node(*__n);
}
 
template <class _Tp, class _Alloc = allocator<_Tp> >
class deque : protected _Deque_base<_Tp, _Alloc> {
 
// concept requirements
__glibcpp_class_requires(_Tp, _SGIAssignableConcept);
 
typedef _Deque_base<_Tp, _Alloc> _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;
 
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
 
protected: // Internal typedefs
typedef pointer* _Map_pointer;
static size_t _S_buffer_size() { return __deque_buf_size(sizeof(_Tp)); }
 
protected:
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;
 
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)]; }
 
void _M_range_check(size_type __n) const {
if (__n >= this->size())
__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]; }
 
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()); }
 
// 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));
}
 
~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);
}
 
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());
}
 
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);
 
// 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));
}
 
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);
 
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);
 
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
 
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);
 
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);
 
template <class _ForwardIterator>
void _M_insert_aux(iterator __pos,
_ForwardIterator __first, _ForwardIterator __last,
size_type __n);
 
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);
};
 
// Non-inline member functions
 
template <class _Tp, class _Alloc>
template <class _InputIter>
void deque<_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>
void deque<_Tp, _Alloc>::_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);
}
 
template <class _Tp, class _Alloc>
typename deque<_Tp,_Alloc>::iterator
deque<_Tp,_Alloc>::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>
void deque<_Tp,_Alloc>::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>
void deque<_Tp,_Alloc>::_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)));
}
 
template <class _Tp, class _Alloc> template <class _InputIterator>
void deque<_Tp,_Alloc>::_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> template <class _ForwardIterator>
void deque<_Tp,_Alloc>::_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)));
}
 
// Called only if _M_finish._M_cur == _M_finish._M_last - 1.
template <class _Tp, class _Alloc>
void deque<_Tp,_Alloc>::_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>
void deque<_Tp,_Alloc>::_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>
void deque<_Tp,_Alloc>::_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>
void deque<_Tp,_Alloc>::_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>
void deque<_Tp,_Alloc>::_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>
void deque<_Tp,_Alloc>::_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;
}
 
template <class _Tp, class _Alloc> template <class _InputIterator>
void deque<_Tp,_Alloc>::insert(iterator __pos,
_InputIterator __first, _InputIterator __last,
input_iterator_tag)
{
copy(__first, __last, inserter(*this, __pos));
}
 
template <class _Tp, class _Alloc> template <class _ForwardIterator>
void
deque<_Tp,_Alloc>::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);
}
 
template <class _Tp, class _Alloc>
typename deque<_Tp, _Alloc>::iterator
deque<_Tp,_Alloc>::_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>
typename deque<_Tp,_Alloc>::iterator
deque<_Tp,_Alloc>::_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>
void deque<_Tp,_Alloc>::_M_insert_aux(iterator __pos,
size_type __n,
const value_type& __x)
{
const difference_type __elems_before = __pos - _M_start;
size_type __length = this->size();
value_type __x_copy = __x;
if (__elems_before < difference_type(__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));
}
}
 
template <class _Tp, class _Alloc> template <class _ForwardIterator>
void deque<_Tp,_Alloc>::_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));
}
}
 
template <class _Tp, class _Alloc>
void deque<_Tp,_Alloc>::_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>
void deque<_Tp,_Alloc>::_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>
void deque<_Tp,_Alloc>::_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.
 
template <class _Tp, class _Alloc>
inline bool operator==(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y) {
return __x.size() == __y.size() &&
equal(__x.begin(), __x.end(), __y.begin());
}
 
template <class _Tp, class _Alloc>
inline bool operator<(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y) {
return lexicographical_compare(__x.begin(), __x.end(),
__y.begin(), __y.end());
}
 
template <class _Tp, class _Alloc>
inline bool operator!=(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y) {
return !(__x == __y);
}
 
template <class _Tp, class _Alloc>
inline bool operator>(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y) {
return __y < __x;
}
 
template <class _Tp, class _Alloc>
inline bool operator<=(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y) {
return !(__y < __x);
}
template <class _Tp, class _Alloc>
inline bool operator>=(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y) {
return !(__x < __y);
}
 
template <class _Tp, class _Alloc>
inline void swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y) {
__x.swap(__y);
}
 
} // namespace std
#endif /* __SGI_STL_INTERNAL_DEQUE_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_function.h
0,0 → 1,744
/*
*
* 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
 
namespace std
{
 
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);
}
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 109. Missing binders for non-const sequence elements
typename _Operation::result_type
operator()(typename _Operation::second_argument_type& __x) const {
return op(value, __x);
}
#endif
};
 
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);
}
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 109. Missing binders for non-const sequence elements
typename _Operation::result_type
operator()(typename _Operation::first_argument_type& __x) const {
return op(__x, value);
}
#endif
};
 
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;
};
 
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;
};
 
 
// 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); }
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_FUNCTION_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_heap.h
0,0 → 1,314
/*
*
* 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
 
namespace std
{
 
// 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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_RandomAccessIterator>::value_type>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_RandomAccessIterator>::value_type>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_RandomAccessIterator>::value_type>);
 
__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)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>);
 
__make_heap(__first, __last, __comp,
__value_type(__first), __distance_type(__first));
}
 
template <class _RandomAccessIterator>
void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>);
__glibcpp_function_requires(_LessThanComparableConcept<
typename iterator_traits<_RandomAccessIterator>::value_type>);
 
while (__last - __first > 1)
pop_heap(__first, __last--);
}
 
template <class _RandomAccessIterator, class _Compare>
void
sort_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp)
{
// concept requirements
__glibcpp_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>);
 
while (__last - __first > 1)
pop_heap(__first, __last--, __comp);
}
 
} // namespace std
 
#endif /* _CPP_BITS_STL_HEAP_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_iterator.h
0,0 → 1,548
/*
*
* 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
 
namespace std
{
 
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; }
};
 
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; }
};
 
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; }
};
 
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;
}
pointer operator->() const { return &(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;
}
};
 
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();
}
 
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);
}
 
 
// 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) {}
template <class _Iter>
reverse_iterator(const reverse_iterator<_Iter>& __x)
: current(__x.base()) {}
iterator_type base() const { return current; }
reference operator*() const {
_Iterator __tmp = current;
return *--__tmp;
}
pointer operator->() const { return &(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();
}
 
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);
}
 
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);
}
 
 
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);
}
 
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);
}
 
 
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;
};
 
 
// 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>
{
 
protected:
_Iterator _M_current;
 
public:
typedef __normal_iterator<_Iterator, _Container> normal_iterator_type;
typedef iterator_traits<_Iterator> __traits_type;
typedef typename __traits_type::iterator_category iterator_category;
typedef typename __traits_type::value_type value_type;
typedef typename __traits_type::difference_type difference_type;
typedef typename __traits_type::pointer pointer;
typedef typename __traits_type::reference reference;
 
__normal_iterator() : _M_current(_Iterator()) { }
 
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
reference
operator*() const { return *_M_current; }
 
pointer
operator->() const { return _M_current; }
 
normal_iterator_type&
operator++() { ++_M_current; return *this; }
 
normal_iterator_type
operator++(int) { return __normal_iterator(_M_current++); }
 
// Bidirectional iterator requirements
normal_iterator_type&
operator--() { --_M_current; return *this; }
 
normal_iterator_type
operator--(int) { return __normal_iterator(_M_current--); }
 
// Random access iterator requirements
reference
operator[](const difference_type& __n) const
{ return _M_current[__n]; }
 
normal_iterator_type&
operator+=(const difference_type& __n)
{ _M_current += __n; return *this; }
 
normal_iterator_type
operator+(const difference_type& __n) const
{ return __normal_iterator(_M_current + __n); }
 
normal_iterator_type&
operator-=(const difference_type& __n)
{ _M_current -= __n; return *this; }
 
normal_iterator_type
operator-(const difference_type& __n) const
{ return __normal_iterator(_M_current - __n); }
 
difference_type
operator-(const normal_iterator_type& __i) const
{ return _M_current - __i._M_current; }
 
const _Iterator&
base() const { return _M_current; }
};
 
// forward iterator requirements
 
template<typename _IteratorL, typename _IteratorR, typename _Container>
inline 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>
inline 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>
inline 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>
inline bool
operator>(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs)
{ return __rhs < __lhs; }
 
template<typename _IteratorL, typename _IteratorR, typename _Container>
inline bool
operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs)
{ return !(__rhs < __lhs); }
 
template<typename _IteratorL, typename _IteratorR, typename _Container>
inline 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); }
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_ITERATOR_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_iterator_base.h
0,0 → 1,367
/*
*
* 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.
 
#include <bits/concept_checks.h>
 
__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)
{
__STL_REQUIRES(_RandomAccessIterator, _RandomAccessIterator);
__n += __last - __first;
}
 
template <class _InputIterator, class _Distance>
inline void distance(_InputIterator __first,
_InputIterator __last, _Distance& __n)
{
__STL_REQUIRES(_InputIterator, _InputIterator);
__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) {
__STL_REQUIRES(_RandomAccessIterator, _RandomAccessIterator);
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;
__STL_REQUIRES(_InputIterator, _InputIterator);
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) {
__STL_REQUIRES(_BidirectionalIterator, _BidirectionalIterator);
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) {
__STL_REQUIRES(_RandomAccessIterator, _RandomAccessIterator);
__i += __n;
}
 
template <class _InputIterator, class _Distance>
inline void advance(_InputIterator& __i, _Distance __n) {
__STL_REQUIRES(_InputIterator, _InputIterator);
__advance(__i, __n, iterator_category(__i));
}
 
__STL_END_NAMESPACE
 
#endif /* __SGI_STL_INTERNAL_ITERATOR_BASE_H */
 
 
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_iterator_base_funcs.h
0,0 → 1,152
/*
*
* 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_FUNCS_H
#define __SGI_STL_INTERNAL_ITERATOR_BASE_FUNCS_H
 
// This file contains all of the general iterator-related utility
// functions, such as distance() and advance().
// The internal file stl_iterator.h contains predefined iterators,
// such as front_insert_iterator and istream_iterator.
 
#pragma GCC system_header
#include <bits/concept_check.h>
 
namespace std
{
 
// There are two signatures for distance. In addition to the one taking
// two iterators and returning a result, there is another taking two
// iterators and a reference-to-result variable, and returning nothing.
// The latter seems to be an SGI extension. -- pedwards
template <class _InputIterator, class _Distance>
inline void __distance(_InputIterator __first, _InputIterator __last,
_Distance& __n, input_iterator_tag)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator>);
while (__first != __last) { ++__first; ++__n; }
}
 
template <class _RandomAccessIterator, class _Distance>
inline void __distance(_RandomAccessIterator __first,
_RandomAccessIterator __last,
_Distance& __n, random_access_iterator_tag)
{
// concept requirements
__glibcpp_function_requires(_RandomAccessIteratorConcept<_RandomAccessIterator>);
__n += __last - __first;
}
 
template <class _InputIterator, class _Distance>
inline void distance(_InputIterator __first,
_InputIterator __last, _Distance& __n)
{
// concept requirements -- taken care of in __distance
__distance(__first, __last, __n, iterator_category(__first));
}
 
template <class _InputIterator>
inline typename iterator_traits<_InputIterator>::difference_type
__distance(_InputIterator __first, _InputIterator __last, input_iterator_tag)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator>);
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)
{
// concept requirements
__glibcpp_function_requires(_RandomAccessIteratorConcept<_RandomAccessIterator>);
return __last - __first;
}
 
template <class _InputIterator>
inline typename iterator_traits<_InputIterator>::difference_type
distance(_InputIterator __first, _InputIterator __last)
{
// concept requirements -- taken care of in __distance
typedef typename iterator_traits<_InputIterator>::iterator_category
_Category;
return __distance(__first, __last, _Category());
}
 
template <class _InputIter, class _Distance>
inline void __advance(_InputIter& __i, _Distance __n, input_iterator_tag)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIter>);
while (__n--) ++__i;
}
 
template <class _BidirectionalIterator, class _Distance>
inline void __advance(_BidirectionalIterator& __i, _Distance __n,
bidirectional_iterator_tag)
{
// concept requirements
__glibcpp_function_requires(_BidirectionalIteratorConcept<_BidirectionalIterator>);
if (__n > 0)
while (__n--) ++__i;
else
while (__n++) --__i;
}
 
template <class _RandomAccessIterator, class _Distance>
inline void __advance(_RandomAccessIterator& __i, _Distance __n,
random_access_iterator_tag)
{
// concept requirements
__glibcpp_function_requires(_RandomAccessIteratorConcept<_RandomAccessIterator>);
__i += __n;
}
 
template <class _InputIterator, class _Distance>
inline void advance(_InputIterator& __i, _Distance __n)
{
// concept requirements -- taken care of in __advance
__advance(__i, __n, iterator_category(__i));
}
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_ITERATOR_BASE_FUNCS_H */
 
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_iterator_base_types.h
0,0 → 1,182
/*
*
* 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_TYPES_H
#define __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H
 
// This file contains all of the general iterator-related utility
// types, such as iterator_traits and struct iterator.
// The internal file stl_iterator.h contains predefined iterators,
// such as front_insert_iterator and istream_iterator.
 
#pragma GCC system_header
 
namespace std
{
 
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;
};
 
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;
};
 
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); }
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_ITERATOR_BASE_TYPES_H */
 
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_list.h
0,0 → 1,745
/*
*
* 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
 
#include <bits/concept_check.h>
 
namespace std
{
 
struct _List_node_base {
_List_node_base* _M_next;
_List_node_base* _M_prev;
};
 
template <class _Tp>
struct _List_node : public _List_node_base {
_Tp _M_data;
};
 
struct _List_iterator_base {
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef bidirectional_iterator_tag iterator_category;
 
_List_node_base* _M_node;
 
_List_iterator_base(_List_node_base* __x) : _M_node(__x) {}
_List_iterator_base() {}
 
void _M_incr() { _M_node = _M_node->_M_next; }
void _M_decr() { _M_node = _M_node->_M_prev; }
 
bool operator==(const _List_iterator_base& __x) const {
return _M_node == __x._M_node;
}
bool operator!=(const _List_iterator_base& __x) const {
return _M_node != __x._M_node;
}
};
 
template<class _Tp, class _Ref, class _Ptr>
struct _List_iterator : public _List_iterator_base {
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 _Tp value_type;
typedef _Ptr pointer;
typedef _Ref reference;
typedef _List_node<_Tp> _Node;
 
_List_iterator(_Node* __x) : _List_iterator_base(__x) {}
_List_iterator() {}
_List_iterator(const iterator& __x) : _List_iterator_base(__x._M_node) {}
 
reference operator*() const { return ((_Node*) _M_node)->_M_data; }
pointer operator->() const { return &(operator*()); }
 
_Self& operator++() {
this->_M_incr();
return *this;
}
_Self operator++(int) {
_Self __tmp = *this;
this->_M_incr();
return __tmp;
}
_Self& operator--() {
this->_M_decr();
return *this;
}
_Self operator--(int) {
_Self __tmp = *this;
this->_M_decr();
return __tmp;
}
};
 
 
// 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.
 
 
// 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();
};
 
 
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>
{
// concept requirements
__glibcpp_class_requires(_Tp, _SGIAssignableConcept);
 
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;
 
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
 
protected:
using _Base::_M_node;
using _Base::_M_put_node;
using _Base::_M_get_node;
 
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;
__position._M_node->_M_prev->_M_next = __tmp;
__position._M_node->_M_prev = __tmp;
return __tmp;
}
iterator insert(iterator __position) { return insert(__position, _Tp()); }
 
// 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());
}
 
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) {
_List_node_base* __next_node = __position._M_node->_M_next;
_List_node_base* __prev_node = __position._M_node->_M_prev;
_Node* __n = (_Node*) __position._M_node;
__prev_node->_M_next = __next_node;
__next_node->_M_prev = __prev_node;
_Destroy(&__n->_M_data);
_M_put_node(__n);
return iterator((_Node*) __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) { this->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()); }
 
// 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); }
 
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);
 
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);
 
protected:
void transfer(iterator __position, iterator __first, iterator __last) {
if (__position != __last) {
// Remove [first, last) from its old position.
__last._M_node->_M_prev->_M_next = __position._M_node;
__first._M_node->_M_prev->_M_next = __last._M_node;
__position._M_node->_M_prev->_M_next = __first._M_node;
 
// Splice [first, last) into its new position.
_List_node_base* __tmp = __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())
this->transfer(__position, __x.begin(), __x.end());
}
void splice(iterator __position, list&, iterator __i) {
iterator __j = __i;
++__j;
if (__position == __i || __position == __j) return;
this->transfer(__position, __i, __j);
}
void splice(iterator __position, list&, iterator __first, iterator __last) {
if (__first != __last)
this->transfer(__position, __first, __last);
}
void remove(const _Tp& __value);
void unique();
void merge(list& __x);
void reverse();
void sort();
 
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);
};
 
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());
}
 
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);
}
 
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);
}
 
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>
typename 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());
}
 
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);
}
 
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);
}
 
inline void __List_base_reverse(_List_node_base* __p)
{
_List_node_base* __tmp = __p;
do {
std::swap(__tmp->_M_next, __tmp->_M_prev);
__tmp = __tmp->_M_prev; // Old next node is now prev.
} while (__tmp != __p);
}
 
template <class _Tp, class _Alloc>
inline void list<_Tp, _Alloc>::reverse()
{
__List_base_reverse(this->_M_node);
}
 
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 && _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]);
}
}
 
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 && _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]);
}
}
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_LIST_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_map.h
0,0 → 1,231
/*
*
* 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
 
#include <bits/concept_check.h>
 
namespace std
{
 
template <class _Key, class _Tp, class _Compare = less<_Key>,
class _Alloc = allocator<pair<const _Key, _Tp> > >
class map
{
// concept requirements
__glibcpp_class_requires(_Tp, _SGIAssignableConcept);
__glibcpp_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept);
 
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) {}
 
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); }
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); }
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_unique(__first, __last);
}
 
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.find(__x) == _M_t.end() ? 0 : 1;
}
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);
}
 
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>&);
};
 
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;
}
 
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);
}
 
} // namespace std
 
#endif /* _CPP_BITS_STL_MAP_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_multimap.h
0,0 → 1,235
/*
*
* 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
 
#include <bits/concept_check.h>
 
namespace std
{
 
// 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
{
// concept requirements
__glibcpp_class_requires(_Tp, _SGIAssignableConcept);
__glibcpp_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept);
 
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) { }
 
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); }
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);
}
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_equal(__first, __last);
}
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);
}
 
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>&);
};
 
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;
}
 
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);
}
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_MULTIMAP_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_multiset.h
0,0 → 1,247
/*
*
* 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
 
#include <bits/concept_check.h>
 
namespace std
{
 
// 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
{
// concept requirements
__glibcpp_class_requires(_Key, _SGIAssignableConcept);
__glibcpp_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept);
 
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) {}
 
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); }
 
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);
}
 
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_equal(__first, __last);
}
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:
 
size_type count(const key_type& __x) const { return _M_t.count(__x); }
 
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
//214. set::find() missing const overload
iterator find(const key_type& __x) { return _M_t.find(__x); }
const_iterator find(const key_type& __x) const { return _M_t.find(__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);
}
#else
iterator find(const key_type& __x) const { return _M_t.find(__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);
}
#endif
 
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>&);
};
 
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;
}
 
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);
}
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_MULTISET_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_numeric.h
0,0 → 1,279
/*
*
* 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
 
namespace std
{
 
template <class _InputIterator, class _Tp>
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator2>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator1>);
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator2>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIterator,
typename iterator_traits<_InputIterator>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIterator,
typename iterator_traits<_InputIterator>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIterator,
typename iterator_traits<_InputIterator>::value_type>);
 
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)
{
// concept requirements
__glibcpp_function_requires(_InputIteratorConcept<_InputIterator>);
__glibcpp_function_requires(_OutputIteratorConcept<_OutputIterator,
typename iterator_traits<_InputIterator>::value_type>);
 
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 _ForwardIter, class _Tp>
void
iota(_ForwardIter __first, _ForwardIter __last, _Tp __value)
{
// concept requirements
__glibcpp_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIter>);
__glibcpp_function_requires(_ConvertibleConcept<_Tp,
typename iterator_traits<_ForwardIter>::value_type>);
 
while (__first != __last)
*__first++ = __value++;
}
 
} // namespace std
 
#endif /* _CPP_BITS_STL_NUMERIC_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_pair.h
0,0 → 1,106
/*
*
* 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
 
namespace std
{
 
template <class _T1, class _T2>
struct pair {
typedef _T1 first_type;
typedef _T2 second_type;
 
_T1 first;
_T2 second;
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
//265. std::pair::pair() effects overly restrictive
pair() : first(), second() {}
#else
pair() : first(_T1()), second(_T2()) {}
#endif
pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
 
template <class _U1, class _U2>
pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
};
 
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);
}
 
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);
}
 
template <class _T1, class _T2>
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
//181. make_pair() unintended behavior
inline pair<_T1, _T2> make_pair(_T1 __x, _T2 __y)
#else
inline pair<_T1, _T2> make_pair(const _T1& __x, const _T2& __y)
#endif
{
return pair<_T1, _T2>(__x, __y);
}
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_PAIR_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_pthread_alloc.h
0,0 → 1,26
/*
* 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>
 
using std::_Pthread_alloc_template;
using std::pthread_alloc;
 
#endif /* _CPP_BITS_STL_PTHREAD_ALLOC_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_queue.h
0,0 → 1,198
/*
*
* 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
 
#include <bits/concept_check.h>
 
namespace std
{
 
// 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
{
// concept requirements
__glibcpp_class_requires(_Tp, _SGIAssignableConcept);
__glibcpp_class_requires(_Sequence, _FrontInsertionSequenceConcept);
__glibcpp_class_requires(_Sequence, _BackInsertionSequenceConcept);
typedef typename _Sequence::value_type _Sequence_value_type;
__glibcpp_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept);
 
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>&);
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:
explicit queue(const _Sequence& __c = _Sequence()) : 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;
}
 
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);
}
 
template <class _Tp,
class _Sequence = vector<_Tp>,
class _Compare = less<typename _Sequence::value_type> >
class priority_queue
{
// concept requirements
__glibcpp_class_requires(_Tp, _SGIAssignableConcept);
__glibcpp_class_requires(_Sequence, _SequenceConcept);
__glibcpp_class_requires(_Sequence, _RandomAccessContainerConcept);
typedef typename _Sequence::value_type _Sequence_value_type;
__glibcpp_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept);
__glibcpp_class_requires4(_Compare, bool, _Tp, _Tp, _BinaryFunctionConcept);
 
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:
explicit priority_queue(const _Compare& __x = _Compare(),
const _Sequence& __s = _Sequence())
: c(__s), comp(__x)
{ make_heap(c.begin(), c.end(), comp); }
 
template <class _InputIterator>
priority_queue(_InputIterator __first, _InputIterator __last,
const _Compare& __x = _Compare(),
const _Sequence& __s = _Sequence())
: c(__s), comp(__x)
{
c.insert(c.end(), __first, __last);
make_heap(c.begin(), c.end(), comp);
}
 
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
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_QUEUE_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_raw_storage_iter.h
0,0 → 1,72
/*
*
* 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
 
namespace std
{
 
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;
}
};
 
 
} // namespace std
 
#endif /* _CPP_BITS_STL_RAW_STORAGE_ITERATOR_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_relops.h
0,0 → 1,76
/*
*
* 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.
*/
 
/**** libstdc++-v3 note: Inclusion of this file has been removed from
* all of the other STL headers for safety reasons, except std_utility.h.
* For more information, see the thread of about twenty messages starting
* with <URL:http://gcc.gnu.org/ml/libstdc++/2001-01/msg00223.html>, or the
* FAQ at <URL:http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#4_4>.
*
* Short summary: the rel_ops operators cannot be made to play nice.
* Don't use them.
*/
 
#ifndef _CPP_BITS_STL_RELOPS_H
#define _CPP_BITS_STL_RELOPS_H 1
 
namespace std
{
namespace rel_ops
{
 
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);
}
 
} // namespace rel_ops
} // namespace std
 
#endif /* _CPP_BITS_STL_RELOPS_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_set.h
0,0 → 1,244
/*
*
* 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
 
#include <bits/concept_check.h>
 
namespace std
{
 
// 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
{
// concept requirements
__glibcpp_class_requires(_Key, _SGIAssignableConcept);
__glibcpp_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept);
 
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) {}
 
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); }
 
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);
}
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_unique(__first, __last);
}
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:
 
size_type count(const key_type& __x) const {
return _M_t.find(__x) == _M_t.end() ? 0 : 1;
}
 
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
//214. set::find() missing const overload
iterator find(const key_type& __x) { return _M_t.find(__x); }
const_iterator find(const key_type& __x) const { return _M_t.find(__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);
}
#else
iterator find(const key_type& __x) const { return _M_t.find(__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);
}
#endif
 
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>&);
};
 
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;
}
 
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);
}
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_SET_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_stack.h
0,0 → 1,130
/*
*
* 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
 
#include <bits/concept_check.h>
 
namespace std
{
 
// 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
{
// concept requirements
__glibcpp_class_requires(_Tp, _SGIAssignableConcept);
__glibcpp_class_requires(_Sequence, _BackInsertionSequenceConcept);
typedef typename _Sequence::value_type _Sequence_value_type;
__glibcpp_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept);
 
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>&);
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;
}
 
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);
}
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_STACK_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_tempbuf.h
0,0 → 1,152
/*
*
* 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
 
namespace std
{
 
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);
}
 
template <class _Tp>
inline pair<_Tp*, ptrdiff_t> get_temporary_buffer(ptrdiff_t __len) {
return __get_temporary_buffer(__len, (_Tp*) 0);
}
 
// 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.
typedef typename __type_traits<_Tp>::has_trivial_default_constructor
_Trivial;
 
__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
= typename iterator_traits<_ForwardIterator>::value_type
>
struct temporary_buffer : public _Temporary_buffer<_ForwardIterator, _Tp>
{
temporary_buffer(_ForwardIterator __first, _ForwardIterator __last)
: _Temporary_buffer<_ForwardIterator, _Tp>(__first, __last) {}
~temporary_buffer() {}
};
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_TEMPBUF_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_threads.h
0,0 → 1,512
/*
* 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.
 
// GCC extension begin
// In order to present a stable threading configuration, in all cases,
// gcc looks for it's own abstraction layer before all others. All
// modifications to this file are marked to allow easier importation of
// STL upgrades.
#if defined(__STL_GTHREADS)
#include "bits/gthr.h"
#else
// GCC extension end
#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
// GCC extension begin
#endif
// GCC extension end
 
namespace std
{
 
// 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
// GCC extension begin
#ifdef __STL_GTHREADS
__gthread_mutex_t _M_ref_count_lock;
_Refcount_Base(_RC_t __n) : _M_ref_count(__n)
{
#ifdef __GTHREAD_MUTEX_INIT
__gthread_mutex_t __tmp = __GTHREAD_MUTEX_INIT;
_M_ref_count_lock = __tmp;
#elif defined(__GTHREAD_MUTEX_INIT_FUNCTION)
__GTHREAD_MUTEX_INIT_FUNCTION (&_M_ref_count_lock);
#else
#error __GTHREAD_MUTEX_INIT or __GTHREAD_MUTEX_INIT_FUNCTION should be defined by gthr.h abstraction layer, report problem to libstdc++@gcc.gnu.org.
#endif
}
#else
// GCC extension end
# 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
// GCC extension begin
#endif
// GCC extension end
 
// GCC extension begin
#ifdef __STL_GTHREADS
void _M_incr() {
__gthread_mutex_lock(&_M_ref_count_lock);
++_M_ref_count;
__gthread_mutex_unlock(&_M_ref_count_lock);
}
_RC_t _M_decr() {
__gthread_mutex_lock(&_M_ref_count_lock);
volatile _RC_t __tmp = --_M_ref_count;
__gthread_mutex_unlock(&_M_ref_count_lock);
return __tmp;
}
#else
// GCC extension end
// _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
// GCC extension begin
#endif
// GCC extension end
};
 
// 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.
// GCC extension begin
#ifdef __STL_GTHREADS
// We don't provide an _Atomic_swap in this configuration. This only
// affects the use of ext/rope with threads. Someone could add this
// later, if required. You can start by cloning the __STL_PTHREADS
// path while making the obvious changes. Later it could be optimized
// to use the atomicity.h abstraction layer from libstdc++-v3.
#else
// GCC extension end
# 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
// GCC extension begin
#endif
// GCC extension end
 
// 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.
 
// Helper struct. This is a workaround for various compilers that don't
// handle static variables in inline functions properly.
template <int __inst>
struct _STL_mutex_spin {
enum { __low_max = 30, __high_max = 1000 };
// Low if we suspect uniprocessor, high for multiprocessor.
 
static unsigned __max;
static unsigned __last;
};
 
template <int __inst>
unsigned _STL_mutex_spin<__inst>::__max = _STL_mutex_spin<__inst>::__low_max;
 
template <int __inst>
unsigned _STL_mutex_spin<__inst>::__last = 0;
 
// GCC extension begin
#if defined(__STL_GTHREADS)
#if !defined(__GTHREAD_MUTEX_INIT) && defined(__GTHREAD_MUTEX_INIT_FUNCTION)
extern __gthread_mutex_t _GLIBCPP_mutex;
extern __gthread_mutex_t *_GLIBCPP_mutex_address;
extern __gthread_once_t _GLIBCPP_once;
extern void _GLIBCPP_mutex_init (void);
extern void _GLIBCPP_mutex_address_init (void);
#endif
#endif
// GCC extension end
 
struct _STL_mutex_lock
{
// GCC extension begin
#if defined(__STL_GTHREADS)
// The class must be statically initialized with __STL_MUTEX_INITIALIZER.
#if !defined(__GTHREAD_MUTEX_INIT) && defined(__GTHREAD_MUTEX_INIT_FUNCTION)
volatile int _M_init_flag;
__gthread_once_t _M_once;
#endif
__gthread_mutex_t _M_lock;
void _M_initialize() {
#ifdef __GTHREAD_MUTEX_INIT
// There should be no code in this path given the usage rules above.
#elif defined(__GTHREAD_MUTEX_INIT_FUNCTION)
if (_M_init_flag) return;
if (__gthread_once (&_GLIBCPP_once, _GLIBCPP_mutex_init) != 0
&& __gthread_active_p ())
abort ();
__gthread_mutex_lock (&_GLIBCPP_mutex);
if (!_M_init_flag) {
// Even though we have a global lock, we use __gthread_once to be
// absolutely certain the _M_lock mutex is only initialized once on
// multiprocessor systems.
_GLIBCPP_mutex_address = &_M_lock;
if (__gthread_once (&_M_once, _GLIBCPP_mutex_address_init) != 0
&& __gthread_active_p ())
abort ();
_M_init_flag = 1;
}
__gthread_mutex_unlock (&_GLIBCPP_mutex);
#endif
}
void _M_acquire_lock() {
#if !defined(__GTHREAD_MUTEX_INIT) && defined(__GTHREAD_MUTEX_INIT_FUNCTION)
if (!_M_init_flag) _M_initialize();
#endif
__gthread_mutex_lock(&_M_lock);
}
void _M_release_lock() {
#if !defined(__GTHREAD_MUTEX_INIT) && defined(__GTHREAD_MUTEX_INIT_FUNCTION)
if (!_M_init_flag) _M_initialize();
#endif
__gthread_mutex_unlock(&_M_lock);
}
#else
// GCC extension end
#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 = 1L << __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() {
volatile unsigned long* __lock = &this->_M_lock;
 
if (!_Atomic_swap((unsigned long*)__lock, 1)) {
return;
}
unsigned __my_spin_max = _STL_mutex_spin<0>::__max;
unsigned __my_last_spins = _STL_mutex_spin<0>::__last;
volatile unsigned __junk = 17; // Value doesn't matter.
unsigned __i;
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.
_STL_mutex_spin<0>::__last = __i;
_STL_mutex_spin<0>::__max = _STL_mutex_spin<0>::__high_max;
return;
}
}
// We are probably being scheduled against the other process. Sleep.
_STL_mutex_spin<0>::__max = _STL_mutex_spin<0>::__low_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
// GCC extension begin
#endif
// GCC extension end
};
 
// GCC extension begin
#if defined(__STL_GTHREADS)
#ifdef __GTHREAD_MUTEX_INIT
#define __STL_MUTEX_INITIALIZER = { __GTHREAD_MUTEX_INIT }
#elif defined(__GTHREAD_MUTEX_INIT_FUNCTION)
#ifdef __GTHREAD_MUTEX_INIT_DEFAULT
#define __STL_MUTEX_INITIALIZER \
= { 0, __GTHREAD_ONCE_INIT, __GTHREAD_MUTEX_INIT_DEFAULT }
#else
#define __STL_MUTEX_INITIALIZER = { 0, __GTHREAD_ONCE_INIT }
#endif
#endif
#else
// GCC extension end
#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
// GCC extension begin
#endif
// GCC extension end
 
 
// 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&);
};
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_THREADS_H */
 
// Local Variables:
// mode:C++
// End:
 
/contrib/media/updf/include/bits/stl_tree.h
0,0 → 1,1277
/*
*
* 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>
 
namespace std
{
 
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; }
pointer operator->() const { return &(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;
}
};
 
template <class _Value, class _Ref, class _Ptr>
inline bool operator==(const _Rb_tree_iterator<_Value, _Ref, _Ptr>& __x,
const _Rb_tree_iterator<_Value, _Ref, _Ptr>& __y) {
return __x._M_node == __y._M_node;
}
 
template <class _Value>
inline bool operator==(const _Rb_tree_iterator<_Value, const _Value&, const _Value*>& __x,
const _Rb_tree_iterator<_Value, _Value&, _Value*>& __y) {
return __x._M_node == __y._M_node;
}
 
template <class _Value>
inline bool operator==(const _Rb_tree_iterator<_Value, _Value&, _Value*>& __x,
const _Rb_tree_iterator<_Value, const _Value&, const _Value*>& __y) {
return __x._M_node == __y._M_node;
}
 
template <class _Value, class _Ref, class _Ptr>
inline bool operator!=(const _Rb_tree_iterator<_Value, _Ref, _Ptr>& __x,
const _Rb_tree_iterator<_Value, _Ref, _Ptr>& __y) {
return __x._M_node != __y._M_node;
}
 
template <class _Value>
inline bool operator!=(const _Rb_tree_iterator<_Value, const _Value&, const _Value*>& __x,
const _Rb_tree_iterator<_Value, _Value&, _Value*>& __y) {
return __x._M_node != __y._M_node;
}
 
template <class _Value>
inline bool operator!=(const _Rb_tree_iterator<_Value, _Value&, _Value*>& __x,
const _Rb_tree_iterator<_Value, const _Value&, const _Value*>& __y) {
return __x._M_node != __y._M_node;
}
 
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.
 
// _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); }
 
};
 
 
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:
using _Base::_M_get_node;
using _Base::_M_put_node;
using _Base::_M_header;
 
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;
 
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
 
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);
 
template <class _InputIterator>
void insert_unique(_InputIterator __first, _InputIterator __last);
template <class _InputIterator>
void insert_equal(_InputIterator __first, _InputIterator __last);
 
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());
}
 
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);
}
 
 
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);
}
}
 
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);
}
 
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() {}
};
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_TREE_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_uninitialized.h
0,0 → 1,282
/*
*
* 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>
 
namespace std
{
 
// 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));
}
 
} // namespace std
 
#endif /* _CPP_BITS_STL_UNINITIALIZED_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/stl_vector.h
0,0 → 1,727
/*
*
* 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/stl_iterator_base_funcs.h>
#include <bits/functexcept.h>
#include <bits/concept_check.h>
 
namespace std
{
 
// 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.
 
// 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); }
};
 
 
template <class _Tp, class _Alloc = allocator<_Tp> >
class vector : protected _Vector_base<_Tp, _Alloc>
{
// concept requirements
__glibcpp_class_requires(_Tp, _SGIAssignableConcept);
 
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(); }
 
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
 
protected:
using _Base::_M_allocate;
using _Base::_M_deallocate;
using _Base::_M_start;
using _Base::_M_finish;
using _Base::_M_end_of_storage;
 
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); }
 
void _M_range_check(size_type __n) const {
if (__n >= this->size())
__throw_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]; }
 
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); }
 
// 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));
}
 
~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);
 
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);
 
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;
}
// 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));
}
 
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:
 
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));
}
 
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);
};
 
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());
}
 
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);
}
 
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());
}
 
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);
}
}
 
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;
}
}
}
 
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;
}
}
}
 
} // namespace std
 
#endif /* __SGI_STL_INTERNAL_VECTOR_H */
 
// Local Variables:
// mode:C++
// End:
/contrib/media/updf/include/bits/streambuf.tcc
0,0 → 1,230
// Stream buffer classes -*- C++ -*-
 
// Copyright (C) 1997, 1998, 1999, 2000, 2001 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 __ret;
if (_M_in_cur && _M_in_cur < _M_in_end)
{
char_type __c = *gptr();
_M_in_cur_move(1);
__ret = traits_type::to_int_type(__c);
}
else
__ret = this->uflow();
return __ret;
}
 
template<typename _CharT, typename _Traits>
basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::
sputbackc(char_type __c)
{
int_type __ret;
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)
__ret = pbackfail(traits_type::to_int_type(__c));
else
{
_M_in_cur_move(-1);
__ret = traits_type::to_int_type(*this->gptr());
}
return __ret;
}
template<typename _CharT, typename _Traits>
basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::
sungetc()
{
int_type __ret;
if (_M_in_cur && _M_in_beg < _M_in_cur)
{
_M_in_cur_move(-1);
__ret = traits_type::to_int_type(*_M_in_cur);
}
else
__ret = this->pbackfail();
return __ret;
}
 
// 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 __ret;
if (_M_out_buf_size())
{
*_M_out_cur = __c;
_M_out_cur_move(1);
__ret = traits_type::to_int_type(__c);
}
else
__ret = this->overflow(traits_type::to_int_type(__c));
return __ret;
}
 
template<typename _CharT, typename _Traits>
streamsize
basic_streambuf<_CharT, _Traits>::
xsgetn(char_type* __s, streamsize __n)
{
streamsize __ret = 0;
while (__ret < __n)
{
size_t __buf_len = _M_in_end - _M_in_cur;
if (__buf_len > 0)
{
size_t __remaining = __n - __ret;
size_t __len = min(__buf_len, __remaining);
traits_type::copy(__s, _M_in_cur, __len);
__ret += __len;
__s += __len;
_M_in_cur_move(__len);
}
if (__ret < __n)
{
int_type __c = this->uflow();
if (__c != traits_type::eof())
{
traits_type::assign(*__s++, traits_type::to_char_type(__c));
++__ret;
}
else
break;
}
}
return __ret;
}
 
// 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 __ret = 0;
while (__ret < __n)
{
off_type __buf_len = _M_out_buf_size();
if (__buf_len > 0)
{
off_type __remaining = __n - __ret;
off_type __len = min(__buf_len, __remaining);
traits_type::copy(_M_out_cur, __s, __len);
__ret += __len;
__s += __len;
_M_out_cur_move(__len);
}
 
if (__ret < __n)
{
int_type __c = this->overflow(traits_type::to_int_type(*__s));
if (__c != traits_type::eof())
{
++__ret;
++__s;
}
else
break;
}
}
return __ret;
}
 
// 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>
streamsize
__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 __ret = 0;
streamsize __bufsize = __sbin->in_avail();
streamsize __xtrct;
bool __testput = __sbout->_M_mode & ios_base::out;
try {
while (__testput && __bufsize != -1)
{
__xtrct = __sbout->sputn(__sbin->gptr(), __bufsize);
__ret += __xtrct;
__sbin->_M_in_cur_move(__xtrct);
if (__xtrct == __bufsize)
{
int_type __c = __sbin->sgetc();
if (__c == _Traits::eof())
{
__ios.setstate(ios_base::eofbit);
break;
}
__bufsize = __sbin->in_avail();
}
else
break;
}
}
catch(exception& __fail) {
if ((__ios.exceptions() & ios_base::failbit) != 0)
__throw_exception_again;
}
return __ret;
}
} // namespace std
 
#endif // _CPP_BITS_STREAMBUF_TCC
 
/contrib/media/updf/include/bits/stringfwd.h
0,0 → 1,68
// String support -*- C++ -*-
 
// Copyright (C) 2001 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_STRINGFWD_H
#define _CPP_BITS_STRINGFWD_H 1
 
#pragma GCC system_header
 
#include <bits/c++config.h>
 
namespace std
{
template<class _CharT>
struct char_traits;
template<> class char_traits<char>;
#ifdef _GLIBCPP_USE_WCHAR_T
template<> class char_traits<wchar_t>;
#endif
 
template<typename _Alloc>
class allocator;
 
template<typename _CharT, typename _Traits = char_traits<_CharT>,
typename _Alloc = allocator<_CharT> >
class basic_string;
 
typedef basic_string<char> string;
#ifdef _GLIBCPP_USE_WCHAR_T
typedef basic_string<wchar_t> wstring;
#endif
} // namespace std
 
#endif // _CPP_BITS_STRINGFWD_H
 
// Local Variables:
// mode:c++
// End:
/contrib/media/updf/include/bits/type_traits.h
0,0 → 1,314
/*
*
* 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
 
#pragma GCC system_header
 
#include <bits/c++config.h>
 
/*
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.
 
template<> 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;
};
 
template<> 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;
};
 
template<> 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;
};
 
template<> 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;
};
 
template<> 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;
};
 
template<> 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;
};
 
template<> 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;
};
 
template<> 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;
};
 
template<> 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;
};
 
template<> 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;
};
 
template<> 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 _GLIBCPP_USE_LONG_LONG
 
template<> 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;
};
 
template<> 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 /* _GLIBCPP_USE_LONG_LONG */
 
template<> 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;
};
 
template<> 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;
};
 
template<> 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;
};
 
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;
};
 
 
// 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;
};
 
template<> struct _Is_integer<bool> {
typedef __true_type _Integral;
};
 
template<> struct _Is_integer<char> {
typedef __true_type _Integral;
};
 
template<> struct _Is_integer<signed char> {
typedef __true_type _Integral;
};
 
template<> struct _Is_integer<unsigned char> {
typedef __true_type _Integral;
};
 
template<> struct _Is_integer<wchar_t> {
typedef __true_type _Integral;
};
 
template<> struct _Is_integer<short> {
typedef __true_type _Integral;
};
 
template<> struct _Is_integer<unsigned short> {
typedef __true_type _Integral;
};
 
template<> struct _Is_integer<int> {
typedef __true_type _Integral;
};
 
template<> struct _Is_integer<unsigned int> {
typedef __true_type _Integral;
};
 
template<> struct _Is_integer<long> {
typedef __true_type _Integral;
};
 
template<> struct _Is_integer<unsigned long> {
typedef __true_type _Integral;
};
 
#ifdef _GLIBCPP_USE_LONG_LONG
 
template<> struct _Is_integer<long long> {
typedef __true_type _Integral;
};
 
template<> struct _Is_integer<unsigned long long> {
typedef __true_type _Integral;
};
 
#endif /* _GLIBCPP_USE_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:
/contrib/media/updf/include/bits/valarray_array.h
0,0 → 1,577
// 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
 
#pragma GCC system_header
 
#include <bits/c++config.h>
#include <bits/cpp_type_traits.h>
#include <bits/std_cstdlib.h>
#include <bits/std_cstring.h>
#include <new>
 
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); }
template<typename _Tp>
inline _Tp*__restrict__
__valarray_get_storage(size_t __n)
{
return static_cast<_Tp*__restrict__>
(__valarray_get_memory(__n * sizeof(_Tp)));
}
 
// 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)*sizeof(_Tp)); }
};
 
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)*sizeof(_Tp)); }
};
 
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>
inline _Tp
__valarray_product(const _Tp* __restrict__ __f,
const _Tp* __restrict__ __l)
{
_Tp __r = _Tp(1);
while (__f != __l) __r = __r * *__f++;
return __r;
}
 
// Compute the min/max of an array-expression
template<typename _Ta>
inline typename _Ta::value_type
__valarray_min(const _Ta& __a)
{
size_t __s = __a.size();
typedef typename _Ta::value_type _Value_type;
_Value_type __r = __s == 0 ? _Value_type() : __a[0];
for (size_t __i = 1; __i < __s; ++__i)
{
_Value_type __t = __a[__i];
if (__t < __r)
__r = __t;
}
return __r;
}
template<typename _Ta>
inline typename _Ta::value_type
__valarray_max(const _Ta& __a)
{
size_t __s = __a.size();
typedef typename _Ta::value_type _Value_type;
_Value_type __r = __s == 0 ? _Value_type() : __a[0];
for (size_t __i = 1; __i < __s; ++__i)
{
_Value_type __t = __a[__i];
if (__t > __r)
__r = __t;
}
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_storage<_Tp>(__n))
{ __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_storage<_Tp>(__s))
{ __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:
/contrib/media/updf/include/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:
/contrib/media/updf/include/bits/valarray_meta.h
0,0 → 1,1070
// The template and inlines for the -*- C++ -*- internal _Meta class.
 
// Copyright (C) 1997-1999, 2000, 2001 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
 
#pragma GCC system_header
 
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 (__v, __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;
 
value_type min() const;
value_type max() const;
 
valarray<value_type> apply(value_type (*) (const value_type&)) const;
valarray<value_type> apply(value_type (*) (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 (); }
 
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::shift(int __n) const
{ return valarray<_Tp>(_M_closure).shift(__n); }
 
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::cshift(int __n) const
{ return valarray<_Tp>(_M_closure).cshift(__n); }
 
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::apply(_Tp __f(const _Tp&)) const
{ return valarray<_Tp>(_M_closure).apply(__f); }
template<class _Clos, typename _Tp>
inline valarray<_Tp>
_Expr<_Clos, _Tp>::apply(_Tp __f(_Tp)) const
{ return valarray<_Tp>(_M_closure).apply(__f); }
 
// 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 _Clos, typename _Tp>
inline _Tp
_Expr<_Clos, _Tp>::min() const
{ return __valarray_min(_M_closure); }
 
template<class _Clos, typename _Tp>
inline _Tp
_Expr<_Clos, _Tp>::max() const
{ return __valarray_max(_M_closure); }
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:
/contrib/media/updf/include/bits/wchar.h
0,0 → 1,26
/* wchar_t type related definitions.
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
 
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
 
The GNU C 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
Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
 
#ifndef _BITS_WCHAR_H
#define _BITS_WCHAR_H 1
 
#define __WCHAR_MIN (-2147483647l - 1l)
#define __WCHAR_MAX (2147483647l)
 
#endif /* bits/wchar.h */
/contrib/media/updf/include/bits/wordsize.h
0,0 → 1,19
/* Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
 
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
 
The GNU C 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
Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
 
#define __WORDSIZE 32