Commit 54a3a087 by Benjamin Kosnik Committed by Benjamin Kosnik

Update to SGI STL 3.3


2000-06-27  Benjamin Kosnik  <bkoz@purist.soma.redhat.com>

	Update to SGI STL 3.3
	* ext/hash_map, ext/hash_set, ext/slist, ext/stl_bvector.h,
	ext/stl_rope.h, ext/ropeimpl.h: Update.
	* bits/std_bitset.h, bits/std_map, bits/std_memory.h,
	bits/stl_algo.h, bits/stl_algobase.h, bits/stl_alloc.h,
	bits/stl_config.h, bits/stl_construct.h, bits/stl_deque.h,
	bits/stl_function.h, bits/stl_heap.h, bits/stl_iterator.h,
	bits/stl_iterator_base.h, bits/stl_list.h, bits/stl_map.h,
	bits/stl_multimap.h, bits/stl_multiset.h, bits/stl_numeric.h,
	bits/stl_queue.h, bits/stl_set.h, bits/stl_stack.h,
	bits/stl_string_fwd.h, bits/stl_threads.h, bits/stl_three.h,
	bits/stl_uninitialized.h, bits/stl_vectory.h: Update.

	* src/Makefile.am (headers): Add new files.
	* src/Makefile.in: Regenerate.
	* src/stl-inst.cc (std): Add instantiation for __sink_unused_warning.
	* bits/concept_checks.h: New file.
	* bits/container_concepts.h: New file.
	* bits/sequence_concepts.h: New file.

From-SVN: r34743
parent adae082f
2000-06-26 Benjamin Kosnik <bkoz@purist.soma.redhat.com> 2000-06-27 Benjamin Kosnik <bkoz@purist.soma.redhat.com>
Update to SGI STL 3.3 Update to SGI STL 3.3
* bits/stl_algo.h: Update. * ext/hash_map, ext/hash_set, ext/slist, ext/stl_bvector.h,
* ext/ropeimpl.h: Update. ext/stl_rope.h, ext/ropeimpl.h: Update.
* bits/std_memory.h: Update. * bits/std_bitset.h, bits/std_map, bits/std_memory.h,
* bits/std_bitset.h: Update. bits/stl_algo.h, bits/stl_algobase.h, bits/stl_alloc.h,
bits/stl_config.h, bits/stl_construct.h, bits/stl_deque.h,
bits/stl_function.h, bits/stl_heap.h, bits/stl_iterator.h,
bits/stl_iterator_base.h, bits/stl_list.h, bits/stl_map.h,
bits/stl_multimap.h, bits/stl_multiset.h, bits/stl_numeric.h,
bits/stl_queue.h, bits/stl_set.h, bits/stl_stack.h,
bits/stl_string_fwd.h, bits/stl_threads.h, bits/stl_three.h,
bits/stl_uninitialized.h, bits/stl_vectory.h: Update.
* src/Makefile.am (headers): Add new files. * src/Makefile.am (headers): Add new files.
* src/Makefile.in: Regenerate. * src/Makefile.in: Regenerate.
* src/stl-inst.cc (std): Add instantiation for __sink_unused_warning.
* bits/concept_checks.h: New file. * bits/concept_checks.h: New file.
* bits/container_concepts.h: New file. * bits/container_concepts.h: New file.
* bits/sequence_concepts.h: New file. * bits/sequence_concepts.h: New file.
* src/stl-inst.cc (std): Add instantiation for __sink_unused_warning.
2000-06-27 H.J. Lu <hjl@gnu.org> 2000-06-27 H.J. Lu <hjl@gnu.org>
Loren J. Rittle <ljrittle@acm.org> Loren J. Rittle <ljrittle@acm.org>
......
...@@ -9,22 +9,17 @@ ...@@ -9,22 +9,17 @@
* in supporting documentation. Silicon Graphics makes no * in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any * representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty. * purpose. It is provided "as is" without express or implied warranty.
*/ */
#ifndef _CPP_BITSET #ifndef __SGI_STL_BITSET
#define _CPP_BITSET 1 #define __SGI_STL_BITSET
// This implementation of bitset<> has a second template parameter, // A bitset of size N has N % (sizeof(unsigned long) * CHAR_BIT) unused
// _WordT, which defaults to unsigned long. *YOU SHOULD NOT USE // bits. (They are the high- order bits in the highest word.) It is
// THIS FEATURE*. It is experimental, and it may be removed in // a class invariant of class bitset<> that those unused bits are
// future releases. // always zero.
// A bitset of size N, using words of type _WordT, will have // Most of the actual code isn't contained in bitset<> itself, but in the
// N % (sizeof(_WordT) * CHAR_BIT) unused bits. (They are the high-
// order bits in the highest word.) It is a class invariant
// of class bitset<> that those unused bits are always zero.
// Most of the actual code isn't contained in bitset<> itself, but in the
// base class _Base_bitset. The base class works with whole words, not with // base class _Base_bitset. The base class works with whole words, not with
// individual bits. This allows us to specialize _Base_bitset for the // individual bits. This allows us to specialize _Base_bitset for the
// important special case where the bitset is only a single word. // important special case where the bitset is only a single word.
...@@ -36,15 +31,20 @@ ...@@ -36,15 +31,20 @@
#include <bits/std_cstddef.h> // for size_t #include <bits/std_cstddef.h> // for size_t
#include <bits/std_cstring.h> // for memset
#include <bits/std_string.h> #include <bits/std_string.h>
#include <bits/std_stdexcept.h> #include <bits/std_stdexcept.h> // for invalid_argument, out_of_range,
#include <bits/std_istream.h> // overflow_error
#include <bits/std_ostream.h>
#include <bits/std_algorithm.h> #ifdef __STL_USE_NEW_IOSTREAMS
#include <iostream>
#else
#include <bits/std_iostream.h> // for istream, ostream
#endif
#define __BITS_PER_WORDT(__wt) (CHAR_BIT*sizeof(__wt)) #define __BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
#define __BITSET_WORDS(__n,__wt) \ #define __BITSET_WORDS(__n) \
((__n) < 1 ? 1 : ((__n) + __BITS_PER_WORDT(__wt) - 1)/__BITS_PER_WORDT(__wt)) ((__n) < 1 ? 1 : ((__n) + __BITS_PER_WORD - 1)/__BITS_PER_WORD)
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
...@@ -53,14 +53,14 @@ __STL_BEGIN_NAMESPACE ...@@ -53,14 +53,14 @@ __STL_BEGIN_NAMESPACE
#endif #endif
// structure to aid in counting bits // structure to aid in counting bits
template<bool __dummy> template<bool __dummy>
struct _Bit_count { struct _Bit_count {
static unsigned char _S_bit_count[256]; static unsigned char _S_bit_count[256];
}; };
// Mapping from 8 bit unsigned integers to the index of the first one // Mapping from 8 bit unsigned integers to the index of the first one
// bit: // bit:
template<bool __dummy> template<bool __dummy>
struct _First_one { struct _First_one {
static unsigned char _S_first_one[256]; static unsigned char _S_first_one[256];
}; };
...@@ -69,53 +69,52 @@ struct _First_one { ...@@ -69,53 +69,52 @@ struct _First_one {
// Base class: general case. // Base class: general case.
// //
template<size_t _Nw, class _WordT> template<size_t _Nw>
struct _Base_bitset { struct _Base_bitset {
typedef unsigned long _WordT;
_WordT _M_w[_Nw]; // 0 is the least significant word. _WordT _M_w[_Nw]; // 0 is the least significant word.
_Base_bitset( void ) { _M_do_reset(); } _Base_bitset( void ) { _M_do_reset(); }
_Base_bitset(unsigned long __val) {
_Base_bitset(unsigned long __val); _M_do_reset();
_M_w[0] = __val;
static size_t _S_whichword( size_t __pos ) {
return __pos / __BITS_PER_WORDT(_WordT);
}
static size_t _S_whichbyte( size_t __pos ) {
return (__pos % __BITS_PER_WORDT(_WordT)) / CHAR_BIT;
}
static size_t _S_whichbit( size_t __pos ) {
return __pos % __BITS_PER_WORDT(_WordT);
}
static _WordT _S_maskbit( size_t __pos ) {
return (static_cast<_WordT>(1)) << _S_whichbit(__pos);
} }
static size_t _S_whichword( size_t __pos )
{ return __pos / __BITS_PER_WORD; }
static size_t _S_whichbyte( size_t __pos )
{ return (__pos % __BITS_PER_WORD) / CHAR_BIT; }
static size_t _S_whichbit( size_t __pos )
{ return __pos % __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) { return _M_w[_S_whichword(__pos)]; }
_WordT _M_getword(size_t __pos) const { 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() { return _M_w[_Nw - 1]; }
_WordT _M_hiword() const { return _M_w[_Nw - 1]; } _WordT _M_hiword() const { return _M_w[_Nw - 1]; }
void _M_do_and(const _Base_bitset<_Nw,_WordT>& __x) { void _M_do_and(const _Base_bitset<_Nw>& __x) {
for ( size_t __i = 0; __i < _Nw; __i++ ) { for ( size_t __i = 0; __i < _Nw; __i++ ) {
_M_w[__i] &= __x._M_w[__i]; _M_w[__i] &= __x._M_w[__i];
} }
} }
void _M_do_or(const _Base_bitset<_Nw,_WordT>& __x) { void _M_do_or(const _Base_bitset<_Nw>& __x) {
for ( size_t __i = 0; __i < _Nw; __i++ ) { for ( size_t __i = 0; __i < _Nw; __i++ ) {
_M_w[__i] |= __x._M_w[__i]; _M_w[__i] |= __x._M_w[__i];
} }
} }
void _M_do_xor(const _Base_bitset<_Nw,_WordT>& __x) { void _M_do_xor(const _Base_bitset<_Nw>& __x) {
for ( size_t __i = 0; __i < _Nw; __i++ ) { for ( size_t __i = 0; __i < _Nw; __i++ ) {
_M_w[__i] ^= __x._M_w[__i]; _M_w[__i] ^= __x._M_w[__i];
} }
} }
void _M_do_left_shift(size_t __shift); void _M_do_left_shift(size_t __shift);
void _M_do_right_shift(size_t __shift); void _M_do_right_shift(size_t __shift);
void _M_do_flip() { void _M_do_flip() {
...@@ -130,13 +129,9 @@ struct _Base_bitset { ...@@ -130,13 +129,9 @@ struct _Base_bitset {
} }
} }
void _M_do_reset() { void _M_do_reset() { memset(_M_w, 0, _Nw * sizeof(_WordT)); }
for ( size_t __i = 0; __i < _Nw; __i++ ) {
_M_w[__i] = 0;
}
}
bool _M_is_equal(const _Base_bitset<_Nw,_WordT>& __x) const { bool _M_is_equal(const _Base_bitset<_Nw>& __x) const {
for (size_t __i = 0; __i < _Nw; ++__i) { for (size_t __i = 0; __i < _Nw; ++__i) {
if (_M_w[__i] != __x._M_w[__i]) if (_M_w[__i] != __x._M_w[__i])
return false; return false;
...@@ -145,7 +140,7 @@ struct _Base_bitset { ...@@ -145,7 +140,7 @@ struct _Base_bitset {
} }
bool _M_is_any() const { bool _M_is_any() const {
for ( size_t __i = 0; __i < __BITSET_WORDS(_Nw,_WordT); __i++ ) { for ( size_t __i = 0; __i < _Nw; __i++ ) {
if ( _M_w[__i] != static_cast<_WordT>(0) ) if ( _M_w[__i] != static_cast<_WordT>(0) )
return true; return true;
} }
...@@ -164,7 +159,7 @@ struct _Base_bitset { ...@@ -164,7 +159,7 @@ struct _Base_bitset {
return __result; return __result;
} }
unsigned long _M_do_to_ulong() const; unsigned long _M_do_to_ulong() const;
// find first "on" bit // find first "on" bit
size_t _M_do_find_first(size_t __not_found) const; size_t _M_do_find_first(size_t __not_found) const;
...@@ -175,107 +170,67 @@ struct _Base_bitset { ...@@ -175,107 +170,67 @@ struct _Base_bitset {
// //
// Definitions of non-inline functions from _Base_bitset. // Definitions of non-inline functions from _Base_bitset.
// //
template<size_t _Nw, class _WordT> template<size_t _Nw>
_Base_bitset<_Nw, _WordT>::_Base_bitset(unsigned long __val) void _Base_bitset<_Nw>::_M_do_left_shift(size_t __shift)
{
_M_do_reset();
const size_t __n = min(sizeof(unsigned long)*CHAR_BIT,
__BITS_PER_WORDT(_WordT)*_Nw);
for(size_t __i = 0; __i < __n; ++__i, __val >>= 1)
if ( __val & 0x1 )
_M_getword(__i) |= _S_maskbit(__i);
}
template<size_t _Nw, class _WordT>
void _Base_bitset<_Nw, _WordT>::_M_do_left_shift(size_t __shift)
{ {
if (__shift != 0) { if (__shift != 0) {
const size_t __wshift = __shift / __BITS_PER_WORDT(_WordT); const size_t __wshift = __shift / __BITS_PER_WORD;
const size_t __offset = __shift % __BITS_PER_WORDT(_WordT); const size_t __offset = __shift % __BITS_PER_WORD;
const size_t __sub_offset = __BITS_PER_WORDT(_WordT) - __offset;
const _WordT __mask = __offset == static_cast<size_t>(0) ? if (__offset == 0)
static_cast<_WordT>(0) : for (size_t __n = _Nw - 1; __n >= __wshift; --__n)
~static_cast<_WordT>(0); _M_w[__n] = _M_w[__n - __wshift];
size_t __n = _Nw - 1;
for ( ; __n > __wshift; --__n) else {
_M_w[__n] = (_M_w[__n - __wshift] << __offset) | const size_t __sub_offset = __BITS_PER_WORD - __offset;
((_M_w[__n - __wshift - 1] >> __sub_offset) & __mask); for (size_t __n = _Nw - 1; __n > __wshift; --__n)
if (__n == __wshift) _M_w[__n] = (_M_w[__n - __wshift] << __offset) |
_M_w[__n] = _M_w[0] << __offset; (_M_w[__n - __wshift - 1] >> __sub_offset);
for (size_t __n1 = 0; __n1 < __n; ++__n1) _M_w[__wshift] = _M_w[0] << __offset;
_M_w[__n1] = static_cast<_WordT>(0); }
fill(_M_w + 0, _M_w + __wshift, static_cast<_WordT>(0));
} }
} }
template<size_t _Nw, class _WordT> template<size_t _Nw>
void _Base_bitset<_Nw, _WordT>::_M_do_right_shift(size_t __shift) void _Base_bitset<_Nw>::_M_do_right_shift(size_t __shift)
{ {
if (__shift != 0) { if (__shift != 0) {
const size_t __wshift = __shift / __BITS_PER_WORDT(_WordT); const size_t __wshift = __shift / __BITS_PER_WORD;
const size_t __offset = __shift % __BITS_PER_WORDT(_WordT); const size_t __offset = __shift % __BITS_PER_WORD;
const size_t __sub_offset = __BITS_PER_WORDT(_WordT) - __offset;
const _WordT __mask = __offset == static_cast<size_t>(0) ?
static_cast<_WordT>(0) :
~static_cast<_WordT>(0);
const size_t __limit = _Nw - __wshift - 1; const size_t __limit = _Nw - __wshift - 1;
size_t __n = 0;
for ( ; __n < __limit; ++__n)
_M_w[__n] = (_M_w[__n + __wshift] >> __offset) |
((_M_w[__n + __wshift + 1] << __sub_offset) & __mask);
_M_w[__limit] = _M_w[_Nw-1] >> __offset;
for (size_t __n1 = __limit + 1; __n1 < _Nw; ++__n1)
_M_w[__n1] = static_cast<_WordT>(0);
}
}
template<size_t _Nw, class _WordT> if (__offset == 0)
unsigned long _Base_bitset<_Nw, _WordT>::_M_do_to_ulong() const for (size_t __n = 0; __n <= __limit; ++__n)
{ _M_w[__n] = _M_w[__n + __wshift];
if (sizeof(_WordT) >= sizeof(unsigned long)) {
for (size_t __i = 1; __i < _Nw; ++__i)
if (_M_w[__i])
__STL_THROW(overflow_error("bitset"));
const _WordT __mask = static_cast<_WordT>(static_cast<unsigned long>(-1));
if (_M_w[0] & ~__mask)
__STL_THROW(overflow_error("bitset"));
return static_cast<unsigned long>(_M_w[0] & __mask); else {
} const size_t __sub_offset = __BITS_PER_WORD - __offset;
else { // sizeof(_WordT) < sizeof(unsigned long). for (size_t __n = 0; __n < __limit; ++__n)
const size_t __nwords = _M_w[__n] = (_M_w[__n + __wshift] >> __offset) |
(sizeof(unsigned long) + sizeof(_WordT) - 1) / sizeof(_WordT); (_M_w[__n + __wshift + 1] << __sub_offset);
_M_w[__limit] = _M_w[_Nw-1] >> __offset;
size_t __min_nwords = __nwords;
if (_Nw > __nwords) {
for (size_t __i = __nwords; __i < _Nw; ++__i)
if (_M_w[__i])
__STL_THROW(overflow_error("bitset"));
} }
else
__min_nwords = _Nw;
// If unsigned long is 8 bytes and _WordT is 6 bytes, then an unsigned fill(_M_w + __limit + 1, _M_w + _Nw, static_cast<_WordT>(0));
// long consists of all of one word plus 2 bytes from another word. }
const size_t __part = sizeof(unsigned long) % sizeof(_WordT); }
if (__part != 0 && __nwords <= _Nw && template<size_t _Nw>
(_M_w[__min_nwords - 1] >> ((sizeof(_WordT) - __part) * CHAR_BIT)) != 0) 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")); __STL_THROW(overflow_error("bitset"));
return _M_w[0];
}
unsigned long __result = 0; template<size_t _Nw>
for (size_t __i = 0; __i < __min_nwords; ++__i) { size_t _Base_bitset<_Nw>::_M_do_find_first(size_t __not_found) const
__result |= static_cast<unsigned long>(
_M_w[__i]) << (__i * sizeof(_WordT) * CHAR_BIT);
}
return __result;
}
} // End _M_do_to_ulong
template<size_t _Nw, class _WordT>
size_t _Base_bitset<_Nw, _WordT>::_M_do_find_first(size_t __not_found) const
{ {
for ( size_t __i = 0; __i < _Nw; __i++ ) { for ( size_t __i = 0; __i < _Nw; __i++ ) {
_WordT __thisword = _M_w[__i]; _WordT __thisword = _M_w[__i];
...@@ -285,7 +240,7 @@ size_t _Base_bitset<_Nw, _WordT>::_M_do_find_first(size_t __not_found) const ...@@ -285,7 +240,7 @@ size_t _Base_bitset<_Nw, _WordT>::_M_do_find_first(size_t __not_found) const
unsigned char __this_byte unsigned char __this_byte
= static_cast<unsigned char>(__thisword & (~(unsigned char)0)); = static_cast<unsigned char>(__thisword & (~(unsigned char)0));
if ( __this_byte ) if ( __this_byte )
return __i*__BITS_PER_WORDT(_WordT) + __j*CHAR_BIT + return __i*__BITS_PER_WORD + __j*CHAR_BIT +
_First_one<true>::_S_first_one[__this_byte]; _First_one<true>::_S_first_one[__this_byte];
__thisword >>= CHAR_BIT; __thisword >>= CHAR_BIT;
...@@ -296,16 +251,15 @@ size_t _Base_bitset<_Nw, _WordT>::_M_do_find_first(size_t __not_found) const ...@@ -296,16 +251,15 @@ size_t _Base_bitset<_Nw, _WordT>::_M_do_find_first(size_t __not_found) const
return __not_found; return __not_found;
} }
template<size_t _Nw, class _WordT> template<size_t _Nw>
size_t size_t
_Base_bitset<_Nw, _WordT>::_M_do_find_next(size_t __prev, _Base_bitset<_Nw>::_M_do_find_next(size_t __prev, size_t __not_found) const
size_t __not_found) const
{ {
// make bound inclusive // make bound inclusive
++__prev; ++__prev;
// check out of bounds // check out of bounds
if ( __prev >= _Nw * __BITS_PER_WORDT(_WordT) ) if ( __prev >= _Nw * __BITS_PER_WORD )
return __not_found; return __not_found;
// search first word // search first word
...@@ -323,7 +277,7 @@ _Base_bitset<_Nw, _WordT>::_M_do_find_next(size_t __prev, ...@@ -323,7 +277,7 @@ _Base_bitset<_Nw, _WordT>::_M_do_find_next(size_t __prev,
unsigned char __this_byte unsigned char __this_byte
= static_cast<unsigned char>(__thisword & (~(unsigned char)0)); = static_cast<unsigned char>(__thisword & (~(unsigned char)0));
if ( __this_byte ) if ( __this_byte )
return __i*__BITS_PER_WORDT(_WordT) + __j*CHAR_BIT + return __i*__BITS_PER_WORD + __j*CHAR_BIT +
_First_one<true>::_S_first_one[__this_byte]; _First_one<true>::_S_first_one[__this_byte];
__thisword >>= CHAR_BIT; __thisword >>= CHAR_BIT;
...@@ -340,7 +294,7 @@ _Base_bitset<_Nw, _WordT>::_M_do_find_next(size_t __prev, ...@@ -340,7 +294,7 @@ _Base_bitset<_Nw, _WordT>::_M_do_find_next(size_t __prev,
unsigned char __this_byte unsigned char __this_byte
= static_cast<unsigned char>(__thisword & (~(unsigned char)0)); = static_cast<unsigned char>(__thisword & (~(unsigned char)0));
if ( __this_byte ) if ( __this_byte )
return __i*__BITS_PER_WORDT(_WordT) + __j*CHAR_BIT + return __i*__BITS_PER_WORD + __j*CHAR_BIT +
_First_one<true>::_S_first_one[__this_byte]; _First_one<true>::_S_first_one[__this_byte];
__thisword >>= CHAR_BIT; __thisword >>= CHAR_BIT;
...@@ -359,28 +313,21 @@ _Base_bitset<_Nw, _WordT>::_M_do_find_next(size_t __prev, ...@@ -359,28 +313,21 @@ _Base_bitset<_Nw, _WordT>::_M_do_find_next(size_t __prev,
// Base class: specialization for a single word. // Base class: specialization for a single word.
// //
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION __STL_TEMPLATE_NULL struct _Base_bitset<1> {
typedef unsigned long _WordT;
template<class _WordT>
struct _Base_bitset<1, _WordT> {
_WordT _M_w; _WordT _M_w;
_Base_bitset( void ) { _M_do_reset(); } _Base_bitset( void ) : _M_w(0) {}
_Base_bitset(unsigned long __val) : _M_w(__val) {}
_Base_bitset(unsigned long __val); static size_t _S_whichword( size_t __pos )
{ return __pos / __BITS_PER_WORD; }
static size_t _S_whichword( size_t __pos ) { static size_t _S_whichbyte( size_t __pos )
return __pos / __BITS_PER_WORDT(_WordT); { return (__pos % __BITS_PER_WORD) / CHAR_BIT; }
} static size_t _S_whichbit( size_t __pos )
static size_t _S_whichbyte( size_t __pos ) { { return __pos % __BITS_PER_WORD; }
return (__pos % __BITS_PER_WORDT(_WordT)) / CHAR_BIT; static _WordT _S_maskbit( size_t __pos )
} { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
static size_t _S_whichbit( size_t __pos ) {
return __pos % __BITS_PER_WORDT(_WordT);
}
static _WordT _S_maskbit( size_t __pos ) {
return (static_cast<_WordT>(1)) << _S_whichbit(__pos);
}
_WordT& _M_getword(size_t) { return _M_w; } _WordT& _M_getword(size_t) { return _M_w; }
_WordT _M_getword(size_t) const { return _M_w; } _WordT _M_getword(size_t) const { return _M_w; }
...@@ -388,26 +335,25 @@ struct _Base_bitset<1, _WordT> { ...@@ -388,26 +335,25 @@ struct _Base_bitset<1, _WordT> {
_WordT& _M_hiword() { return _M_w; } _WordT& _M_hiword() { return _M_w; }
_WordT _M_hiword() const { return _M_w; } _WordT _M_hiword() const { return _M_w; }
void _M_do_and(const _Base_bitset<1,_WordT>& __x) { _M_w &= __x._M_w; } void _M_do_and(const _Base_bitset<1>& __x) { _M_w &= __x._M_w; }
void _M_do_or(const _Base_bitset<1,_WordT>& __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,_WordT>& __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_left_shift(size_t __shift) { _M_w <<= __shift; }
void _M_do_right_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_flip() { _M_w = ~_M_w; }
void _M_do_set() { _M_w = ~static_cast<_WordT>(0); } void _M_do_set() { _M_w = ~static_cast<_WordT>(0); }
void _M_do_reset() { _M_w = 0; } void _M_do_reset() { _M_w = 0; }
bool _M_is_equal(const _Base_bitset<1,_WordT>& __x) const { bool _M_is_equal(const _Base_bitset<1>& __x) const
return _M_w == __x._M_w; { return _M_w == __x._M_w; }
} bool _M_is_any() const
bool _M_is_any() const { { return _M_w != 0; }
return _M_w != 0;
}
size_t _M_do_count() const { size_t _M_do_count() const {
size_t __result = 0; size_t __result = 0;
const unsigned char* __byte_ptr = (const unsigned char*)&_M_w; const unsigned char* __byte_ptr = (const unsigned char*)&_M_w;
const unsigned char* __end_ptr = ((const unsigned char*)&_M_w)+sizeof(_M_w); const unsigned char* __end_ptr
= ((const unsigned char*)&_M_w)+sizeof(_M_w);
while ( __byte_ptr < __end_ptr ) { while ( __byte_ptr < __end_ptr ) {
__result += _Bit_count<true>::_S_bit_count[*__byte_ptr]; __result += _Bit_count<true>::_S_bit_count[*__byte_ptr];
__byte_ptr++; __byte_ptr++;
...@@ -415,21 +361,12 @@ struct _Base_bitset<1, _WordT> { ...@@ -415,21 +361,12 @@ struct _Base_bitset<1, _WordT> {
return __result; return __result;
} }
unsigned long _M_do_to_ulong() const { unsigned long _M_do_to_ulong() const { return _M_w; }
if (sizeof(_WordT) <= sizeof(unsigned long))
return static_cast<unsigned long>(_M_w);
else {
const _WordT __mask = static_cast<_WordT>(static_cast<unsigned long>(-1));
if (_M_w & ~__mask)
__STL_THROW(overflow_error("bitset"));
return static_cast<unsigned long>(_M_w);
}
}
size_t _M_do_find_first(size_t __not_found) const; size_t _M_do_find_first(size_t __not_found) const;
// find the next "on" bit that follows "prev" // find the next "on" bit that follows "prev"
size_t _M_do_find_next(size_t __prev, size_t __not_found) const; size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
}; };
...@@ -438,19 +375,7 @@ struct _Base_bitset<1, _WordT> { ...@@ -438,19 +375,7 @@ struct _Base_bitset<1, _WordT> {
// _Base_bitset. // _Base_bitset.
// //
template <class _WordT> size_t _Base_bitset<1>::_M_do_find_first(size_t __not_found) const
_Base_bitset<1, _WordT>::_Base_bitset(unsigned long __val)
{
_M_do_reset();
const size_t __n = min(sizeof(unsigned long)*CHAR_BIT,
__BITS_PER_WORDT(_WordT)*_Nw);
for(size_t __i = 0; __i < __n; ++__i, __val >>= 1)
if ( __val & 0x1 )
_M_w |= _S_maskbit(__i);
}
template <class _WordT>
size_t _Base_bitset<1, _WordT>::_M_do_find_first(size_t __not_found) const
{ {
_WordT __thisword = _M_w; _WordT __thisword = _M_w;
...@@ -469,16 +394,13 @@ size_t _Base_bitset<1, _WordT>::_M_do_find_first(size_t __not_found) const ...@@ -469,16 +394,13 @@ size_t _Base_bitset<1, _WordT>::_M_do_find_first(size_t __not_found) const
return __not_found; return __not_found;
} }
template <class _WordT> size_t _Base_bitset<1>::_M_do_find_next(size_t __prev, size_t __not_found ) const
size_t
_Base_bitset<1, _WordT>::_M_do_find_next(size_t __prev,
size_t __not_found ) const
{ {
// make bound inclusive // make bound inclusive
++__prev; ++__prev;
// check out of bounds // check out of bounds
if ( __prev >= __BITS_PER_WORDT(_WordT) ) if ( __prev >= __BITS_PER_WORD )
return __not_found; return __not_found;
// search first (and only) word // search first (and only) word
...@@ -505,89 +427,35 @@ _Base_bitset<1, _WordT>::_M_do_find_next(size_t __prev, ...@@ -505,89 +427,35 @@ _Base_bitset<1, _WordT>::_M_do_find_next(size_t __prev,
return __not_found; return __not_found;
} // end _M_do_find_next } // end _M_do_find_next
//
// One last specialization: _M_do_to_ulong() and the constructor from
// unsigned long are very simple if the bitset consists of a single
// word of type unsigned long.
//
__STL_TEMPLATE_NULL
inline unsigned long
_Base_bitset<1, unsigned long>::_M_do_to_ulong() const { return _M_w; }
__STL_TEMPLATE_NULL
inline _Base_bitset<1, unsigned long>::_Base_bitset(unsigned long __val) {
_M_w = __val;
}
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
// ------------------------------------------------------------ // ------------------------------------------------------------
// Helper class to zero out the unused high-order bits in the highest word. // Helper class to zero out the unused high-order bits in the highest word.
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION template <size_t _Extrabits> struct _Sanitize {
static void _M_do_sanitize(unsigned long& __val)
template <class _WordT, size_t _Extrabits> struct _Sanitize { { __val &= ~((~static_cast<unsigned long>(0)) << _Extrabits); }
static void _M_do_sanitize(_WordT& __val)
{ __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
}; };
template <class _WordT> struct _Sanitize<_WordT, 0> { __STL_TEMPLATE_NULL struct _Sanitize<0> {
static void _M_do_sanitize(_WordT) {} static void _M_do_sanitize(unsigned long) {}
}; };
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class _WordT, size_t _Extrabits> struct _Sanitize {
static void _M_do_sanitize(_WordT& __val) {
if (_Extrabits != 0)
__val &= ~((~static_cast<_WordT>(0)) << _Extrabits);
}
};
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
// ------------------------------------------------------------ // ------------------------------------------------------------
// Class bitset. // Class bitset.
// _Nb may be any nonzero number of type size_t. // _Nb may be any nonzero number of type size_t.
// Type _WordT may be any unsigned integral type.
template<size_t _Nb, class _WordT = unsigned long> template<size_t _Nb>
class bitset : private _Base_bitset<__BITSET_WORDS(_Nb,_WordT), _WordT> class bitset : private _Base_bitset<__BITSET_WORDS(_Nb)>
{ {
private: private:
typedef _Base_bitset<__BITSET_WORDS(_Nb,_WordT), _WordT> _Base; typedef _Base_bitset<__BITSET_WORDS(_Nb)> _Base;
typedef unsigned long _WordT;
// Import base's protected interface. Necessary because of new template
// name resolution rules.
#ifdef __STL_HAS_NAMESPACES
using _Base::_S_whichword;
using _Base::_S_whichbyte;
using _Base::_S_whichbit;
using _Base::_S_maskbit;
using _Base::_M_getword;
using _Base::_M_hiword;
using _Base::_M_do_and;
using _Base::_M_do_or;
using _Base::_M_do_xor;
using _Base::_M_do_left_shift;
using _Base::_M_do_right_shift;
using _Base::_M_do_flip;
using _Base::_M_do_set;
using _Base::_M_do_reset;
using _Base::_M_is_equal;
using _Base::_M_is_any;
using _Base::_M_do_count;
using _Base::_M_do_to_ulong;
using _Base::_M_do_find_first;
using _Base::_M_do_find_next;
#endif /* __STL_HAS_NAMESPACES */
private: private:
void _M_do_sanitize() { void _M_do_sanitize() {
_Sanitize<_WordT,_Nb%__BITS_PER_WORDT(_WordT) > _Sanitize<_Nb%__BITS_PER_WORD>::_M_do_sanitize(this->_M_hiword());
::_M_do_sanitize(_M_hiword());
} }
public: public:
...@@ -595,7 +463,7 @@ public: ...@@ -595,7 +463,7 @@ public:
// bit reference: // bit reference:
class reference; class reference;
friend class reference; friend class reference;
class reference { class reference {
friend class bitset; friend class bitset;
...@@ -608,7 +476,7 @@ public: ...@@ -608,7 +476,7 @@ public:
public: public:
reference( bitset& __b, size_t __pos ) { reference( bitset& __b, size_t __pos ) {
_M_wp = &__b._M_getword(__pos); _M_wp = &__b._M_getword(__pos);
_M_bpos = _S_whichbit(__pos); _M_bpos = _Base::_S_whichbit(__pos);
} }
~reference() {} ~reference() {}
...@@ -616,101 +484,101 @@ public: ...@@ -616,101 +484,101 @@ public:
// for b[i] = __x; // for b[i] = __x;
reference& operator=(bool __x) { reference& operator=(bool __x) {
if ( __x ) if ( __x )
*_M_wp |= _S_maskbit(_M_bpos); *_M_wp |= _Base::_S_maskbit(_M_bpos);
else else
*_M_wp &= ~_S_maskbit(_M_bpos); *_M_wp &= ~_Base::_S_maskbit(_M_bpos);
return *this; return *this;
} }
// for b[i] = b[__j]; // for b[i] = b[__j];
reference& operator=(const reference& __j) { reference& operator=(const reference& __j) {
if ( (*(__j._M_wp) & _S_maskbit(__j._M_bpos)) ) if ( (*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)) )
*_M_wp |= _S_maskbit(_M_bpos); *_M_wp |= _Base::_S_maskbit(_M_bpos);
else else
*_M_wp &= ~_S_maskbit(_M_bpos); *_M_wp &= ~_Base::_S_maskbit(_M_bpos);
return *this; return *this;
} }
// flips the bit // flips the bit
bool operator~() const { return (*(_M_wp) & _S_maskbit(_M_bpos)) == 0; } bool operator~() const
{ return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
// for __x = b[i]; // for __x = b[i];
operator bool() const { return (*(_M_wp) & _S_maskbit(_M_bpos)) != 0; } operator bool() const
{ return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
// for b[i].flip(); // for b[i].flip();
reference& flip() { reference& flip() {
*_M_wp ^= _S_maskbit(_M_bpos); *_M_wp ^= _Base::_S_maskbit(_M_bpos);
return *this; return *this;
} }
}; };
// 23.3.5.1 constructors: // 23.3.5.1 constructors:
bitset() {} bitset() {}
bitset(unsigned long __val) : bitset(unsigned long __val) : _Base_bitset<__BITSET_WORDS(_Nb)>(__val)
_Base_bitset<__BITSET_WORDS(_Nb,_WordT), _WordT>(__val) {} { _M_do_sanitize(); }
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
template<class _CharT, class _Traits, class _Alloc> template<class _CharT, class _Traits, class _Alloc>
explicit bitset(const basic_string<_CharT,_Traits,_Alloc>& __s, explicit bitset(const basic_string<_CharT, _Traits, _Alloc>& __s,
size_t __pos = 0) size_t __pos = 0)
: _Base() : _Base()
{ {
if (__pos > __s.size()) if (__pos > __s.size())
__STL_THROW(out_of_range("bitset")); __STL_THROW(out_of_range("bitset"));
_M_copy_from_string(__s, __pos, _M_copy_from_string(__s, __pos,
basic_string<_CharT,_Traits,_Alloc>::npos); basic_string<_CharT, _Traits, _Alloc>::npos);
} }
template<class _CharT, class _Traits, class _Alloc> template<class _CharT, class _Traits, class _Alloc>
bitset(const basic_string<_CharT, _Traits, _Alloc>& __s, bitset(const basic_string<_CharT, _Traits, _Alloc>& __s,
size_t __pos, size_t __pos,
size_t __n) size_t __n)
: _Base() : _Base()
{ {
if (__pos > __s.size()) if (__pos > __s.size())
__STL_THROW(out_of_range("bitset")); __STL_THROW(out_of_range("bitset"));
_M_copy_from_string(__s, __pos, __n); _M_copy_from_string(__s, __pos, __n);
} }
#else #else /* __STL_MEMBER_TEMPLATES */
explicit bitset(const basic_string<char>& __s, explicit bitset(const basic_string<char>& __s,
size_t __pos = 0, size_t __pos = 0,
size_t __n = basic_string<char>::npos) size_t __n = basic_string<char>::npos)
: _Base() : _Base()
{ {
if (__pos > __s.size()) if (__pos > __s.size())
__STL_THROW(out_of_range("bitset")); __STL_THROW(out_of_range("bitset"));
_M_copy_from_string(__s, __pos, __n); _M_copy_from_string(__s, __pos, __n);
} }
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
// 23.3.5.2 bitset operations: // 23.3.5.2 bitset operations:
bitset<_Nb,_WordT>& operator&=(const bitset<_Nb,_WordT>& __rhs) { bitset<_Nb>& operator&=(const bitset<_Nb>& __rhs) {
_M_do_and(__rhs); this->_M_do_and(__rhs);
return *this; return *this;
} }
bitset<_Nb,_WordT>& operator|=(const bitset<_Nb,_WordT>& __rhs) { bitset<_Nb>& operator|=(const bitset<_Nb>& __rhs) {
_M_do_or(__rhs); this->_M_do_or(__rhs);
return *this; return *this;
} }
bitset<_Nb,_WordT>& operator^=(const bitset<_Nb,_WordT>& __rhs) { bitset<_Nb>& operator^=(const bitset<_Nb>& __rhs) {
_M_do_xor(__rhs); this->_M_do_xor(__rhs);
return *this; return *this;
} }
bitset<_Nb,_WordT>& operator<<=(size_t __pos) { bitset<_Nb>& operator<<=(size_t __pos) {
_M_do_left_shift(__pos); this->_M_do_left_shift(__pos);
_M_do_sanitize(); this->_M_do_sanitize();
return *this; return *this;
} }
bitset<_Nb,_WordT>& operator>>=(size_t __pos) { bitset<_Nb>& operator>>=(size_t __pos) {
_M_do_right_shift(__pos); this->_M_do_right_shift(__pos);
_M_do_sanitize(); this->_M_do_sanitize();
return *this; return *this;
} }
...@@ -719,83 +587,84 @@ public: ...@@ -719,83 +587,84 @@ public:
// Versions of single-bit set, reset, flip, test with no range checking. // Versions of single-bit set, reset, flip, test with no range checking.
// //
bitset<_Nb,_WordT>& _Unchecked_set(size_t __pos) { bitset<_Nb>& _Unchecked_set(size_t __pos) {
_M_getword(__pos) |= _S_maskbit(__pos); this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
return *this; return *this;
} }
bitset<_Nb,_WordT>& _Unchecked_set(size_t __pos, int __val) { bitset<_Nb>& _Unchecked_set(size_t __pos, int __val) {
if (__val) if (__val)
_M_getword(__pos) |= _S_maskbit(__pos); this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
else else
_M_getword(__pos) &= ~_S_maskbit(__pos); this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
return *this; return *this;
} }
bitset<_Nb,_WordT>& _Unchecked_reset(size_t __pos) { bitset<_Nb>& _Unchecked_reset(size_t __pos) {
_M_getword(__pos) &= ~_S_maskbit(__pos); this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
return *this; return *this;
} }
bitset<_Nb,_WordT>& _Unchecked_flip(size_t __pos) { bitset<_Nb>& _Unchecked_flip(size_t __pos) {
_M_getword(__pos) ^= _S_maskbit(__pos); this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
return *this; return *this;
} }
bool _Unchecked_test(size_t __pos) const { bool _Unchecked_test(size_t __pos) const {
return (_M_getword(__pos) & _S_maskbit(__pos)) != static_cast<_WordT>(0); return (this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
!= static_cast<_WordT>(0);
} }
// Set, reset, and flip. // Set, reset, and flip.
bitset<_Nb,_WordT>& set() { bitset<_Nb>& set() {
_M_do_set(); this->_M_do_set();
_M_do_sanitize(); this->_M_do_sanitize();
return *this; return *this;
} }
bitset<_Nb,_WordT>& set(size_t __pos) { bitset<_Nb>& set(size_t __pos) {
if (__pos >= _Nb) if (__pos >= _Nb)
__STL_THROW(out_of_range("bitset")); __STL_THROW(out_of_range("bitset"));
return _Unchecked_set(__pos); return _Unchecked_set(__pos);
} }
bitset<_Nb,_WordT>& set(size_t __pos, int __val) { bitset<_Nb>& set(size_t __pos, int __val) {
if (__pos >= _Nb) if (__pos >= _Nb)
__STL_THROW(out_of_range("bitset")); __STL_THROW(out_of_range("bitset"));
return _Unchecked_set(__pos, __val); return _Unchecked_set(__pos, __val);
} }
bitset<_Nb,_WordT>& reset() { bitset<_Nb>& reset() {
_M_do_reset(); this->_M_do_reset();
return *this; return *this;
} }
bitset<_Nb,_WordT>& reset(size_t __pos) { bitset<_Nb>& reset(size_t __pos) {
if (__pos >= _Nb) if (__pos >= _Nb)
__STL_THROW(out_of_range("bitset")); __STL_THROW(out_of_range("bitset"));
return _Unchecked_reset(__pos); return _Unchecked_reset(__pos);
} }
bitset<_Nb,_WordT>& flip() { bitset<_Nb>& flip() {
_M_do_flip(); this->_M_do_flip();
_M_do_sanitize(); this->_M_do_sanitize();
return *this; return *this;
} }
bitset<_Nb,_WordT>& flip(size_t __pos) { bitset<_Nb>& flip(size_t __pos) {
if (__pos >= _Nb) if (__pos >= _Nb)
__STL_THROW(out_of_range("bitset")); __STL_THROW(out_of_range("bitset"));
return _Unchecked_flip(__pos); return _Unchecked_flip(__pos);
} }
bitset<_Nb,_WordT> operator~() const { bitset<_Nb> operator~() const {
return bitset<_Nb,_WordT>(*this).flip(); return bitset<_Nb>(*this).flip();
} }
// element access: // element access:
...@@ -803,23 +672,20 @@ public: ...@@ -803,23 +672,20 @@ public:
reference operator[](size_t __pos) { return reference(*this,__pos); } reference operator[](size_t __pos) { return reference(*this,__pos); }
bool operator[](size_t __pos) const { return _Unchecked_test(__pos); } bool operator[](size_t __pos) const { return _Unchecked_test(__pos); }
unsigned long to_ulong() const { return _M_do_to_ulong(); } unsigned long to_ulong() const { return this->_M_do_to_ulong(); }
#if defined(__STL_MEMBER_TEMPLATES) && \
defined(__STL_EXPLICIT_FUNCTION_TMPL_ARGS)
#if defined(__STL_MEMBER_TEMPLATES) && \
defined(__STL_EXPLICIT_FUNCTION_TMPL_ARGS)
template <class _CharT, class _Traits, class _Alloc> template <class _CharT, class _Traits, class _Alloc>
basic_string<_CharT, _Traits, _Alloc> to_string() const { basic_string<_CharT, _Traits, _Alloc> to_string() const {
basic_string<_CharT, _Traits, _Alloc> __result; basic_string<_CharT, _Traits, _Alloc> __result;
_M_copy_to_string(__result); _M_copy_to_string(__result);
return __result; return __result;
} }
#endif /* member templates and explicit function template args */ #endif /* member templates and explicit function template args */
// Helper functions for string operations. // Helper functions for string operations.
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
template<class _CharT, class _Traits, class _Alloc> template<class _CharT, class _Traits, class _Alloc>
void _M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s, void _M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s,
size_t, size_t,
...@@ -827,23 +693,20 @@ public: ...@@ -827,23 +693,20 @@ public:
template<class _CharT, class _Traits, class _Alloc> template<class _CharT, class _Traits, class _Alloc>
void _M_copy_to_string(basic_string<_CharT,_Traits,_Alloc>&) const; void _M_copy_to_string(basic_string<_CharT,_Traits,_Alloc>&) const;
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_MEMBER_TEMPLATES */
void _M_copy_from_string(const basic_string<char>&, size_t, size_t); void _M_copy_from_string(const basic_string<char>&, size_t, size_t);
void _M_copy_to_string(basic_string<char>&) const; void _M_copy_to_string(basic_string<char>&) const;
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
size_t count() const { return _M_do_count(); } size_t count() const { return this->_M_do_count(); }
size_t size() const { return _Nb; } size_t size() const { return _Nb; }
bool operator==(const bitset<_Nb,_WordT>& __rhs) const { bool operator==(const bitset<_Nb>& __rhs) const {
return _M_is_equal(__rhs); return this->_M_is_equal(__rhs);
} }
bool operator!=(const bitset<_Nb,_WordT>& __rhs) const { bool operator!=(const bitset<_Nb>& __rhs) const {
return !_M_is_equal(__rhs); return !this->_M_is_equal(__rhs);
} }
bool test(size_t __pos) const { bool test(size_t __pos) const {
...@@ -853,27 +716,27 @@ public: ...@@ -853,27 +716,27 @@ public:
return _Unchecked_test(__pos); return _Unchecked_test(__pos);
} }
bool any() const { return _M_is_any(); } bool any() const { return this->_M_is_any(); }
bool none() const { return !_M_is_any(); } bool none() const { return !this->_M_is_any(); }
bitset<_Nb,_WordT> operator<<(size_t __pos) const bitset<_Nb> operator<<(size_t __pos) const
{ return bitset<_Nb,_WordT>(*this) <<= __pos; } { return bitset<_Nb>(*this) <<= __pos; }
bitset<_Nb,_WordT> operator>>(size_t __pos) const bitset<_Nb> operator>>(size_t __pos) const
{ return bitset<_Nb,_WordT>(*this) >>= __pos; } { return bitset<_Nb>(*this) >>= __pos; }
// //
// EXTENSIONS: bit-find operations. These operations are // EXTENSIONS: bit-find operations. These operations are
// experimental, and are subject to change or removal in future // experimental, and are subject to change or removal in future
// versions. // versions.
// //
// find the index of the first "on" bit // find the index of the first "on" bit
size_t _Find_first() const size_t _Find_first() const
{ return _M_do_find_first(_Nb); } { return this->_M_do_find_first(_Nb); }
// find the index of the next "on" bit after prev // find the index of the next "on" bit after prev
size_t _Find_next( size_t __prev ) const size_t _Find_next( size_t __prev ) const
{ return _M_do_find_next(__prev, _Nb); } { return this->_M_do_find_next(__prev, _Nb); }
}; };
...@@ -883,9 +746,9 @@ public: ...@@ -883,9 +746,9 @@ public:
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
template <size_t _Nb, class _WordT> template <size_t _Nb>
template<class _CharT, class _Traits, class _Alloc> template<class _CharT, class _Traits, class _Alloc>
void bitset<_Nb, _WordT> void bitset<_Nb>
::_M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s, ::_M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s,
size_t __pos, size_t __pos,
size_t __n) size_t __n)
...@@ -905,23 +768,23 @@ void bitset<_Nb, _WordT> ...@@ -905,23 +768,23 @@ void bitset<_Nb, _WordT>
} }
} }
template <size_t _Nb, class _WordT> template <size_t _Nb>
template <class _CharT, class _Traits, class _Alloc> template <class _CharT, class _Traits, class _Alloc>
void bitset<_Nb, _WordT> void bitset<_Nb>
::_M_copy_to_string(basic_string<_CharT, _Traits, _Alloc>& __s) const ::_M_copy_to_string(basic_string<_CharT, _Traits, _Alloc>& __s) const
{ {
__s.assign(_Nb, '0'); __s.assign(_Nb, '0');
for (size_t __i = 0; __i < _Nb; ++__i) for (size_t __i = 0; __i < _Nb; ++__i)
if (_Unchecked_test(__i)) if (_Unchecked_test(__i))
__s[_Nb - 1 - __i] = '1'; __s[_Nb - 1 - __i] = '1';
} }
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_MEMBER_TEMPLATES */
template <size_t _Nb, class _WordT> template <size_t _Nb>
void bitset<_Nb, _WordT>::_M_copy_from_string(const basic_string<char>& __s, void bitset<_Nb>::_M_copy_from_string(const basic_string<char>& __s,
size_t __pos, size_t __n) size_t __pos, size_t __n)
{ {
reset(); reset();
size_t __tmp = _Nb; size_t __tmp = _Nb;
...@@ -939,8 +802,8 @@ void bitset<_Nb, _WordT>::_M_copy_from_string(const basic_string<char>& __s, ...@@ -939,8 +802,8 @@ void bitset<_Nb, _WordT>::_M_copy_from_string(const basic_string<char>& __s,
} }
} }
template <size_t _Nb, class _WordT> template <size_t _Nb>
void bitset<_Nb, _WordT>::_M_copy_to_string(basic_string<char>& __s) const void bitset<_Nb>::_M_copy_to_string(basic_string<char>& __s) const
{ {
__s.assign(_Nb, '0'); __s.assign(_Nb, '0');
...@@ -957,36 +820,33 @@ void bitset<_Nb, _WordT>::_M_copy_to_string(basic_string<char>& __s) const ...@@ -957,36 +820,33 @@ void bitset<_Nb, _WordT>::_M_copy_to_string(basic_string<char>& __s) const
// 23.3.5.3 bitset operations: // 23.3.5.3 bitset operations:
// //
template <size_t _Nb, class _WordT> template <size_t _Nb>
inline bitset<_Nb,_WordT> operator&(const bitset<_Nb,_WordT>& __x, inline bitset<_Nb> operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) {
const bitset<_Nb,_WordT>& __y) { bitset<_Nb> __result(__x);
bitset<_Nb,_WordT> __result(__x);
__result &= __y; __result &= __y;
return __result; return __result;
} }
template <size_t _Nb, class _WordT> template <size_t _Nb>
inline bitset<_Nb,_WordT> operator|(const bitset<_Nb,_WordT>& __x, inline bitset<_Nb> operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) {
const bitset<_Nb,_WordT>& __y) { bitset<_Nb> __result(__x);
bitset<_Nb,_WordT> __result(__x);
__result |= __y; __result |= __y;
return __result; return __result;
} }
template <size_t _Nb, class _WordT> template <size_t _Nb>
inline bitset<_Nb,_WordT> operator^(const bitset<_Nb,_WordT>& __x, inline bitset<_Nb> operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) {
const bitset<_Nb,_WordT>& __y) { bitset<_Nb> __result(__x);
bitset<_Nb,_WordT> __result(__x);
__result ^= __y; __result ^= __y;
return __result; return __result;
} }
#ifdef __STL_USE_NEW_IOSTREAMS #ifdef __STL_USE_NEW_IOSTREAMS
template <class _CharT, class _Traits, size_t _Nb, class _WordT> template <class _CharT, class _Traits, size_t _Nb>
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb,_WordT>& __x) operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x)
{ {
basic_string<_CharT, _Traits> __tmp; basic_string<_CharT, _Traits> __tmp;
__tmp.reserve(_Nb); __tmp.reserve(_Nb);
...@@ -1025,10 +885,9 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb,_WordT>& __x) ...@@ -1025,10 +885,9 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb,_WordT>& __x)
return __is; return __is;
} }
template <class _CharT, class _Traits, size_t _Nb, class _WordT> template <class _CharT, class _Traits, size_t _Nb>
basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Nb>& __x)
const bitset<_Nb,_WordT>& __x)
{ {
basic_string<_CharT, _Traits> __tmp; basic_string<_CharT, _Traits> __tmp;
__x._M_copy_to_string(__tmp); __x._M_copy_to_string(__tmp);
...@@ -1037,9 +896,8 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, ...@@ -1037,9 +896,8 @@ operator<<(basic_ostream<_CharT, _Traits>& __os,
#else /* __STL_USE_NEW_IOSTREAMS */ #else /* __STL_USE_NEW_IOSTREAMS */
template <size_t _Nb, class _WordT> template <size_t _Nb>
istream& istream& operator>>(istream& __is, bitset<_Nb>& __x) {
operator>>(istream& __is, bitset<_Nb,_WordT>& __x) {
string __tmp; string __tmp;
__tmp.reserve(_Nb); __tmp.reserve(_Nb);
...@@ -1074,8 +932,8 @@ operator>>(istream& __is, bitset<_Nb,_WordT>& __x) { ...@@ -1074,8 +932,8 @@ operator>>(istream& __is, bitset<_Nb,_WordT>& __x) {
return __is; return __is;
} }
template <size_t _Nb, class _WordT> template <size_t _Nb>
ostream& operator<<(ostream& __os, const bitset<_Nb,_WordT>& __x) { ostream& operator<<(ostream& __os, const bitset<_Nb>& __x) {
string __tmp; string __tmp;
__x._M_copy_to_string(__tmp); __x._M_copy_to_string(__tmp);
return __os << __tmp; return __os << __tmp;
...@@ -1140,7 +998,7 @@ unsigned char _Bit_count<__dummy>::_S_bit_count[] = { ...@@ -1140,7 +998,7 @@ unsigned char _Bit_count<__dummy>::_S_bit_count[] = {
6, /* 245 */ 6, /* 246 */ 7, /* 247 */ 5, /* 248 */ 6, /* 249 */ 6, /* 245 */ 6, /* 246 */ 7, /* 247 */ 5, /* 248 */ 6, /* 249 */
6, /* 250 */ 7, /* 251 */ 6, /* 252 */ 7, /* 253 */ 7, /* 254 */ 6, /* 250 */ 7, /* 251 */ 6, /* 252 */ 7, /* 253 */ 7, /* 254 */
8 /* 255 */ 8 /* 255 */
}; // end _S_bit_count }; // end _Bit_count
template<bool __dummy> template<bool __dummy>
unsigned char _First_one<__dummy>::_S_first_one[] = { unsigned char _First_one<__dummy>::_S_first_one[] = {
...@@ -1205,12 +1063,13 @@ unsigned char _First_one<__dummy>::_S_first_one[] = { ...@@ -1205,12 +1063,13 @@ unsigned char _First_one<__dummy>::_S_first_one[] = {
__STL_END_NAMESPACE __STL_END_NAMESPACE
#undef __BITS_PER_WORDT #undef __BITS_PER_WORD
#undef __BITSET_WORDS #undef __BITSET_WORDS
#endif /* _CPP_BITSET */ #endif /* __SGI_STL_BITSET */
// Local Variables: // Local Variables:
// mode:C++ // mode:C++
// End: // End:
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#ifndef _CPP_MAP #ifndef _CPP_MAP
#define _CPP_MAP 1 #define _CPP_MAP 1
#ifndef _CPP_BITS_STL_TREE_H /* XXX is this guard necessary? */ #ifndef _CPP_BITS_STL_TREE_H
#include <bits/stl_tree.h> #include <bits/stl_tree.h>
#endif #endif
#include <bits/stl_map.h> #include <bits/stl_map.h>
......
...@@ -62,9 +62,13 @@ public: ...@@ -62,9 +62,13 @@ public:
return *this; return *this;
} }
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
~auto_ptr() __STL_NOTHROW { delete _M_ptr; } // 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 { _Tp& operator*() const __STL_NOTHROW {
return *_M_ptr; return *_M_ptr;
} }
......
...@@ -33,6 +33,10 @@ ...@@ -33,6 +33,10 @@
#include <bits/stl_heap.h> #include <bits/stl_heap.h>
// See concept_checks.h for the concept-checking macros
// __STL_REQUIRES, __STL_CONVERTIBLE, etc.
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
...@@ -43,6 +47,7 @@ __STL_BEGIN_NAMESPACE ...@@ -43,6 +47,7 @@ __STL_BEGIN_NAMESPACE
template <class _Tp> template <class _Tp>
inline const _Tp& __median(const _Tp& __a, const _Tp& __b, const _Tp& __c) { inline const _Tp& __median(const _Tp& __a, const _Tp& __b, const _Tp& __c) {
__STL_REQUIRES(_Tp, _LessThanComparable);
if (__a < __b) if (__a < __b)
if (__b < __c) if (__b < __c)
return __b; return __b;
...@@ -61,6 +66,7 @@ inline const _Tp& __median(const _Tp& __a, const _Tp& __b, const _Tp& __c) { ...@@ -61,6 +66,7 @@ inline const _Tp& __median(const _Tp& __a, const _Tp& __b, const _Tp& __c) {
template <class _Tp, class _Compare> template <class _Tp, class _Compare>
inline const _Tp& inline const _Tp&
__median(const _Tp& __a, const _Tp& __b, const _Tp& __c, _Compare __comp) { __median(const _Tp& __a, const _Tp& __b, const _Tp& __c, _Compare __comp) {
__STL_BINARY_FUNCTION_CHECK(_Compare, bool, _Tp, _Tp);
if (__comp(__a, __b)) if (__comp(__a, __b))
if (__comp(__b, __c)) if (__comp(__b, __c))
return __b; return __b;
...@@ -79,6 +85,7 @@ __median(const _Tp& __a, const _Tp& __b, const _Tp& __c, _Compare __comp) { ...@@ -79,6 +85,7 @@ __median(const _Tp& __a, const _Tp& __b, const _Tp& __c, _Compare __comp) {
// for_each. Apply a function to every element of a range. // for_each. Apply a function to every element of a range.
template <class _InputIter, class _Function> template <class _InputIter, class _Function>
_Function for_each(_InputIter __first, _InputIter __last, _Function __f) { _Function for_each(_InputIter __first, _InputIter __last, _Function __f) {
__STL_REQUIRES(_InputIter, _InputIterator);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
__f(*__first); __f(*__first);
return __f; return __f;
...@@ -91,7 +98,7 @@ inline _InputIter find(_InputIter __first, _InputIter __last, ...@@ -91,7 +98,7 @@ inline _InputIter find(_InputIter __first, _InputIter __last,
const _Tp& __val, const _Tp& __val,
input_iterator_tag) input_iterator_tag)
{ {
while (__first != __last && *__first != __val) while (__first != __last && !(*__first == __val))
++__first; ++__first;
return __first; return __first;
} }
...@@ -190,12 +197,18 @@ template <class _InputIter, class _Tp> ...@@ -190,12 +197,18 @@ template <class _InputIter, class _Tp>
inline _InputIter find(_InputIter __first, _InputIter __last, inline _InputIter find(_InputIter __first, _InputIter __last,
const _Tp& __val) const _Tp& __val)
{ {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES_BINARY_OP(_OP_EQUAL, bool,
typename iterator_traits<_InputIter>::value_type, _Tp);
return find(__first, __last, __val, __ITERATOR_CATEGORY(__first)); return find(__first, __last, __val, __ITERATOR_CATEGORY(__first));
} }
template <class _InputIter, class _Predicate> template <class _InputIter, class _Predicate>
inline _InputIter find_if(_InputIter __first, _InputIter __last, inline _InputIter find_if(_InputIter __first, _InputIter __last,
_Predicate __pred) { _Predicate __pred) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_UNARY_FUNCTION_CHECK(_Predicate, bool,
typename iterator_traits<_InputIter>::value_type);
return find_if(__first, __last, __pred, __ITERATOR_CATEGORY(__first)); return find_if(__first, __last, __pred, __ITERATOR_CATEGORY(__first));
} }
...@@ -203,6 +216,9 @@ inline _InputIter find_if(_InputIter __first, _InputIter __last, ...@@ -203,6 +216,9 @@ inline _InputIter find_if(_InputIter __first, _InputIter __last,
template <class _ForwardIter> template <class _ForwardIter>
_ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last) { _ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES(typename iterator_traits<_ForwardIter>::value_type,
_EqualityComparable);
if (__first == __last) if (__first == __last)
return __last; return __last;
_ForwardIter __next = __first; _ForwardIter __next = __first;
...@@ -217,6 +233,10 @@ _ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last) { ...@@ -217,6 +233,10 @@ _ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last) {
template <class _ForwardIter, class _BinaryPredicate> template <class _ForwardIter, class _BinaryPredicate>
_ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last, _ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last,
_BinaryPredicate __binary_pred) { _BinaryPredicate __binary_pred) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_BINARY_FUNCTION_CHECK(_BinaryPredicate, bool,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type);
if (__first == __last) if (__first == __last)
return __last; return __last;
_ForwardIter __next = __first; _ForwardIter __next = __first;
...@@ -237,6 +257,10 @@ _ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last, ...@@ -237,6 +257,10 @@ _ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last,
template <class _InputIter, class _Tp, class _Size> template <class _InputIter, class _Tp, class _Size>
void count(_InputIter __first, _InputIter __last, const _Tp& __value, void count(_InputIter __first, _InputIter __last, const _Tp& __value,
_Size& __n) { _Size& __n) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(typename iterator_traits<_InputIter>::value_type,
_EqualityComparable);
__STL_REQUIRES(_Tp, _EqualityComparable);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
if (*__first == __value) if (*__first == __value)
++__n; ++__n;
...@@ -245,6 +269,9 @@ void count(_InputIter __first, _InputIter __last, const _Tp& __value, ...@@ -245,6 +269,9 @@ void count(_InputIter __first, _InputIter __last, const _Tp& __value,
template <class _InputIter, class _Predicate, class _Size> template <class _InputIter, class _Predicate, class _Size>
void count_if(_InputIter __first, _InputIter __last, _Predicate __pred, void count_if(_InputIter __first, _InputIter __last, _Predicate __pred,
_Size& __n) { _Size& __n) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_UNARY_FUNCTION_CHECK(_Predicate, bool,
typename iterator_traits<_InputIter>::value_type);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
if (__pred(*__first)) if (__pred(*__first))
++__n; ++__n;
...@@ -255,6 +282,10 @@ void count_if(_InputIter __first, _InputIter __last, _Predicate __pred, ...@@ -255,6 +282,10 @@ void count_if(_InputIter __first, _InputIter __last, _Predicate __pred,
template <class _InputIter, class _Tp> template <class _InputIter, class _Tp>
typename iterator_traits<_InputIter>::difference_type typename iterator_traits<_InputIter>::difference_type
count(_InputIter __first, _InputIter __last, const _Tp& __value) { count(_InputIter __first, _InputIter __last, const _Tp& __value) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(typename iterator_traits<_InputIter>::value_type,
_EqualityComparable);
__STL_REQUIRES(_Tp, _EqualityComparable);
typename iterator_traits<_InputIter>::difference_type __n = 0; typename iterator_traits<_InputIter>::difference_type __n = 0;
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
if (*__first == __value) if (*__first == __value)
...@@ -265,6 +296,9 @@ count(_InputIter __first, _InputIter __last, const _Tp& __value) { ...@@ -265,6 +296,9 @@ count(_InputIter __first, _InputIter __last, const _Tp& __value) {
template <class _InputIter, class _Predicate> template <class _InputIter, class _Predicate>
typename iterator_traits<_InputIter>::difference_type typename iterator_traits<_InputIter>::difference_type
count_if(_InputIter __first, _InputIter __last, _Predicate __pred) { count_if(_InputIter __first, _InputIter __last, _Predicate __pred) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_UNARY_FUNCTION_CHECK(_Predicate, bool,
typename iterator_traits<_InputIter>::value_type);
typename iterator_traits<_InputIter>::difference_type __n = 0; typename iterator_traits<_InputIter>::difference_type __n = 0;
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
if (__pred(*__first)) if (__pred(*__first))
...@@ -281,6 +315,12 @@ template <class _ForwardIter1, class _ForwardIter2> ...@@ -281,6 +315,12 @@ template <class _ForwardIter1, class _ForwardIter2>
_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2) _ForwardIter2 __first2, _ForwardIter2 __last2)
{ {
__STL_REQUIRES(_ForwardIter1, _ForwardIterator);
__STL_REQUIRES(_ForwardIter2, _ForwardIterator);
__STL_REQUIRES_BINARY_OP(_OP_EQUAL, bool,
typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type);
// Test for empty ranges // Test for empty ranges
if (__first1 == __last1 || __first2 == __last2) if (__first1 == __last1 || __first2 == __last2)
return __first1; return __first1;
...@@ -326,6 +366,12 @@ _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1, ...@@ -326,6 +366,12 @@ _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2, _ForwardIter2 __first2, _ForwardIter2 __last2,
_BinaryPred __predicate) _BinaryPred __predicate)
{ {
__STL_REQUIRES(_ForwardIter1, _ForwardIterator);
__STL_REQUIRES(_ForwardIter2, _ForwardIterator);
__STL_BINARY_FUNCTION_CHECK(_BinaryPred, bool,
typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type);
// Test for empty ranges // Test for empty ranges
if (__first1 == __last1 || __first2 == __last2) if (__first1 == __last1 || __first2 == __last2)
return __first1; return __first1;
...@@ -379,6 +425,11 @@ _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1, ...@@ -379,6 +425,11 @@ _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
template <class _ForwardIter, class _Integer, class _Tp> template <class _ForwardIter, class _Integer, class _Tp>
_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last, _ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
_Integer __count, const _Tp& __val) { _Integer __count, const _Tp& __val) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES(typename iterator_traits<_ForwardIter>::value_type,
_EqualityComparable);
__STL_REQUIRES(_Tp, _EqualityComparable);
if (__count <= 0) if (__count <= 0)
return __first; return __first;
else { else {
...@@ -404,6 +455,9 @@ template <class _ForwardIter, class _Integer, class _Tp, class _BinaryPred> ...@@ -404,6 +455,9 @@ template <class _ForwardIter, class _Integer, class _Tp, class _BinaryPred>
_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last, _ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
_Integer __count, const _Tp& __val, _Integer __count, const _Tp& __val,
_BinaryPred __binary_pred) { _BinaryPred __binary_pred) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_BINARY_FUNCTION_CHECK(_BinaryPred, bool,
typename iterator_traits<_ForwardIter>::value_type, _Tp);
if (__count <= 0) if (__count <= 0)
return __first; return __first;
else { else {
...@@ -440,6 +494,12 @@ _ForwardIter search_n(_ForwardIter __first, _ForwardIter __last, ...@@ -440,6 +494,12 @@ _ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
template <class _ForwardIter1, class _ForwardIter2> template <class _ForwardIter1, class _ForwardIter2>
_ForwardIter2 swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter2 swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2) { _ForwardIter2 __first2) {
__STL_REQUIRES(_ForwardIter1, _Mutable_ForwardIterator);
__STL_REQUIRES(_ForwardIter2, _Mutable_ForwardIterator);
__STL_CONVERTIBLE(typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type);
__STL_CONVERTIBLE(typename iterator_traits<_ForwardIter2>::value_type,
typename iterator_traits<_ForwardIter1>::value_type);
for ( ; __first1 != __last1; ++__first1, ++__first2) for ( ; __first1 != __last1; ++__first1, ++__first2)
iter_swap(__first1, __first2); iter_swap(__first1, __first2);
return __first2; return __first2;
...@@ -450,6 +510,9 @@ _ForwardIter2 swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1, ...@@ -450,6 +510,9 @@ _ForwardIter2 swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1,
template <class _InputIter, class _OutputIter, class _UnaryOperation> template <class _InputIter, class _OutputIter, class _UnaryOperation>
_OutputIter transform(_InputIter __first, _InputIter __last, _OutputIter transform(_InputIter __first, _InputIter __last,
_OutputIter __result, _UnaryOperation __unary_op) { _OutputIter __result, _UnaryOperation __unary_op) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
for ( ; __first != __last; ++__first, ++__result) for ( ; __first != __last; ++__first, ++__result)
*__result = __unary_op(*__first); *__result = __unary_op(*__first);
return __result; return __result;
...@@ -460,6 +523,9 @@ template <class _InputIter1, class _InputIter2, class _OutputIter, ...@@ -460,6 +523,9 @@ template <class _InputIter1, class _InputIter2, class _OutputIter,
_OutputIter transform(_InputIter1 __first1, _InputIter1 __last1, _OutputIter transform(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _OutputIter __result, _InputIter2 __first2, _OutputIter __result,
_BinaryOperation __binary_op) { _BinaryOperation __binary_op) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
for ( ; __first1 != __last1; ++__first1, ++__first2, ++__result) for ( ; __first1 != __last1; ++__first1, ++__first2, ++__result)
*__result = __binary_op(*__first1, *__first2); *__result = __binary_op(*__first1, *__first2);
return __result; return __result;
...@@ -470,6 +536,10 @@ _OutputIter transform(_InputIter1 __first1, _InputIter1 __last1, ...@@ -470,6 +536,10 @@ _OutputIter transform(_InputIter1 __first1, _InputIter1 __last1,
template <class _ForwardIter, class _Tp> template <class _ForwardIter, class _Tp>
void replace(_ForwardIter __first, _ForwardIter __last, void replace(_ForwardIter __first, _ForwardIter __last,
const _Tp& __old_value, const _Tp& __new_value) { const _Tp& __old_value, const _Tp& __new_value) {
__STL_REQUIRES(_ForwardIter, _Mutable_ForwardIterator);
__STL_REQUIRES_BINARY_OP(_OP_EQUAL, bool,
typename iterator_traits<_ForwardIter>::value_type, _Tp);
__STL_CONVERTIBLE(_Tp, typename iterator_traits<_ForwardIter>::value_type);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
if (*__first == __old_value) if (*__first == __old_value)
*__first = __new_value; *__first = __new_value;
...@@ -478,6 +548,10 @@ void replace(_ForwardIter __first, _ForwardIter __last, ...@@ -478,6 +548,10 @@ void replace(_ForwardIter __first, _ForwardIter __last,
template <class _ForwardIter, class _Predicate, class _Tp> template <class _ForwardIter, class _Predicate, class _Tp>
void replace_if(_ForwardIter __first, _ForwardIter __last, void replace_if(_ForwardIter __first, _ForwardIter __last,
_Predicate __pred, const _Tp& __new_value) { _Predicate __pred, const _Tp& __new_value) {
__STL_REQUIRES(_ForwardIter, _Mutable_ForwardIterator);
__STL_CONVERTIBLE(_Tp, typename iterator_traits<_ForwardIter>::value_type);
__STL_UNARY_FUNCTION_CHECK(_Predicate, bool,
typename iterator_traits<_ForwardIter>::value_type);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
if (__pred(*__first)) if (__pred(*__first))
*__first = __new_value; *__first = __new_value;
...@@ -487,15 +561,23 @@ template <class _InputIter, class _OutputIter, class _Tp> ...@@ -487,15 +561,23 @@ template <class _InputIter, class _OutputIter, class _Tp>
_OutputIter replace_copy(_InputIter __first, _InputIter __last, _OutputIter replace_copy(_InputIter __first, _InputIter __last,
_OutputIter __result, _OutputIter __result,
const _Tp& __old_value, const _Tp& __new_value) { const _Tp& __old_value, const _Tp& __new_value) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES_BINARY_OP(_OP_EQUAL, bool,
typename iterator_traits<_InputIter>::value_type, _Tp);
for ( ; __first != __last; ++__first, ++__result) for ( ; __first != __last; ++__first, ++__result)
*__result = *__first == __old_value ? __new_value : *__first; *__result = *__first == __old_value ? __new_value : *__first;
return __result; return __result;
} }
template <class Iterator, class _OutputIter, class _Predicate, class _Tp> template <class _InputIter, class _OutputIter, class _Predicate, class _Tp>
_OutputIter replace_copy_if(Iterator __first, Iterator __last, _OutputIter replace_copy_if(_InputIter __first, _InputIter __last,
_OutputIter __result, _OutputIter __result,
_Predicate __pred, const _Tp& __new_value) { _Predicate __pred, const _Tp& __new_value) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_UNARY_FUNCTION_CHECK(_Predicate, bool,
typename iterator_traits<_InputIter>::value_type);
for ( ; __first != __last; ++__first, ++__result) for ( ; __first != __last; ++__first, ++__result)
*__result = __pred(*__first) ? __new_value : *__first; *__result = __pred(*__first) ? __new_value : *__first;
return __result; return __result;
...@@ -505,12 +587,16 @@ _OutputIter replace_copy_if(Iterator __first, Iterator __last, ...@@ -505,12 +587,16 @@ _OutputIter replace_copy_if(Iterator __first, Iterator __last,
template <class _ForwardIter, class _Generator> template <class _ForwardIter, class _Generator>
void generate(_ForwardIter __first, _ForwardIter __last, _Generator __gen) { void generate(_ForwardIter __first, _ForwardIter __last, _Generator __gen) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_GENERATOR_CHECK(_Generator,
typename iterator_traits<_ForwardIter>::value_type);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
*__first = __gen(); *__first = __gen();
} }
template <class _OutputIter, class _Size, class _Generator> template <class _OutputIter, class _Size, class _Generator>
_OutputIter generate_n(_OutputIter __first, _Size __n, _Generator __gen) { _OutputIter generate_n(_OutputIter __first, _Size __n, _Generator __gen) {
__STL_REQUIRES(_OutputIter, _OutputIterator);
for ( ; __n > 0; --__n, ++__first) for ( ; __n > 0; --__n, ++__first)
*__first = __gen(); *__first = __gen();
return __first; return __first;
...@@ -521,8 +607,12 @@ _OutputIter generate_n(_OutputIter __first, _Size __n, _Generator __gen) { ...@@ -521,8 +607,12 @@ _OutputIter generate_n(_OutputIter __first, _Size __n, _Generator __gen) {
template <class _InputIter, class _OutputIter, class _Tp> template <class _InputIter, class _OutputIter, class _Tp>
_OutputIter remove_copy(_InputIter __first, _InputIter __last, _OutputIter remove_copy(_InputIter __first, _InputIter __last,
_OutputIter __result, const _Tp& __value) { _OutputIter __result, const _Tp& __value) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES_BINARY_OP(_OP_EQUAL, bool,
typename iterator_traits<_InputIter>::value_type, _Tp);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
if (*__first != __value) { if (!(*__first == __value)) {
*__result = *__first; *__result = *__first;
++__result; ++__result;
} }
...@@ -532,6 +622,10 @@ _OutputIter remove_copy(_InputIter __first, _InputIter __last, ...@@ -532,6 +622,10 @@ _OutputIter remove_copy(_InputIter __first, _InputIter __last,
template <class _InputIter, class _OutputIter, class _Predicate> template <class _InputIter, class _OutputIter, class _Predicate>
_OutputIter remove_copy_if(_InputIter __first, _InputIter __last, _OutputIter remove_copy_if(_InputIter __first, _InputIter __last,
_OutputIter __result, _Predicate __pred) { _OutputIter __result, _Predicate __pred) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_UNARY_FUNCTION_CHECK(_Predicate, bool,
typename iterator_traits<_InputIter>::value_type);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
if (!__pred(*__first)) { if (!__pred(*__first)) {
*__result = *__first; *__result = *__first;
...@@ -543,6 +637,10 @@ _OutputIter remove_copy_if(_InputIter __first, _InputIter __last, ...@@ -543,6 +637,10 @@ _OutputIter remove_copy_if(_InputIter __first, _InputIter __last,
template <class _ForwardIter, class _Tp> template <class _ForwardIter, class _Tp>
_ForwardIter remove(_ForwardIter __first, _ForwardIter __last, _ForwardIter remove(_ForwardIter __first, _ForwardIter __last,
const _Tp& __value) { const _Tp& __value) {
__STL_REQUIRES(_ForwardIter, _Mutable_ForwardIterator);
__STL_REQUIRES_BINARY_OP(_OP_EQUAL, bool,
typename iterator_traits<_ForwardIter>::value_type, _Tp);
__STL_CONVERTIBLE(_Tp, typename iterator_traits<_ForwardIter>::value_type);
__first = find(__first, __last, __value); __first = find(__first, __last, __value);
_ForwardIter __i = __first; _ForwardIter __i = __first;
return __first == __last ? __first return __first == __last ? __first
...@@ -552,6 +650,9 @@ _ForwardIter remove(_ForwardIter __first, _ForwardIter __last, ...@@ -552,6 +650,9 @@ _ForwardIter remove(_ForwardIter __first, _ForwardIter __last,
template <class _ForwardIter, class _Predicate> template <class _ForwardIter, class _Predicate>
_ForwardIter remove_if(_ForwardIter __first, _ForwardIter __last, _ForwardIter remove_if(_ForwardIter __first, _ForwardIter __last,
_Predicate __pred) { _Predicate __pred) {
__STL_REQUIRES(_ForwardIter, _Mutable_ForwardIterator);
__STL_UNARY_FUNCTION_CHECK(_Predicate, bool,
typename iterator_traits<_ForwardIter>::value_type);
__first = find_if(__first, __last, __pred); __first = find_if(__first, __last, __pred);
_ForwardIter __i = __first; _ForwardIter __i = __first;
return __first == __last ? __first return __first == __last ? __first
...@@ -566,7 +667,7 @@ _OutputIter __unique_copy(_InputIter __first, _InputIter __last, ...@@ -566,7 +667,7 @@ _OutputIter __unique_copy(_InputIter __first, _InputIter __last,
_Tp __value = *__first; _Tp __value = *__first;
*__result = __value; *__result = __value;
while (++__first != __last) while (++__first != __last)
if (__value != *__first) { if (!(__value == *__first)) {
__value = *__first; __value = *__first;
*++__result = __value; *++__result = __value;
} }
...@@ -585,13 +686,18 @@ _ForwardIter __unique_copy(_InputIter __first, _InputIter __last, ...@@ -585,13 +686,18 @@ _ForwardIter __unique_copy(_InputIter __first, _InputIter __last,
_ForwardIter __result, forward_iterator_tag) { _ForwardIter __result, forward_iterator_tag) {
*__result = *__first; *__result = *__first;
while (++__first != __last) while (++__first != __last)
if (*__result != *__first) *++__result = *__first; if (!(*__result == *__first))
*++__result = *__first;
return ++__result; return ++__result;
} }
template <class _InputIter, class _OutputIter> template <class _InputIter, class _OutputIter>
inline _OutputIter unique_copy(_InputIter __first, _InputIter __last, inline _OutputIter unique_copy(_InputIter __first, _InputIter __last,
_OutputIter __result) { _OutputIter __result) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES(typename iterator_traits<_InputIter>::value_type,
_EqualityComparable);
if (__first == __last) return __result; if (__first == __last) return __result;
return __unique_copy(__first, __last, __result, return __unique_copy(__first, __last, __result,
__ITERATOR_CATEGORY(__result)); __ITERATOR_CATEGORY(__result));
...@@ -602,6 +708,7 @@ template <class _InputIter, class _OutputIter, class _BinaryPredicate, ...@@ -602,6 +708,7 @@ template <class _InputIter, class _OutputIter, class _BinaryPredicate,
_OutputIter __unique_copy(_InputIter __first, _InputIter __last, _OutputIter __unique_copy(_InputIter __first, _InputIter __last,
_OutputIter __result, _OutputIter __result,
_BinaryPredicate __binary_pred, _Tp*) { _BinaryPredicate __binary_pred, _Tp*) {
__STL_BINARY_FUNCTION_CHECK(_BinaryPredicate, bool, _Tp, _Tp);
_Tp __value = *__first; _Tp __value = *__first;
*__result = __value; *__result = __value;
while (++__first != __last) while (++__first != __last)
...@@ -626,6 +733,9 @@ _ForwardIter __unique_copy(_InputIter __first, _InputIter __last, ...@@ -626,6 +733,9 @@ _ForwardIter __unique_copy(_InputIter __first, _InputIter __last,
_ForwardIter __result, _ForwardIter __result,
_BinaryPredicate __binary_pred, _BinaryPredicate __binary_pred,
forward_iterator_tag) { forward_iterator_tag) {
__STL_BINARY_FUNCTION_CHECK(_BinaryPredicate, bool,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_InputIter>::value_type);
*__result = *__first; *__result = *__first;
while (++__first != __last) while (++__first != __last)
if (!__binary_pred(*__result, *__first)) *++__result = *__first; if (!__binary_pred(*__result, *__first)) *++__result = *__first;
...@@ -636,6 +746,8 @@ template <class _InputIter, class _OutputIter, class _BinaryPredicate> ...@@ -636,6 +746,8 @@ template <class _InputIter, class _OutputIter, class _BinaryPredicate>
inline _OutputIter unique_copy(_InputIter __first, _InputIter __last, inline _OutputIter unique_copy(_InputIter __first, _InputIter __last,
_OutputIter __result, _OutputIter __result,
_BinaryPredicate __binary_pred) { _BinaryPredicate __binary_pred) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
if (__first == __last) return __result; if (__first == __last) return __result;
return __unique_copy(__first, __last, __result, __binary_pred, return __unique_copy(__first, __last, __result, __binary_pred,
__ITERATOR_CATEGORY(__result)); __ITERATOR_CATEGORY(__result));
...@@ -643,6 +755,9 @@ inline _OutputIter unique_copy(_InputIter __first, _InputIter __last, ...@@ -643,6 +755,9 @@ inline _OutputIter unique_copy(_InputIter __first, _InputIter __last,
template <class _ForwardIter> template <class _ForwardIter>
_ForwardIter unique(_ForwardIter __first, _ForwardIter __last) { _ForwardIter unique(_ForwardIter __first, _ForwardIter __last) {
__STL_REQUIRES(_ForwardIter, _Mutable_ForwardIterator);
__STL_REQUIRES(typename iterator_traits<_ForwardIter>::value_type,
_EqualityComparable);
__first = adjacent_find(__first, __last); __first = adjacent_find(__first, __last);
return unique_copy(__first, __last, __first); return unique_copy(__first, __last, __first);
} }
...@@ -650,6 +765,10 @@ _ForwardIter unique(_ForwardIter __first, _ForwardIter __last) { ...@@ -650,6 +765,10 @@ _ForwardIter unique(_ForwardIter __first, _ForwardIter __last) {
template <class _ForwardIter, class _BinaryPredicate> template <class _ForwardIter, class _BinaryPredicate>
_ForwardIter unique(_ForwardIter __first, _ForwardIter __last, _ForwardIter unique(_ForwardIter __first, _ForwardIter __last,
_BinaryPredicate __binary_pred) { _BinaryPredicate __binary_pred) {
__STL_REQUIRES(_ForwardIter, _Mutable_ForwardIterator);
__STL_BINARY_FUNCTION_CHECK(_BinaryPredicate, bool,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type);
__first = adjacent_find(__first, __last, __binary_pred); __first = adjacent_find(__first, __last, __binary_pred);
return unique_copy(__first, __last, __first, __binary_pred); return unique_copy(__first, __last, __first, __binary_pred);
} }
...@@ -675,13 +794,16 @@ void __reverse(_RandomAccessIter __first, _RandomAccessIter __last, ...@@ -675,13 +794,16 @@ void __reverse(_RandomAccessIter __first, _RandomAccessIter __last,
template <class _BidirectionalIter> template <class _BidirectionalIter>
inline void reverse(_BidirectionalIter __first, _BidirectionalIter __last) { inline void reverse(_BidirectionalIter __first, _BidirectionalIter __last) {
__STL_REQUIRES(_BidirectionalIter, _Mutable_BidirectionalIterator);
__reverse(__first, __last, __ITERATOR_CATEGORY(__first)); __reverse(__first, __last, __ITERATOR_CATEGORY(__first));
} }
template <class _BidirectionalIter, class _OutputIter> template <class _BidirectionalIter, class _OutputIter>
_OutputIter reverse_copy(_BidirectionalIter __first, _OutputIter reverse_copy(_BidirectionalIter __first,
_BidirectionalIter __last, _BidirectionalIter __last,
_OutputIter __result) { _OutputIter __result) {
__STL_REQUIRES(_BidirectionalIter, _BidirectionalIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
while (__first != __last) { while (__first != __last) {
--__last; --__last;
*__result = *__last; *__result = *__last;
...@@ -744,6 +866,7 @@ _BidirectionalIter __rotate(_BidirectionalIter __first, ...@@ -744,6 +866,7 @@ _BidirectionalIter __rotate(_BidirectionalIter __first,
_BidirectionalIter __last, _BidirectionalIter __last,
_Distance*, _Distance*,
bidirectional_iterator_tag) { bidirectional_iterator_tag) {
__STL_REQUIRES(_BidirectionalIter, _Mutable_BidirectionalIterator);
if (__first == __middle) if (__first == __middle)
return __last; return __last;
if (__last == __middle) if (__last == __middle)
...@@ -770,7 +893,7 @@ _RandomAccessIter __rotate(_RandomAccessIter __first, ...@@ -770,7 +893,7 @@ _RandomAccessIter __rotate(_RandomAccessIter __first,
_RandomAccessIter __middle, _RandomAccessIter __middle,
_RandomAccessIter __last, _RandomAccessIter __last,
_Distance *, _Tp *) { _Distance *, _Tp *) {
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
_Distance __n = __last - __first; _Distance __n = __last - __first;
_Distance __k = __middle - __first; _Distance __k = __middle - __first;
_Distance __l = __n - __k; _Distance __l = __n - __k;
...@@ -824,6 +947,7 @@ _RandomAccessIter __rotate(_RandomAccessIter __first, ...@@ -824,6 +947,7 @@ _RandomAccessIter __rotate(_RandomAccessIter __first,
template <class _ForwardIter> template <class _ForwardIter>
inline _ForwardIter rotate(_ForwardIter __first, _ForwardIter __middle, inline _ForwardIter rotate(_ForwardIter __first, _ForwardIter __middle,
_ForwardIter __last) { _ForwardIter __last) {
__STL_REQUIRES(_ForwardIter, _Mutable_ForwardIterator);
return __rotate(__first, __middle, __last, return __rotate(__first, __middle, __last,
__DISTANCE_TYPE(__first), __DISTANCE_TYPE(__first),
__ITERATOR_CATEGORY(__first)); __ITERATOR_CATEGORY(__first));
...@@ -831,7 +955,9 @@ inline _ForwardIter rotate(_ForwardIter __first, _ForwardIter __middle, ...@@ -831,7 +955,9 @@ inline _ForwardIter rotate(_ForwardIter __first, _ForwardIter __middle,
template <class _ForwardIter, class _OutputIter> template <class _ForwardIter, class _OutputIter>
_OutputIter rotate_copy(_ForwardIter __first, _ForwardIter __middle, _OutputIter rotate_copy(_ForwardIter __first, _ForwardIter __middle,
_ForwardIter __last, _OutputIter __result) { _ForwardIter __last, _OutputIter __result) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
return copy(__first, __middle, copy(__middle, __last, __result)); return copy(__first, __middle, copy(__middle, __last, __result));
} }
...@@ -853,6 +979,7 @@ inline _Distance __random_number(_Distance __n) { ...@@ -853,6 +979,7 @@ inline _Distance __random_number(_Distance __n) {
template <class _RandomAccessIter> template <class _RandomAccessIter>
inline void random_shuffle(_RandomAccessIter __first, inline void random_shuffle(_RandomAccessIter __first,
_RandomAccessIter __last) { _RandomAccessIter __last) {
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
if (__first == __last) return; if (__first == __last) return;
for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i) for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i)
iter_swap(__i, __first + __random_number((__i - __first) + 1)); iter_swap(__i, __first + __random_number((__i - __first) + 1));
...@@ -861,6 +988,7 @@ inline void random_shuffle(_RandomAccessIter __first, ...@@ -861,6 +988,7 @@ inline void random_shuffle(_RandomAccessIter __first,
template <class _RandomAccessIter, class _RandomNumberGenerator> template <class _RandomAccessIter, class _RandomNumberGenerator>
void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last, void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last,
_RandomNumberGenerator& __rand) { _RandomNumberGenerator& __rand) {
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
if (__first == __last) return; if (__first == __last) return;
for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i) for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i)
iter_swap(__i, __first + __rand((__i - __first) + 1)); iter_swap(__i, __first + __rand((__i - __first) + 1));
...@@ -872,6 +1000,8 @@ template <class _ForwardIter, class _OutputIter, class _Distance> ...@@ -872,6 +1000,8 @@ template <class _ForwardIter, class _OutputIter, class _Distance>
_OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last, _OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
_OutputIter __out, const _Distance __n) _OutputIter __out, const _Distance __n)
{ {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
_Distance __remaining = 0; _Distance __remaining = 0;
distance(__first, __last, __remaining); distance(__first, __last, __remaining);
_Distance __m = min(__n, __remaining); _Distance __m = min(__n, __remaining);
...@@ -895,6 +1025,9 @@ _OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last, ...@@ -895,6 +1025,9 @@ _OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
_OutputIter __out, const _Distance __n, _OutputIter __out, const _Distance __n,
_RandomNumberGenerator& __rand) _RandomNumberGenerator& __rand)
{ {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_UNARY_FUNCTION_CHECK(_RandomNumberGenerator, _Distance, _Distance);
_Distance __remaining = 0; _Distance __remaining = 0;
distance(__first, __last, __remaining); distance(__first, __last, __remaining);
_Distance __m = min(__n, __remaining); _Distance __m = min(__n, __remaining);
...@@ -940,6 +1073,7 @@ _RandomAccessIter __random_sample(_InputIter __first, _InputIter __last, ...@@ -940,6 +1073,7 @@ _RandomAccessIter __random_sample(_InputIter __first, _InputIter __last,
_RandomNumberGenerator& __rand, _RandomNumberGenerator& __rand,
const _Distance __n) const _Distance __n)
{ {
__STL_UNARY_FUNCTION_CHECK(_RandomNumberGenerator, _Distance, _Distance);
_Distance __m = 0; _Distance __m = 0;
_Distance __t = __n; _Distance __t = __n;
for ( ; __first != __last && __m < __n; ++__m, ++__first) for ( ; __first != __last && __m < __n; ++__m, ++__first)
...@@ -961,6 +1095,8 @@ inline _RandomAccessIter ...@@ -961,6 +1095,8 @@ inline _RandomAccessIter
random_sample(_InputIter __first, _InputIter __last, random_sample(_InputIter __first, _InputIter __last,
_RandomAccessIter __out_first, _RandomAccessIter __out_last) _RandomAccessIter __out_first, _RandomAccessIter __out_last)
{ {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
return __random_sample(__first, __last, return __random_sample(__first, __last,
__out_first, __out_last - __out_first); __out_first, __out_last - __out_first);
} }
...@@ -973,6 +1109,8 @@ random_sample(_InputIter __first, _InputIter __last, ...@@ -973,6 +1109,8 @@ random_sample(_InputIter __first, _InputIter __last,
_RandomAccessIter __out_first, _RandomAccessIter __out_last, _RandomAccessIter __out_first, _RandomAccessIter __out_last,
_RandomNumberGenerator& __rand) _RandomNumberGenerator& __rand)
{ {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
return __random_sample(__first, __last, return __random_sample(__first, __last,
__out_first, __rand, __out_first, __rand,
__out_last - __out_first); __out_last - __out_first);
...@@ -1031,6 +1169,9 @@ template <class _ForwardIter, class _Predicate> ...@@ -1031,6 +1169,9 @@ template <class _ForwardIter, class _Predicate>
inline _ForwardIter partition(_ForwardIter __first, inline _ForwardIter partition(_ForwardIter __first,
_ForwardIter __last, _ForwardIter __last,
_Predicate __pred) { _Predicate __pred) {
__STL_REQUIRES(_ForwardIter, _Mutable_ForwardIterator);
__STL_UNARY_FUNCTION_CHECK(_Predicate, bool,
typename iterator_traits<_ForwardIter>::value_type);
return __partition(__first, __last, __pred, __ITERATOR_CATEGORY(__first)); return __partition(__first, __last, __pred, __ITERATOR_CATEGORY(__first));
} }
...@@ -1105,6 +1246,9 @@ template <class _ForwardIter, class _Predicate> ...@@ -1105,6 +1246,9 @@ template <class _ForwardIter, class _Predicate>
inline _ForwardIter stable_partition(_ForwardIter __first, inline _ForwardIter stable_partition(_ForwardIter __first,
_ForwardIter __last, _ForwardIter __last,
_Predicate __pred) { _Predicate __pred) {
__STL_REQUIRES(_ForwardIter, _Mutable_ForwardIterator);
__STL_UNARY_FUNCTION_CHECK(_Predicate, bool,
typename iterator_traits<_ForwardIter>::value_type);
if (__first == __last) if (__first == __last)
return __first; return __first;
else else
...@@ -1320,6 +1464,9 @@ void __introsort_loop(_RandomAccessIter __first, ...@@ -1320,6 +1464,9 @@ void __introsort_loop(_RandomAccessIter __first,
template <class _RandomAccessIter> template <class _RandomAccessIter>
inline void sort(_RandomAccessIter __first, _RandomAccessIter __last) { inline void sort(_RandomAccessIter __first, _RandomAccessIter __last) {
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
__STL_REQUIRES(typename iterator_traits<_RandomAccessIter>::value_type,
_LessThanComparable);
if (__first != __last) { if (__first != __last) {
__introsort_loop(__first, __last, __introsort_loop(__first, __last,
__VALUE_TYPE(__first), __VALUE_TYPE(__first),
...@@ -1331,6 +1478,10 @@ inline void sort(_RandomAccessIter __first, _RandomAccessIter __last) { ...@@ -1331,6 +1478,10 @@ inline void sort(_RandomAccessIter __first, _RandomAccessIter __last) {
template <class _RandomAccessIter, class _Compare> template <class _RandomAccessIter, class _Compare>
inline void sort(_RandomAccessIter __first, _RandomAccessIter __last, inline void sort(_RandomAccessIter __first, _RandomAccessIter __last,
_Compare __comp) { _Compare __comp) {
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type);
if (__first != __last) { if (__first != __last) {
__introsort_loop(__first, __last, __introsort_loop(__first, __last,
__VALUE_TYPE(__first), __VALUE_TYPE(__first),
...@@ -1546,6 +1697,9 @@ inline void __stable_sort_aux(_RandomAccessIter __first, ...@@ -1546,6 +1697,9 @@ inline void __stable_sort_aux(_RandomAccessIter __first,
template <class _RandomAccessIter> template <class _RandomAccessIter>
inline void stable_sort(_RandomAccessIter __first, inline void stable_sort(_RandomAccessIter __first,
_RandomAccessIter __last) { _RandomAccessIter __last) {
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
__STL_REQUIRES(typename iterator_traits<_RandomAccessIter>::value_type,
_LessThanComparable);
__stable_sort_aux(__first, __last, __stable_sort_aux(__first, __last,
__VALUE_TYPE(__first), __VALUE_TYPE(__first),
__DISTANCE_TYPE(__first)); __DISTANCE_TYPE(__first));
...@@ -1554,6 +1708,10 @@ inline void stable_sort(_RandomAccessIter __first, ...@@ -1554,6 +1708,10 @@ inline void stable_sort(_RandomAccessIter __first,
template <class _RandomAccessIter, class _Compare> template <class _RandomAccessIter, class _Compare>
inline void stable_sort(_RandomAccessIter __first, inline void stable_sort(_RandomAccessIter __first,
_RandomAccessIter __last, _Compare __comp) { _RandomAccessIter __last, _Compare __comp) {
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type);
__stable_sort_aux(__first, __last, __stable_sort_aux(__first, __last,
__VALUE_TYPE(__first), __VALUE_TYPE(__first),
__DISTANCE_TYPE(__first), __DISTANCE_TYPE(__first),
...@@ -1577,6 +1735,9 @@ template <class _RandomAccessIter> ...@@ -1577,6 +1735,9 @@ template <class _RandomAccessIter>
inline void partial_sort(_RandomAccessIter __first, inline void partial_sort(_RandomAccessIter __first,
_RandomAccessIter __middle, _RandomAccessIter __middle,
_RandomAccessIter __last) { _RandomAccessIter __last) {
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
__STL_REQUIRES(typename iterator_traits<_RandomAccessIter>::value_type,
_LessThanComparable);
__partial_sort(__first, __middle, __last, __VALUE_TYPE(__first)); __partial_sort(__first, __middle, __last, __VALUE_TYPE(__first));
} }
...@@ -1595,16 +1756,20 @@ template <class _RandomAccessIter, class _Compare> ...@@ -1595,16 +1756,20 @@ template <class _RandomAccessIter, class _Compare>
inline void partial_sort(_RandomAccessIter __first, inline void partial_sort(_RandomAccessIter __first,
_RandomAccessIter __middle, _RandomAccessIter __middle,
_RandomAccessIter __last, _Compare __comp) { _RandomAccessIter __last, _Compare __comp) {
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type);
__partial_sort(__first, __middle, __last, __VALUE_TYPE(__first), __comp); __partial_sort(__first, __middle, __last, __VALUE_TYPE(__first), __comp);
} }
template <class _InputIter, class _RandomAccessIter, class _Distance, template <class _InputIter, class _RandomAccessIter, class _Distance,
class _Tp> class _Tp>
_RandomAccessIter __partial_sort_copy(_InputIter __first, _RandomAccessIter __partial_sort_copy(_InputIter __first,
_InputIter __last, _InputIter __last,
_RandomAccessIter __result_first, _RandomAccessIter __result_first,
_RandomAccessIter __result_last, _RandomAccessIter __result_last,
_Distance*, _Tp*) { _Distance*, _Tp*) {
if (__result_first == __result_last) return __result_last; if (__result_first == __result_last) return __result_last;
_RandomAccessIter __result_real_last = __result_first; _RandomAccessIter __result_real_last = __result_first;
while(__first != __last && __result_real_last != __result_last) { while(__first != __last && __result_real_last != __result_last) {
...@@ -1629,6 +1794,14 @@ inline _RandomAccessIter ...@@ -1629,6 +1794,14 @@ inline _RandomAccessIter
partial_sort_copy(_InputIter __first, _InputIter __last, partial_sort_copy(_InputIter __first, _InputIter __last,
_RandomAccessIter __result_first, _RandomAccessIter __result_first,
_RandomAccessIter __result_last) { _RandomAccessIter __result_last) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
__STL_CONVERTIBLE(typename iterator_traits<_InputIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type);
__STL_REQUIRES(typename iterator_traits<_RandomAccessIter>::value_type,
_LessThanComparable);
__STL_REQUIRES(typename iterator_traits<_InputIter>::value_type,
_LessThanComparable);
return __partial_sort_copy(__first, __last, __result_first, __result_last, return __partial_sort_copy(__first, __last, __result_first, __result_last,
__DISTANCE_TYPE(__result_first), __DISTANCE_TYPE(__result_first),
__VALUE_TYPE(__first)); __VALUE_TYPE(__first));
...@@ -1666,6 +1839,13 @@ inline _RandomAccessIter ...@@ -1666,6 +1839,13 @@ inline _RandomAccessIter
partial_sort_copy(_InputIter __first, _InputIter __last, partial_sort_copy(_InputIter __first, _InputIter __last,
_RandomAccessIter __result_first, _RandomAccessIter __result_first,
_RandomAccessIter __result_last, _Compare __comp) { _RandomAccessIter __result_last, _Compare __comp) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
__STL_CONVERTIBLE(typename iterator_traits<_InputIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type);
return __partial_sort_copy(__first, __last, __result_first, __result_last, return __partial_sort_copy(__first, __last, __result_first, __result_last,
__comp, __comp,
__DISTANCE_TYPE(__result_first), __DISTANCE_TYPE(__result_first),
...@@ -1694,6 +1874,9 @@ void __nth_element(_RandomAccessIter __first, _RandomAccessIter __nth, ...@@ -1694,6 +1874,9 @@ void __nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
template <class _RandomAccessIter> template <class _RandomAccessIter>
inline void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth, inline void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
_RandomAccessIter __last) { _RandomAccessIter __last) {
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
__STL_REQUIRES(typename iterator_traits<_RandomAccessIter>::value_type,
_LessThanComparable);
__nth_element(__first, __nth, __last, __VALUE_TYPE(__first)); __nth_element(__first, __nth, __last, __VALUE_TYPE(__first));
} }
...@@ -1718,7 +1901,11 @@ void __nth_element(_RandomAccessIter __first, _RandomAccessIter __nth, ...@@ -1718,7 +1901,11 @@ void __nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
template <class _RandomAccessIter, class _Compare> template <class _RandomAccessIter, class _Compare>
inline void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth, inline void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
_RandomAccessIter __last, _Compare __comp) { _RandomAccessIter __last, _Compare __comp) {
__STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type);
__nth_element(__first, __nth, __last, __VALUE_TYPE(__first), __comp); __nth_element(__first, __nth, __last, __VALUE_TYPE(__first), __comp);
} }
...@@ -1751,7 +1938,11 @@ _ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last, ...@@ -1751,7 +1938,11 @@ _ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
template <class _ForwardIter, class _Tp> template <class _ForwardIter, class _Tp>
inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last, inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val) { const _Tp& __val) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES_SAME_TYPE(_Tp,
typename iterator_traits<_ForwardIter>::value_type);
__STL_REQUIRES(_Tp, _LessThanComparable);
return __lower_bound(__first, __last, __val, return __lower_bound(__first, __last, __val,
__DISTANCE_TYPE(__first)); __DISTANCE_TYPE(__first));
} }
...@@ -1783,6 +1974,10 @@ _ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last, ...@@ -1783,6 +1974,10 @@ _ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
template <class _ForwardIter, class _Tp, class _Compare> template <class _ForwardIter, class _Tp, class _Compare>
inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last, inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val, _Compare __comp) { const _Tp& __val, _Compare __comp) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES_SAME_TYPE(_Tp,
typename iterator_traits<_ForwardIter>::value_type);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool, _Tp, _Tp);
return __lower_bound(__first, __last, __val, __comp, return __lower_bound(__first, __last, __val, __comp,
__DISTANCE_TYPE(__first)); __DISTANCE_TYPE(__first));
} }
...@@ -1814,6 +2009,10 @@ _ForwardIter __upper_bound(_ForwardIter __first, _ForwardIter __last, ...@@ -1814,6 +2009,10 @@ _ForwardIter __upper_bound(_ForwardIter __first, _ForwardIter __last,
template <class _ForwardIter, class _Tp> template <class _ForwardIter, class _Tp>
inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last, inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val) { const _Tp& __val) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES_SAME_TYPE(_Tp,
typename iterator_traits<_ForwardIter>::value_type);
__STL_REQUIRES(_Tp, _LessThanComparable);
return __upper_bound(__first, __last, __val, return __upper_bound(__first, __last, __val,
__DISTANCE_TYPE(__first)); __DISTANCE_TYPE(__first));
} }
...@@ -1845,6 +2044,10 @@ _ForwardIter __upper_bound(_ForwardIter __first, _ForwardIter __last, ...@@ -1845,6 +2044,10 @@ _ForwardIter __upper_bound(_ForwardIter __first, _ForwardIter __last,
template <class _ForwardIter, class _Tp, class _Compare> template <class _ForwardIter, class _Tp, class _Compare>
inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last, inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val, _Compare __comp) { const _Tp& __val, _Compare __comp) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES_SAME_TYPE(_Tp,
typename iterator_traits<_ForwardIter>::value_type);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool, _Tp, _Tp);
return __upper_bound(__first, __last, __val, __comp, return __upper_bound(__first, __last, __val, __comp,
__DISTANCE_TYPE(__first)); __DISTANCE_TYPE(__first));
} }
...@@ -1883,6 +2086,10 @@ __equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val, ...@@ -1883,6 +2086,10 @@ __equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
template <class _ForwardIter, class _Tp> template <class _ForwardIter, class _Tp>
inline pair<_ForwardIter, _ForwardIter> inline pair<_ForwardIter, _ForwardIter>
equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) { equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES_SAME_TYPE(_Tp,
typename iterator_traits<_ForwardIter>::value_type);
__STL_REQUIRES(_Tp, _LessThanComparable);
return __equal_range(__first, __last, __val, return __equal_range(__first, __last, __val,
__DISTANCE_TYPE(__first)); __DISTANCE_TYPE(__first));
} }
...@@ -1922,6 +2129,10 @@ template <class _ForwardIter, class _Tp, class _Compare> ...@@ -1922,6 +2129,10 @@ template <class _ForwardIter, class _Tp, class _Compare>
inline pair<_ForwardIter, _ForwardIter> inline pair<_ForwardIter, _ForwardIter>
equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val, equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
_Compare __comp) { _Compare __comp) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES_SAME_TYPE(_Tp,
typename iterator_traits<_ForwardIter>::value_type);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool, _Tp, _Tp);
return __equal_range(__first, __last, __val, __comp, return __equal_range(__first, __last, __val, __comp,
__DISTANCE_TYPE(__first)); __DISTANCE_TYPE(__first));
} }
...@@ -1929,6 +2140,10 @@ equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val, ...@@ -1929,6 +2140,10 @@ equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
template <class _ForwardIter, class _Tp> template <class _ForwardIter, class _Tp>
bool binary_search(_ForwardIter __first, _ForwardIter __last, bool binary_search(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val) { const _Tp& __val) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES_SAME_TYPE(_Tp,
typename iterator_traits<_ForwardIter>::value_type);
__STL_REQUIRES(_Tp, _LessThanComparable);
_ForwardIter __i = lower_bound(__first, __last, __val); _ForwardIter __i = lower_bound(__first, __last, __val);
return __i != __last && !(__val < *__i); return __i != __last && !(__val < *__i);
} }
...@@ -1937,6 +2152,10 @@ template <class _ForwardIter, class _Tp, class _Compare> ...@@ -1937,6 +2152,10 @@ template <class _ForwardIter, class _Tp, class _Compare>
bool binary_search(_ForwardIter __first, _ForwardIter __last, bool binary_search(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val, const _Tp& __val,
_Compare __comp) { _Compare __comp) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES_SAME_TYPE(_Tp,
typename iterator_traits<_ForwardIter>::value_type);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool, _Tp, _Tp);
_ForwardIter __i = lower_bound(__first, __last, __val, __comp); _ForwardIter __i = lower_bound(__first, __last, __val, __comp);
return __i != __last && !__comp(__val, *__i); return __i != __last && !__comp(__val, *__i);
} }
...@@ -1947,6 +2166,14 @@ template <class _InputIter1, class _InputIter2, class _OutputIter> ...@@ -1947,6 +2166,14 @@ template <class _InputIter1, class _InputIter2, class _OutputIter>
_OutputIter merge(_InputIter1 __first1, _InputIter1 __last1, _OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result) { _OutputIter __result) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_REQUIRES(typename iterator_traits<_InputIter1>::value_type,
_LessThanComparable);
while (__first1 != __last1 && __first2 != __last2) { while (__first1 != __last1 && __first2 != __last2) {
if (*__first2 < *__first1) { if (*__first2 < *__first1) {
*__result = *__first2; *__result = *__first2;
...@@ -1966,6 +2193,15 @@ template <class _InputIter1, class _InputIter2, class _OutputIter, ...@@ -1966,6 +2193,15 @@ template <class _InputIter1, class _InputIter2, class _OutputIter,
_OutputIter merge(_InputIter1 __first1, _InputIter1 __last1, _OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result, _Compare __comp) { _OutputIter __result, _Compare __comp) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter1>::value_type);
while (__first1 != __last1 && __first2 != __last2) { while (__first1 != __last1 && __first2 != __last2) {
if (__comp(*__first2, *__first1)) { if (__comp(*__first2, *__first1)) {
*__result = *__first2; *__result = *__first2;
...@@ -2263,6 +2499,9 @@ template <class _BidirectionalIter> ...@@ -2263,6 +2499,9 @@ template <class _BidirectionalIter>
inline void inplace_merge(_BidirectionalIter __first, inline void inplace_merge(_BidirectionalIter __first,
_BidirectionalIter __middle, _BidirectionalIter __middle,
_BidirectionalIter __last) { _BidirectionalIter __last) {
__STL_REQUIRES(_BidirectionalIter, _Mutable_BidirectionalIterator);
__STL_REQUIRES(typename iterator_traits<_BidirectionalIter>::value_type,
_LessThanComparable);
if (__first == __middle || __middle == __last) if (__first == __middle || __middle == __last)
return; return;
__inplace_merge_aux(__first, __middle, __last, __inplace_merge_aux(__first, __middle, __last,
...@@ -2273,6 +2512,10 @@ template <class _BidirectionalIter, class _Compare> ...@@ -2273,6 +2512,10 @@ template <class _BidirectionalIter, class _Compare>
inline void inplace_merge(_BidirectionalIter __first, inline void inplace_merge(_BidirectionalIter __first,
_BidirectionalIter __middle, _BidirectionalIter __middle,
_BidirectionalIter __last, _Compare __comp) { _BidirectionalIter __last, _Compare __comp) {
__STL_REQUIRES(_BidirectionalIter, _Mutable_BidirectionalIterator);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_BidirectionalIter>::value_type,
typename iterator_traits<_BidirectionalIter>::value_type);
if (__first == __middle || __middle == __last) if (__first == __middle || __middle == __last)
return; return;
__inplace_merge_aux(__first, __middle, __last, __inplace_merge_aux(__first, __middle, __last,
...@@ -2288,6 +2531,13 @@ inline void inplace_merge(_BidirectionalIter __first, ...@@ -2288,6 +2531,13 @@ inline void inplace_merge(_BidirectionalIter __first,
template <class _InputIter1, class _InputIter2> template <class _InputIter1, class _InputIter2>
bool includes(_InputIter1 __first1, _InputIter1 __last1, bool includes(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2) { _InputIter2 __first2, _InputIter2 __last2) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_REQUIRES(typename iterator_traits<_InputIter1>::value_type,
_LessThanComparable);
while (__first1 != __last1 && __first2 != __last2) while (__first1 != __last1 && __first2 != __last2)
if (*__first2 < *__first1) if (*__first2 < *__first1)
return false; return false;
...@@ -2302,6 +2552,14 @@ bool includes(_InputIter1 __first1, _InputIter1 __last1, ...@@ -2302,6 +2552,14 @@ bool includes(_InputIter1 __first1, _InputIter1 __last1,
template <class _InputIter1, class _InputIter2, class _Compare> template <class _InputIter1, class _InputIter2, class _Compare>
bool includes(_InputIter1 __first1, _InputIter1 __last1, bool includes(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _Compare __comp) { _InputIter2 __first2, _InputIter2 __last2, _Compare __comp) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
while (__first1 != __last1 && __first2 != __last2) while (__first1 != __last1 && __first2 != __last2)
if (__comp(*__first2, *__first1)) if (__comp(*__first2, *__first1))
return false; return false;
...@@ -2317,6 +2575,14 @@ template <class _InputIter1, class _InputIter2, class _OutputIter> ...@@ -2317,6 +2575,14 @@ template <class _InputIter1, class _InputIter2, class _OutputIter>
_OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1, _OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result) { _OutputIter __result) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_REQUIRES(typename iterator_traits<_InputIter1>::value_type,
_LessThanComparable);
while (__first1 != __last1 && __first2 != __last2) { while (__first1 != __last1 && __first2 != __last2) {
if (*__first1 < *__first2) { if (*__first1 < *__first2) {
*__result = *__first1; *__result = *__first1;
...@@ -2341,6 +2607,15 @@ template <class _InputIter1, class _InputIter2, class _OutputIter, ...@@ -2341,6 +2607,15 @@ template <class _InputIter1, class _InputIter2, class _OutputIter,
_OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1, _OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result, _Compare __comp) { _OutputIter __result, _Compare __comp) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
while (__first1 != __last1 && __first2 != __last2) { while (__first1 != __last1 && __first2 != __last2) {
if (__comp(*__first1, *__first2)) { if (__comp(*__first1, *__first2)) {
*__result = *__first1; *__result = *__first1;
...@@ -2364,6 +2639,14 @@ template <class _InputIter1, class _InputIter2, class _OutputIter> ...@@ -2364,6 +2639,14 @@ template <class _InputIter1, class _InputIter2, class _OutputIter>
_OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1, _OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result) { _OutputIter __result) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_REQUIRES(typename iterator_traits<_InputIter1>::value_type,
_LessThanComparable);
while (__first1 != __last1 && __first2 != __last2) while (__first1 != __last1 && __first2 != __last2)
if (*__first1 < *__first2) if (*__first1 < *__first2)
++__first1; ++__first1;
...@@ -2383,6 +2666,16 @@ template <class _InputIter1, class _InputIter2, class _OutputIter, ...@@ -2383,6 +2666,16 @@ template <class _InputIter1, class _InputIter2, class _OutputIter,
_OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1, _OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result, _Compare __comp) { _OutputIter __result, _Compare __comp) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
while (__first1 != __last1 && __first2 != __last2) while (__first1 != __last1 && __first2 != __last2)
if (__comp(*__first1, *__first2)) if (__comp(*__first1, *__first2))
++__first1; ++__first1;
...@@ -2401,6 +2694,14 @@ template <class _InputIter1, class _InputIter2, class _OutputIter> ...@@ -2401,6 +2694,14 @@ template <class _InputIter1, class _InputIter2, class _OutputIter>
_OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1, _OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result) { _OutputIter __result) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_REQUIRES(typename iterator_traits<_InputIter1>::value_type,
_LessThanComparable);
while (__first1 != __last1 && __first2 != __last2) while (__first1 != __last1 && __first2 != __last2)
if (*__first1 < *__first2) { if (*__first1 < *__first2) {
*__result = *__first1; *__result = *__first1;
...@@ -2421,6 +2722,16 @@ template <class _InputIter1, class _InputIter2, class _OutputIter, ...@@ -2421,6 +2722,16 @@ template <class _InputIter1, class _InputIter2, class _OutputIter,
_OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1, _OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result, _Compare __comp) { _OutputIter __result, _Compare __comp) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
while (__first1 != __last1 && __first2 != __last2) while (__first1 != __last1 && __first2 != __last2)
if (__comp(*__first1, *__first2)) { if (__comp(*__first1, *__first2)) {
*__result = *__first1; *__result = *__first1;
...@@ -2441,6 +2752,14 @@ _OutputIter ...@@ -2441,6 +2752,14 @@ _OutputIter
set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1, set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result) { _OutputIter __result) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_REQUIRES(typename iterator_traits<_InputIter1>::value_type,
_LessThanComparable);
while (__first1 != __last1 && __first2 != __last2) while (__first1 != __last1 && __first2 != __last2)
if (*__first1 < *__first2) { if (*__first1 < *__first2) {
*__result = *__first1; *__result = *__first1;
...@@ -2466,6 +2785,15 @@ set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1, ...@@ -2466,6 +2785,15 @@ set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result, _OutputIter __result,
_Compare __comp) { _Compare __comp) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
__STL_REQUIRES_SAME_TYPE(
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_InputIter1>::value_type,
typename iterator_traits<_InputIter2>::value_type);
while (__first1 != __last1 && __first2 != __last2) while (__first1 != __last1 && __first2 != __last2)
if (__comp(*__first1, *__first2)) { if (__comp(*__first1, *__first2)) {
*__result = *__first1; *__result = *__first1;
...@@ -2489,6 +2817,9 @@ set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1, ...@@ -2489,6 +2817,9 @@ set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
template <class _ForwardIter> template <class _ForwardIter>
_ForwardIter max_element(_ForwardIter __first, _ForwardIter __last) { _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES(typename iterator_traits<_ForwardIter>::value_type,
_LessThanComparable);
if (__first == __last) return __first; if (__first == __last) return __first;
_ForwardIter __result = __first; _ForwardIter __result = __first;
while (++__first != __last) while (++__first != __last)
...@@ -2499,7 +2830,11 @@ _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last) { ...@@ -2499,7 +2830,11 @@ _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last) {
template <class _ForwardIter, class _Compare> template <class _ForwardIter, class _Compare>
_ForwardIter max_element(_ForwardIter __first, _ForwardIter __last, _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last,
_Compare __comp) { _Compare __comp) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type);
if (__first == __last) return __first; if (__first == __last) return __first;
_ForwardIter __result = __first; _ForwardIter __result = __first;
while (++__first != __last) while (++__first != __last)
...@@ -2509,6 +2844,9 @@ _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last, ...@@ -2509,6 +2844,9 @@ _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last,
template <class _ForwardIter> template <class _ForwardIter>
_ForwardIter min_element(_ForwardIter __first, _ForwardIter __last) { _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES(typename iterator_traits<_ForwardIter>::value_type,
_LessThanComparable);
if (__first == __last) return __first; if (__first == __last) return __first;
_ForwardIter __result = __first; _ForwardIter __result = __first;
while (++__first != __last) while (++__first != __last)
...@@ -2519,7 +2857,11 @@ _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last) { ...@@ -2519,7 +2857,11 @@ _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last) {
template <class _ForwardIter, class _Compare> template <class _ForwardIter, class _Compare>
_ForwardIter min_element(_ForwardIter __first, _ForwardIter __last, _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last,
_Compare __comp) { _Compare __comp) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type);
if (__first == __last) return __first; if (__first == __last) return __first;
_ForwardIter __result = __first; _ForwardIter __result = __first;
while (++__first != __last) while (++__first != __last)
...@@ -2533,6 +2875,9 @@ _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last, ...@@ -2533,6 +2875,9 @@ _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last,
template <class _BidirectionalIter> template <class _BidirectionalIter>
bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last) { bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last) {
__STL_REQUIRES(_BidirectionalIter, _BidirectionalIterator);
__STL_REQUIRES(typename iterator_traits<_BidirectionalIter>::value_type,
_LessThanComparable);
if (__first == __last) if (__first == __last)
return false; return false;
_BidirectionalIter __i = __first; _BidirectionalIter __i = __first;
...@@ -2563,6 +2908,10 @@ bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last) { ...@@ -2563,6 +2908,10 @@ bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last) {
template <class _BidirectionalIter, class _Compare> template <class _BidirectionalIter, class _Compare>
bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last, bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
_Compare __comp) { _Compare __comp) {
__STL_REQUIRES(_BidirectionalIter, _BidirectionalIterator);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_BidirectionalIter>::value_type,
typename iterator_traits<_BidirectionalIter>::value_type);
if (__first == __last) if (__first == __last)
return false; return false;
_BidirectionalIter __i = __first; _BidirectionalIter __i = __first;
...@@ -2592,6 +2941,9 @@ bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last, ...@@ -2592,6 +2941,9 @@ bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
template <class _BidirectionalIter> template <class _BidirectionalIter>
bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last) { bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last) {
__STL_REQUIRES(_BidirectionalIter, _BidirectionalIterator);
__STL_REQUIRES(typename iterator_traits<_BidirectionalIter>::value_type,
_LessThanComparable);
if (__first == __last) if (__first == __last)
return false; return false;
_BidirectionalIter __i = __first; _BidirectionalIter __i = __first;
...@@ -2622,6 +2974,10 @@ bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last) { ...@@ -2622,6 +2974,10 @@ bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last) {
template <class _BidirectionalIter, class _Compare> template <class _BidirectionalIter, class _Compare>
bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last, bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
_Compare __comp) { _Compare __comp) {
__STL_REQUIRES(_BidirectionalIter, _BidirectionalIterator);
__STL_BINARY_FUNCTION_CHECK(_Compare, bool,
typename iterator_traits<_BidirectionalIter>::value_type,
typename iterator_traits<_BidirectionalIter>::value_type);
if (__first == __last) if (__first == __last)
return false; return false;
_BidirectionalIter __i = __first; _BidirectionalIter __i = __first;
...@@ -2655,6 +3011,12 @@ template <class _InputIter, class _ForwardIter> ...@@ -2655,6 +3011,12 @@ template <class _InputIter, class _ForwardIter>
_InputIter find_first_of(_InputIter __first1, _InputIter __last1, _InputIter find_first_of(_InputIter __first1, _InputIter __last1,
_ForwardIter __first2, _ForwardIter __last2) _ForwardIter __first2, _ForwardIter __last2)
{ {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES_BINARY_OP(_OP_EQUAL, bool,
typename iterator_traits<_InputIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type);
for ( ; __first1 != __last1; ++__first1) for ( ; __first1 != __last1; ++__first1)
for (_ForwardIter __iter = __first2; __iter != __last2; ++__iter) for (_ForwardIter __iter = __first2; __iter != __last2; ++__iter)
if (*__first1 == *__iter) if (*__first1 == *__iter)
...@@ -2667,6 +3029,12 @@ _InputIter find_first_of(_InputIter __first1, _InputIter __last1, ...@@ -2667,6 +3029,12 @@ _InputIter find_first_of(_InputIter __first1, _InputIter __last1,
_ForwardIter __first2, _ForwardIter __last2, _ForwardIter __first2, _ForwardIter __last2,
_BinaryPredicate __comp) _BinaryPredicate __comp)
{ {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_BINARY_FUNCTION_CHECK(_BinaryPredicate, bool,
typename iterator_traits<_InputIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type);
for ( ; __first1 != __last1; ++__first1) for ( ; __first1 != __last1; ++__first1)
for (_ForwardIter __iter = __first2; __iter != __last2; ++__iter) for (_ForwardIter __iter = __first2; __iter != __last2; ++__iter)
if (__comp(*__first1, *__iter)) if (__comp(*__first1, *__iter))
...@@ -2738,6 +3106,8 @@ __find_end(_BidirectionalIter1 __first1, _BidirectionalIter1 __last1, ...@@ -2738,6 +3106,8 @@ __find_end(_BidirectionalIter1 __first1, _BidirectionalIter1 __last1,
_BidirectionalIter2 __first2, _BidirectionalIter2 __last2, _BidirectionalIter2 __first2, _BidirectionalIter2 __last2,
bidirectional_iterator_tag, bidirectional_iterator_tag) bidirectional_iterator_tag, bidirectional_iterator_tag)
{ {
__STL_REQUIRES(_BidirectionalIter1, _BidirectionalIterator);
__STL_REQUIRES(_BidirectionalIter2, _BidirectionalIterator);
typedef reverse_iterator<_BidirectionalIter1> _RevIter1; typedef reverse_iterator<_BidirectionalIter1> _RevIter1;
typedef reverse_iterator<_BidirectionalIter2> _RevIter2; typedef reverse_iterator<_BidirectionalIter2> _RevIter2;
...@@ -2763,6 +3133,8 @@ __find_end(_BidirectionalIter1 __first1, _BidirectionalIter1 __last1, ...@@ -2763,6 +3133,8 @@ __find_end(_BidirectionalIter1 __first1, _BidirectionalIter1 __last1,
bidirectional_iterator_tag, bidirectional_iterator_tag, bidirectional_iterator_tag, bidirectional_iterator_tag,
_BinaryPredicate __comp) _BinaryPredicate __comp)
{ {
__STL_REQUIRES(_BidirectionalIter1, _BidirectionalIterator);
__STL_REQUIRES(_BidirectionalIter2, _BidirectionalIterator);
typedef reverse_iterator<_BidirectionalIter1> _RevIter1; typedef reverse_iterator<_BidirectionalIter1> _RevIter1;
typedef reverse_iterator<_BidirectionalIter2> _RevIter2; typedef reverse_iterator<_BidirectionalIter2> _RevIter2;
...@@ -2789,6 +3161,11 @@ inline _ForwardIter1 ...@@ -2789,6 +3161,11 @@ inline _ForwardIter1
find_end(_ForwardIter1 __first1, _ForwardIter1 __last1, find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2) _ForwardIter2 __first2, _ForwardIter2 __last2)
{ {
__STL_REQUIRES(_ForwardIter1, _ForwardIterator);
__STL_REQUIRES(_ForwardIter2, _ForwardIterator);
__STL_REQUIRES_BINARY_OP(_OP_EQUAL, bool,
typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type);
return __find_end(__first1, __last1, __first2, __last2, return __find_end(__first1, __last1, __first2, __last2,
__ITERATOR_CATEGORY(__first1), __ITERATOR_CATEGORY(__first1),
__ITERATOR_CATEGORY(__first2)); __ITERATOR_CATEGORY(__first2));
...@@ -2801,6 +3178,12 @@ find_end(_ForwardIter1 __first1, _ForwardIter1 __last1, ...@@ -2801,6 +3178,12 @@ find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2, _ForwardIter2 __first2, _ForwardIter2 __last2,
_BinaryPredicate __comp) _BinaryPredicate __comp)
{ {
__STL_REQUIRES(_ForwardIter1, _ForwardIterator);
__STL_REQUIRES(_ForwardIter2, _ForwardIterator);
__STL_BINARY_FUNCTION_CHECK(_BinaryPredicate, bool,
typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type);
return __find_end(__first1, __last1, __first2, __last2, return __find_end(__first1, __last1, __first2, __last2,
__ITERATOR_CATEGORY(__first1), __ITERATOR_CATEGORY(__first1),
__ITERATOR_CATEGORY(__first2), __ITERATOR_CATEGORY(__first2),
...@@ -2841,6 +3224,9 @@ bool __is_heap(_RandomAccessIter __first, _StrictWeakOrdering __comp, ...@@ -2841,6 +3224,9 @@ bool __is_heap(_RandomAccessIter __first, _StrictWeakOrdering __comp,
template <class _RandomAccessIter> template <class _RandomAccessIter>
inline bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last) inline bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last)
{ {
__STL_REQUIRES(_RandomAccessIter, _RandomAccessIterator);
__STL_REQUIRES(typename iterator_traits<_RandomAccessIter>::value_type,
_LessThanComparable);
return __is_heap(__first, __last - __first); return __is_heap(__first, __last - __first);
} }
...@@ -2849,6 +3235,10 @@ template <class _RandomAccessIter, class _StrictWeakOrdering> ...@@ -2849,6 +3235,10 @@ template <class _RandomAccessIter, class _StrictWeakOrdering>
inline bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last, inline bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last,
_StrictWeakOrdering __comp) _StrictWeakOrdering __comp)
{ {
__STL_REQUIRES(_RandomAccessIter, _RandomAccessIterator);
__STL_BINARY_FUNCTION_CHECK(_StrictWeakOrdering, bool,
typename iterator_traits<_RandomAccessIter>::value_type,
typename iterator_traits<_RandomAccessIter>::value_type);
return __is_heap(__first, __comp, __last - __first); return __is_heap(__first, __comp, __last - __first);
} }
...@@ -2859,6 +3249,9 @@ inline bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last, ...@@ -2859,6 +3249,9 @@ inline bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last,
template <class _ForwardIter> template <class _ForwardIter>
bool is_sorted(_ForwardIter __first, _ForwardIter __last) bool is_sorted(_ForwardIter __first, _ForwardIter __last)
{ {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES(typename iterator_traits<_ForwardIter>::value_type,
_LessThanComparable);
if (__first == __last) if (__first == __last)
return true; return true;
...@@ -2875,6 +3268,10 @@ template <class _ForwardIter, class _StrictWeakOrdering> ...@@ -2875,6 +3268,10 @@ template <class _ForwardIter, class _StrictWeakOrdering>
bool is_sorted(_ForwardIter __first, _ForwardIter __last, bool is_sorted(_ForwardIter __first, _ForwardIter __last,
_StrictWeakOrdering __comp) _StrictWeakOrdering __comp)
{ {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_BINARY_FUNCTION_CHECK(_StrictWeakOrdering, bool,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type);
if (__first == __last) if (__first == __last)
return true; return true;
......
...@@ -34,9 +34,12 @@ ...@@ -34,9 +34,12 @@
#include <bits/stl_config.h> #include <bits/stl_config.h>
#include <bits/stl_relops.h> #include <bits/stl_relops.h>
#ifndef __SGI_STL_INTERNAL_PAIR_H
#include <bits/stl_pair.h> #include <bits/stl_pair.h>
#endif
#ifndef _CPP_BITS_TYPE_TRAITS_H
#include <bits/type_traits.h> #include <bits/type_traits.h>
#endif
#include <bits/std_cstring.h> #include <bits/std_cstring.h>
#include <bits/std_climits.h> #include <bits/std_climits.h>
#include <bits/std_cstdlib.h> #include <bits/std_cstdlib.h>
...@@ -52,6 +55,8 @@ ...@@ -52,6 +55,8 @@
#include <bits/stl_iterator_base.h> #include <bits/stl_iterator_base.h>
#include <bits/stl_iterator.h> #include <bits/stl_iterator.h>
// We pick up concept_checks.h from stl_iterator_base.h.
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
// swap and iter_swap // swap and iter_swap
...@@ -65,11 +70,18 @@ inline void __iter_swap(_ForwardIter1 __a, _ForwardIter2 __b, _Tp*) { ...@@ -65,11 +70,18 @@ inline void __iter_swap(_ForwardIter1 __a, _ForwardIter2 __b, _Tp*) {
template <class _ForwardIter1, class _ForwardIter2> template <class _ForwardIter1, class _ForwardIter2>
inline void iter_swap(_ForwardIter1 __a, _ForwardIter2 __b) { inline void iter_swap(_ForwardIter1 __a, _ForwardIter2 __b) {
__STL_REQUIRES(_ForwardIter1, _Mutable_ForwardIterator);
__STL_REQUIRES(_ForwardIter2, _Mutable_ForwardIterator);
__STL_CONVERTIBLE(typename iterator_traits<_ForwardIter1>::value_type,
typename iterator_traits<_ForwardIter2>::value_type);
__STL_CONVERTIBLE(typename iterator_traits<_ForwardIter2>::value_type,
typename iterator_traits<_ForwardIter1>::value_type);
__iter_swap(__a, __b, __VALUE_TYPE(__a)); __iter_swap(__a, __b, __VALUE_TYPE(__a));
} }
template <class _Tp> template <class _Tp>
inline void swap(_Tp& __a, _Tp& __b) { inline void swap(_Tp& __a, _Tp& __b) {
__STL_REQUIRES(_Tp, _Assignable);
_Tp __tmp = __a; _Tp __tmp = __a;
__a = __b; __a = __b;
__b = __tmp; __b = __tmp;
...@@ -78,19 +90,21 @@ inline void swap(_Tp& __a, _Tp& __b) { ...@@ -78,19 +90,21 @@ inline void swap(_Tp& __a, _Tp& __b) {
//-------------------------------------------------- //--------------------------------------------------
// min and max // min and max
#ifndef __BORLANDC__ #if !defined(__BORLANDC__) || __BORLANDC__ >= 0x540 /* C++ Builder 4.0 */
#undef min #undef min
#undef max #undef max
template <class _Tp> template <class _Tp>
inline const _Tp& min(const _Tp& __a, const _Tp& __b) { inline const _Tp& min(const _Tp& __a, const _Tp& __b) {
__STL_REQUIRES(_Tp, _LessThanComparable);
//return __b < __a ? __b : __a; //return __b < __a ? __b : __a;
if (__b < __a) return __b; return __a; if (__b < __a) return __b; return __a;
} }
template <class _Tp> template <class _Tp>
inline const _Tp& max(const _Tp& __a, const _Tp& __b) { inline const _Tp& max(const _Tp& __a, const _Tp& __b) {
__STL_REQUIRES(_Tp, _LessThanComparable);
//return __a < __b ? __b : __a; //return __a < __b ? __b : __a;
if (__a < __b) return __b; return __a; if (__a < __b) return __b; return __a;
} }
...@@ -166,12 +180,16 @@ inline _OutputIter __copy_aux2(_InputIter __first, _InputIter __last, ...@@ -166,12 +180,16 @@ inline _OutputIter __copy_aux2(_InputIter __first, _InputIter __last,
__DISTANCE_TYPE(__first)); __DISTANCE_TYPE(__first));
} }
#ifndef __USLC__
template <class _Tp> template <class _Tp>
inline _Tp* __copy_aux2(_Tp* __first, _Tp* __last, _Tp* __result, inline _Tp* __copy_aux2(_Tp* __first, _Tp* __last, _Tp* __result,
__true_type) { __true_type) {
return __copy_trivial(__first, __last, __result); return __copy_trivial(__first, __last, __result);
} }
#endif /* __USLC__ */
template <class _Tp> template <class _Tp>
inline _Tp* __copy_aux2(const _Tp* __first, const _Tp* __last, _Tp* __result, inline _Tp* __copy_aux2(const _Tp* __first, const _Tp* __last, _Tp* __result,
__true_type) { __true_type) {
...@@ -217,6 +235,8 @@ inline _OutputIter __copy_ni1(_InputIter __first, _InputIter __last, ...@@ -217,6 +235,8 @@ inline _OutputIter __copy_ni1(_InputIter __first, _InputIter __last,
template <class _InputIter, class _OutputIter> template <class _InputIter, class _OutputIter>
inline _OutputIter copy(_InputIter __first, _InputIter __last, inline _OutputIter copy(_InputIter __first, _InputIter __last,
_OutputIter __result) { _OutputIter __result) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
typedef typename _Is_normal_iterator<_InputIter>::_Normal __Normal; typedef typename _Is_normal_iterator<_InputIter>::_Normal __Normal;
return __copy_ni1(__first, __last, __result, __Normal()); return __copy_ni1(__first, __last, __result, __Normal());
} }
...@@ -254,6 +274,8 @@ struct __copy_dispatch<const _Tp*, _Tp*, __true_type> ...@@ -254,6 +274,8 @@ struct __copy_dispatch<const _Tp*, _Tp*, __true_type>
template <class _InputIter, class _OutputIter> template <class _InputIter, class _OutputIter>
inline _OutputIter copy(_InputIter __first, _InputIter __last, inline _OutputIter copy(_InputIter __first, _InputIter __last,
_OutputIter __result) { _OutputIter __result) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
typedef typename iterator_traits<_InputIter>::value_type _Tp; typedef typename iterator_traits<_InputIter>::value_type _Tp;
typedef typename __type_traits<_Tp>::has_trivial_assignment_operator typedef typename __type_traits<_Tp>::has_trivial_assignment_operator
_Trivial; _Trivial;
...@@ -277,7 +299,8 @@ inline _OutputIter copy(_InputIter __first, _InputIter __last, ...@@ -277,7 +299,8 @@ inline _OutputIter copy(_InputIter __first, _InputIter __last,
#define __SGI_STL_DECLARE_COPY_TRIVIAL(_Tp) \ #define __SGI_STL_DECLARE_COPY_TRIVIAL(_Tp) \
inline _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) { \ inline _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) { \
return __copy_trivial(__first, __last, __result); \ memmove(__result, __first, sizeof(_Tp) * (__last - __first)); \
return __result + (__last - __first); \
} }
__SGI_STL_DECLARE_COPY_TRIVIAL(char) __SGI_STL_DECLARE_COPY_TRIVIAL(char)
...@@ -412,6 +435,10 @@ inline _BI2 __copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last, ...@@ -412,6 +435,10 @@ inline _BI2 __copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last,
template <typename _BI1, typename _BI2> template <typename _BI1, typename _BI2>
inline _BI2 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result) { inline _BI2 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result) {
__STL_REQUIRES(_BI1, _BidirectionalIterator);
__STL_REQUIRES(_BI2, _Mutable_BidirectionalIterator);
__STL_CONVERTIBLE(typename iterator_traits<_BI1>::value_type,
typename iterator_traits<_BI2>::value_type);
typedef typename _Is_normal_iterator<_BI1>::_Normal __Normal; typedef typename _Is_normal_iterator<_BI1>::_Normal __Normal;
return __copy_backward_input_normal_iterator(__first, __last, __result, return __copy_backward_input_normal_iterator(__first, __last, __result,
__Normal()); __Normal());
...@@ -462,6 +489,8 @@ __copy_n(_InputIter __first, _Size __count, _OutputIter __result) { ...@@ -462,6 +489,8 @@ __copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
template <class _InputIter, class _Size, class _OutputIter> template <class _InputIter, class _Size, class _OutputIter>
inline pair<_InputIter, _OutputIter> inline pair<_InputIter, _OutputIter>
copy_n(_InputIter __first, _Size __count, _OutputIter __result) { copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(_OutputIter, _OutputIterator);
return __copy_n(__first, __count, __result); return __copy_n(__first, __count, __result);
} }
...@@ -471,17 +500,62 @@ copy_n(_InputIter __first, _Size __count, _OutputIter __result) { ...@@ -471,17 +500,62 @@ copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
template <class _ForwardIter, class _Tp> template <class _ForwardIter, class _Tp>
void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __value) { void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __value) {
__STL_REQUIRES(_ForwardIter, _Mutable_ForwardIterator);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
*__first = __value; *__first = __value;
} }
template <class _OutputIter, class _Size, class _Tp> template <class _OutputIter, class _Size, class _Tp>
_OutputIter fill_n(_OutputIter __first, _Size __n, const _Tp& __value) { _OutputIter fill_n(_OutputIter __first, _Size __n, const _Tp& __value) {
__STL_REQUIRES(_OutputIter, _OutputIterator);
for ( ; __n > 0; --__n, ++__first) for ( ; __n > 0; --__n, ++__first)
*__first = __value; *__first = __value;
return __first; 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);
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
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;
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
//-------------------------------------------------- //--------------------------------------------------
// equal and mismatch // equal and mismatch
...@@ -489,6 +563,12 @@ template <class _InputIter1, class _InputIter2> ...@@ -489,6 +563,12 @@ template <class _InputIter1, class _InputIter2>
pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1, pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
_InputIter1 __last1, _InputIter1 __last1,
_InputIter2 __first2) { _InputIter2 __first2) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(typename iterator_traits<_InputIter1>::value_type,
_EqualityComparable);
__STL_REQUIRES(typename iterator_traits<_InputIter2>::value_type,
_EqualityComparable);
while (__first1 != __last1 && *__first1 == *__first2) { while (__first1 != __last1 && *__first1 == *__first2) {
++__first1; ++__first1;
++__first2; ++__first2;
...@@ -501,6 +581,8 @@ pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1, ...@@ -501,6 +581,8 @@ pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
_InputIter1 __last1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __first2,
_BinaryPredicate __binary_pred) { _BinaryPredicate __binary_pred) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) { while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) {
++__first1; ++__first1;
++__first2; ++__first2;
...@@ -511,6 +593,12 @@ pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1, ...@@ -511,6 +593,12 @@ pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
template <class _InputIter1, class _InputIter2> template <class _InputIter1, class _InputIter2>
inline bool equal(_InputIter1 __first1, _InputIter1 __last1, inline bool equal(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2) { _InputIter2 __first2) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(typename iterator_traits<_InputIter1>::value_type,
_EqualityComparable);
__STL_REQUIRES(typename iterator_traits<_InputIter2>::value_type,
_EqualityComparable);
for ( ; __first1 != __last1; ++__first1, ++__first2) for ( ; __first1 != __last1; ++__first1, ++__first2)
if (*__first1 != *__first2) if (*__first1 != *__first2)
return false; return false;
...@@ -520,6 +608,8 @@ inline bool equal(_InputIter1 __first1, _InputIter1 __last1, ...@@ -520,6 +608,8 @@ inline bool equal(_InputIter1 __first1, _InputIter1 __last1,
template <class _InputIter1, class _InputIter2, class _BinaryPredicate> template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
inline bool equal(_InputIter1 __first1, _InputIter1 __last1, inline bool equal(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _BinaryPredicate __binary_pred) { _InputIter2 __first2, _BinaryPredicate __binary_pred) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
for ( ; __first1 != __last1; ++__first1, ++__first2) for ( ; __first1 != __last1; ++__first1, ++__first2)
if (!__binary_pred(*__first1, *__first2)) if (!__binary_pred(*__first1, *__first2))
return false; return false;
...@@ -533,6 +623,12 @@ inline bool equal(_InputIter1 __first1, _InputIter1 __last1, ...@@ -533,6 +623,12 @@ inline bool equal(_InputIter1 __first1, _InputIter1 __last1,
template <class _InputIter1, class _InputIter2> template <class _InputIter1, class _InputIter2>
bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1, bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2) { _InputIter2 __first2, _InputIter2 __last2) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(typename iterator_traits<_InputIter1>::value_type,
_LessThanComparable);
__STL_REQUIRES(typename iterator_traits<_InputIter2>::value_type,
_LessThanComparable);
for ( ; __first1 != __last1 && __first2 != __last2 for ( ; __first1 != __last1 && __first2 != __last2
; ++__first1, ++__first2) { ; ++__first1, ++__first2) {
if (*__first1 < *__first2) if (*__first1 < *__first2)
...@@ -547,6 +643,8 @@ template <class _InputIter1, class _InputIter2, class _Compare> ...@@ -547,6 +643,8 @@ template <class _InputIter1, class _InputIter2, class _Compare>
bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1, bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _InputIter2 __first2, _InputIter2 __last2,
_Compare __comp) { _Compare __comp) {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
for ( ; __first1 != __last1 && __first2 != __last2 for ( ; __first1 != __last1 && __first2 != __last2
; ++__first1, ++__first2) { ; ++__first1, ++__first2) {
if (__comp(*__first1, *__first2)) if (__comp(*__first1, *__first2))
...@@ -640,6 +738,12 @@ template <class _InputIter1, class _InputIter2> ...@@ -640,6 +738,12 @@ template <class _InputIter1, class _InputIter2>
int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1, int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2) _InputIter2 __first2, _InputIter2 __last2)
{ {
__STL_REQUIRES(_InputIter1, _InputIterator);
__STL_REQUIRES(_InputIter2, _InputIterator);
__STL_REQUIRES(typename iterator_traits<_InputIter1>::value_type,
_LessThanComparable);
__STL_REQUIRES(typename iterator_traits<_InputIter2>::value_type,
_LessThanComparable);
return __lexicographical_compare_3way(__first1, __last1, __first2, __last2); return __lexicographical_compare_3way(__first1, __last1, __first2, __last2);
} }
......
...@@ -49,10 +49,6 @@ ...@@ -49,10 +49,6 @@
# endif # endif
#endif #endif
#ifdef __STL_WIN32THREADS
# include <windows.h>
#endif
#include <bits/std_cstddef.h> #include <bits/std_cstddef.h>
#include <bits/std_cstdlib.h> #include <bits/std_cstdlib.h>
#include <bits/std_cstring.h> #include <bits/std_cstring.h>
...@@ -281,7 +277,8 @@ typedef malloc_alloc single_client_alloc; ...@@ -281,7 +277,8 @@ typedef malloc_alloc single_client_alloc;
// creation of multiple default_alloc instances. // creation of multiple default_alloc instances.
// Node that containers built on different allocator instances have // Node that containers built on different allocator instances have
// different types, limiting the utility of this approach. // different types, limiting the utility of this approach.
#ifdef __SUNPRO_CC
#if defined(__SUNPRO_CC) || defined(__GNUC__)
// breaks if we make these template class members: // breaks if we make these template class members:
enum {_ALIGN = 8}; enum {_ALIGN = 8};
enum {_MAX_BYTES = 128}; enum {_MAX_BYTES = 128};
...@@ -294,7 +291,7 @@ class __default_alloc_template { ...@@ -294,7 +291,7 @@ class __default_alloc_template {
private: private:
// Really we should use static const int x = N // Really we should use static const int x = N
// instead of enum { x = N }, but few compilers accept the former. // instead of enum { x = N }, but few compilers accept the former.
# ifndef __SUNPRO_CC #if ! (defined(__SUNPRO_CC) || defined(__GNUC__))
enum {_ALIGN = 8}; enum {_ALIGN = 8};
enum {_MAX_BYTES = 128}; enum {_MAX_BYTES = 128};
enum {_NFREELISTS = 16}; // _MAX_BYTES/_ALIGN enum {_NFREELISTS = 16}; // _MAX_BYTES/_ALIGN
...@@ -309,7 +306,7 @@ __PRIVATE: ...@@ -309,7 +306,7 @@ __PRIVATE:
char _M_client_data[1]; /* The client sees this. */ char _M_client_data[1]; /* The client sees this. */
}; };
private: private:
# ifdef __SUNPRO_CC # if defined(__SUNPRO_CC) || defined(__GNUC__) || defined(__HP_aCC)
static _Obj* __STL_VOLATILE _S_free_list[]; static _Obj* __STL_VOLATILE _S_free_list[];
// Specifying a size results in duplicate def for 4.1 // Specifying a size results in duplicate def for 4.1
# else # else
...@@ -405,6 +402,22 @@ public: ...@@ -405,6 +402,22 @@ public:
typedef __default_alloc_template<__NODE_ALLOCATOR_THREADS, 0> alloc; typedef __default_alloc_template<__NODE_ALLOCATOR_THREADS, 0> alloc;
typedef __default_alloc_template<false, 0> single_client_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;
}
# ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <bool __threads, int __inst>
inline bool operator!=(const __default_alloc_template<__threads, __inst>&,
const __default_alloc_template<__threads, __inst>&)
{
return false;
}
# endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
/* We allocate memory in large chunks in order to avoid fragmenting */ /* We allocate memory in large chunks in order to avoid fragmenting */
...@@ -548,9 +561,9 @@ template <bool __threads, int __inst> ...@@ -548,9 +561,9 @@ template <bool __threads, int __inst>
size_t __default_alloc_template<__threads, __inst>::_S_heap_size = 0; size_t __default_alloc_template<__threads, __inst>::_S_heap_size = 0;
template <bool __threads, int __inst> template <bool __threads, int __inst>
__default_alloc_template<__threads, __inst>::_Obj* __STL_VOLATILE typename __default_alloc_template<__threads, __inst>::_Obj* __STL_VOLATILE
__default_alloc_template<__threads, __inst> ::_S_free_list[ __default_alloc_template<__threads, __inst> ::_S_free_list[
# ifdef __SUNPRO_CC # if defined(__SUNPRO_CC) || defined(__GNUC__) || defined(__HP_aCC)
_NFREELISTS _NFREELISTS
# else # else
__default_alloc_template<__threads, __inst>::_NFREELISTS __default_alloc_template<__threads, __inst>::_NFREELISTS
...@@ -742,24 +755,6 @@ inline bool operator!=(const __malloc_alloc_template<__inst>&, ...@@ -742,24 +755,6 @@ inline bool operator!=(const __malloc_alloc_template<__inst>&,
} }
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */ #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#ifndef __USE_MALLOC
template <bool __threads, int __inst>
inline bool operator==(const __default_alloc_template<__threads, __inst>&,
const __default_alloc_template<__threads, __inst>&)
{
return true;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <bool __threads, int __inst>
inline bool operator!=(const __default_alloc_template<__threads, __inst>&,
const __default_alloc_template<__threads, __inst>&)
{
return false;
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#endif
template <class _Alloc> template <class _Alloc>
inline bool operator==(const debug_alloc<_Alloc>&, inline bool operator==(const debug_alloc<_Alloc>&,
const debug_alloc<_Alloc>&) { const debug_alloc<_Alloc>&) {
......
...@@ -51,6 +51,8 @@ ...@@ -51,6 +51,8 @@
// member functions of classes. // member functions of classes.
// * __STL_MEMBER_TEMPLATE_CLASSES: defined if the compiler supports // * __STL_MEMBER_TEMPLATE_CLASSES: defined if the compiler supports
// nested classes that are member templates of other classes. // 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 // * __STL_EXPLICIT_FUNCTION_TMPL_ARGS: defined if the compiler
// supports calling a function template by providing its template // supports calling a function template by providing its template
// arguments explicitly. // arguments explicitly.
...@@ -86,8 +88,23 @@ ...@@ -86,8 +88,23 @@
// types. (They're not in the C++ standard, but they are expected to be // types. (They're not in the C++ standard, but they are expected to be
// included in the forthcoming C9X standard.) // included in the forthcoming C9X standard.)
// * __STL_THREADS is defined if thread safety is needed. // * __STL_THREADS is defined if thread safety is needed.
// * __STL_VOLATILE is deifined to be "volatile" if threads are being // * __STL_VOLATILE is defined to be "volatile" if threads are being
// used, and the empty string otherwise. // 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: // User-settable macros that control compilation:
...@@ -107,6 +124,8 @@ ...@@ -107,6 +124,8 @@
// * _UITHREADS:if defined, use SCO/Solaris/UI threads for multithreading // * _UITHREADS:if defined, use SCO/Solaris/UI threads for multithreading
// support // support
// * _NOTHREADS: if defined, don't use any 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, // * __STL_USE_NEW_IOSTREAMS: if defined, then the STL will use new,
// standard-conforming iostreams (e.g. the <iosfwd> header). If not // standard-conforming iostreams (e.g. the <iosfwd> header). If not
// defined, the STL will use old cfront-style iostreams (e.g. the // defined, the STL will use old cfront-style iostreams (e.g. the
...@@ -152,6 +171,7 @@ ...@@ -152,6 +171,7 @@
# endif # endif
# ifdef _MEMBER_TEMPLATES # ifdef _MEMBER_TEMPLATES
# define __STL_MEMBER_TEMPLATES # define __STL_MEMBER_TEMPLATES
# define __STL_TEMPLATE_FRIENDS
# define __STL_MEMBER_TEMPLATE_CLASSES # define __STL_MEMBER_TEMPLATE_CLASSES
# endif # endif
# if defined(_MEMBER_TEMPLATE_KEYWORD) # if defined(_MEMBER_TEMPLATE_KEYWORD)
...@@ -163,7 +183,7 @@ ...@@ -163,7 +183,7 @@
# if (_COMPILER_VERSION >= 730) && defined(_MIPS_SIM) && _MIPS_SIM != _ABIO32 # if (_COMPILER_VERSION >= 730) && defined(_MIPS_SIM) && _MIPS_SIM != _ABIO32
# define __STL_MEMBER_TEMPLATE_KEYWORD # define __STL_MEMBER_TEMPLATE_KEYWORD
# endif # endif
# if defined(_MIPS_SIM) && _MIPS_SIM == _ABIO32 # if COMPILER_VERSION < 720 || (defined(_MIPS_SIM) && _MIPS_SIM == _ABIO32)
# define __STL_DEFAULT_CONSTRUCTOR_BUG # define __STL_DEFAULT_CONSTRUCTOR_BUG
# endif # endif
# if !defined(_EXPLICIT_IS_KEYWORD) # if !defined(_EXPLICIT_IS_KEYWORD)
...@@ -175,7 +195,8 @@ ...@@ -175,7 +195,8 @@
# if (_COMPILER_VERSION >= 721) && defined(_NAMESPACES) # if (_COMPILER_VERSION >= 721) && defined(_NAMESPACES)
# define __STL_HAS_NAMESPACES # define __STL_HAS_NAMESPACES
# endif # endif
# if (_COMPILER_VERSION < 721) # if (_COMPILER_VERSION < 721) || \
!defined(__STL_HAS_NAMESPACES) || defined(__STL_NO_NAMESPACES)
# define __STL_NO_EXCEPTION_HEADER # define __STL_NO_EXCEPTION_HEADER
# endif # endif
# if _COMPILER_VERSION < 730 || !defined(_STANDARD_C_PLUS_PLUS) || \ # if _COMPILER_VERSION < 730 || !defined(_STANDARD_C_PLUS_PLUS) || \
...@@ -236,6 +257,7 @@ ...@@ -236,6 +257,7 @@
# define __STL_HAS_WCHAR_T # define __STL_HAS_WCHAR_T
# define __STL_MEMBER_TEMPLATES # define __STL_MEMBER_TEMPLATES
# define __STL_MEMBER_TEMPLATE_CLASSES # define __STL_MEMBER_TEMPLATE_CLASSES
# define __STL_TEMPLATE_FRIENDS
# define __STL_CLASS_PARTIAL_SPECIALIZATION # define __STL_CLASS_PARTIAL_SPECIALIZATION
# define __STL_PARTIAL_SPECIALIZATION_SYNTAX # define __STL_PARTIAL_SPECIALIZATION_SYNTAX
# define __STL_FUNCTION_TMPL_PARTIAL_ORDER # define __STL_FUNCTION_TMPL_PARTIAL_ORDER
...@@ -257,6 +279,9 @@ ...@@ -257,6 +279,9 @@
# ifndef __STRICT_ANSI__ # ifndef __STRICT_ANSI__
# define __STL_LONG_LONG # define __STL_LONG_LONG
# endif # endif
# if (__GNUC__ < 2) || (__GNUC__ == 2 && __GNUC_MINOR__ < 95)
# define __STL_NO_FUNCTION_PTR_IN_CLASS_TEMPLATE
# endif
# endif # endif
# if defined(__SUNPRO_CC) # if defined(__SUNPRO_CC)
...@@ -276,6 +301,7 @@ ...@@ -276,6 +301,7 @@
# if defined(__COMO__) # if defined(__COMO__)
# define __STL_MEMBER_TEMPLATES # define __STL_MEMBER_TEMPLATES
# define __STL_MEMBER_TEMPLATE_CLASSES # define __STL_MEMBER_TEMPLATE_CLASSES
# define __STL_TEMPLATE_FRIENDS
# define __STL_CLASS_PARTIAL_SPECIALIZATION # define __STL_CLASS_PARTIAL_SPECIALIZATION
# define __STL_USE_EXCEPTIONS # define __STL_USE_EXCEPTIONS
# define __STL_HAS_NAMESPACES # define __STL_HAS_NAMESPACES
...@@ -286,6 +312,7 @@ ...@@ -286,6 +312,7 @@
# define __STL_LONG_LONG # define __STL_LONG_LONG
# define __STL_MEMBER_TEMPLATES # define __STL_MEMBER_TEMPLATES
# define __STL_MEMBER_TEMPLATE_CLASSES # define __STL_MEMBER_TEMPLATE_CLASSES
# define __STL_TEMPLATE_FRIENDS
# define __STL_FUNCTION_TMPL_PARTIAL_ORDER # define __STL_FUNCTION_TMPL_PARTIAL_ORDER
# define __STL_CLASS_PARTIAL_SPECIALIZATION # define __STL_CLASS_PARTIAL_SPECIALIZATION
# define __STL_NO_DRAND48 # define __STL_NO_DRAND48
...@@ -300,19 +327,32 @@ ...@@ -300,19 +327,32 @@
# endif # endif
# endif # endif
// Mingw32, EGCS compiler using the Microsoft C runtime // Mingw32, egcs compiler using the Microsoft C runtime
# if defined(__MINGW32__) # if defined(__MINGW32__)
# define __STL_NO_DRAND48 # define __STL_NO_DRAND48
# ifdef _MT
# define __STL_WIN32THREADS
# endif
# endif # endif
// Cygwin32, egcs compiler on MS Windows
# if defined(__CYGWIN__)
# define __STL_NO_DRAND48
# endif
// Microsoft compiler. // Microsoft compiler.
# if defined(_MSC_VER) && !defined(__ICL) # if defined(_MSC_VER) && !defined(__ICL) && !defined(__MWERKS__)
# define __STL_NO_DRAND48 # define __STL_NO_DRAND48
# define __STL_STATIC_CONST_INIT_BUG # define __STL_STATIC_CONST_INIT_BUG
# define __STL_NEED_TYPENAME # 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. */ # if _MSC_VER < 1100 /* 1000 is version 4.0, 1100 is 5.0, 1200 is 6.0. */
# define __STL_NEED_EXPLICIT # define __STL_NEED_EXPLICIT
# define __STL_NO_BOOL # define __STL_NO_BOOL
# define __STL_NO_BAD_ALLOC
# endif # endif
# if _MSC_VER > 1000 # if _MSC_VER > 1000
# include <yvals.h> # include <yvals.h>
...@@ -330,8 +370,16 @@ ...@@ -330,8 +370,16 @@
# if _MSC_VER >= 1200 # if _MSC_VER >= 1200
# define __STL_PARTIAL_SPECIALIZATION_SYNTAX # define __STL_PARTIAL_SPECIALIZATION_SYNTAX
# define __STL_HAS_NAMESPACES # define __STL_HAS_NAMESPACES
# define __STL_NO_NAMESPACES
# define __STL_CAN_THROW_RANGE_ERRORS # 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 # endif
# if _MSC_VER < 1100 # if _MSC_VER < 1100
# define __STL_NO_EXCEPTION_HEADER # define __STL_NO_EXCEPTION_HEADER
...@@ -343,13 +391,21 @@ ...@@ -343,13 +391,21 @@
# endif # endif
# if defined(__BORLANDC__) # if defined(__BORLANDC__)
# define __STL_NO_BAD_ALLOC # define __STL_NO_BAD_ALLOC
# define __STL_NO_DRAND48 # define __STL_NO_DRAND48
# define __STL_NEED_TYPENAME # define __STL_DEFAULT_CONSTRUCTOR_BUG
# define __STL_LIMITED_DEFAULT_TEMPLATES # if __BORLANDC__ >= 0x540 /* C++ Builder 4.0 */
# define __SGI_STL_NO_ARROW_OPERATOR # define __STL_CLASS_PARTIAL_SPECIALIZATION
# define __STL_DEFAULT_CONSTRUCTOR_BUG # define __STL_FUNCTION_TMPL_PARTIAL_ORDER
# define __STL_NON_TYPE_TMPL_PARAM_BUG # 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 # ifdef _CPPUNWIND
# define __STL_USE_EXCEPTIONS # define __STL_USE_EXCEPTIONS
# endif # endif
...@@ -368,6 +424,12 @@ ...@@ -368,6 +424,12 @@
# define typename # define typename
# endif # 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 # ifdef __STL_MEMBER_TEMPLATE_KEYWORD
# define __STL_TEMPLATE template # define __STL_TEMPLATE template
# else # else
...@@ -405,6 +467,14 @@ ...@@ -405,6 +467,14 @@
# define __STL_USE_STD_ALLOCATORS # define __STL_USE_STD_ALLOCATORS
# endif # 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 // __STL_NO_NAMESPACES is a hook so that users can disable namespaces
// without having to edit library headers. __STL_NO_RELOPS_NAMESPACE is // without having to edit library headers. __STL_NO_RELOPS_NAMESPACE is
// a hook so that users can disable the std::rel_ops namespace, keeping // a hook so that users can disable the std::rel_ops namespace, keeping
...@@ -475,7 +545,7 @@ ...@@ -475,7 +545,7 @@
# define __stl_assert(expr) # define __stl_assert(expr)
#endif #endif
#if defined(__STL_WIN32THREADS) || defined(STL_SGI_THREADS) \ #if defined(__STL_WIN32THREADS) || defined(__STL_SGI_THREADS) \
|| defined(__STL_PTHREADS) || defined(__STL_UITHREADS) || defined(__STL_PTHREADS) || defined(__STL_UITHREADS)
# define __STL_THREADS # define __STL_THREADS
# define __STL_VOLATILE volatile # define __STL_VOLATILE volatile
...@@ -483,6 +553,13 @@ ...@@ -483,6 +553,13 @@
# define __STL_VOLATILE # define __STL_VOLATILE
#endif #endif
#if defined(__STL_CLASS_PARTIAL_SPECIALIZATION) \
&& defined(__STL_MEMBER_TEMPLATES) \
&& !defined(_STL_NO_CONCEPT_CHECKS)
# define __STL_USE_CONCEPT_CHECKS
#endif
#endif /* __STL_CONFIG_H */ #endif /* __STL_CONFIG_H */
// Local Variables: // Local Variables:
......
...@@ -36,23 +36,28 @@ ...@@ -36,23 +36,28 @@
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
// construct and destroy. These functions are not part of the C++ standard, // construct and destroy. These functions are not part of the C++ standard,
// and are provided for backward compatibility with the HP STL. // 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.
template <class _Tp> // Internal names
inline void destroy(_Tp* __pointer) {
__pointer->_Tp::~_Tp();
}
template <class _Tp1, class _Tp2> template <class _T1, class _T2>
inline void construct(_Tp1* __p, const _Tp2& __value) { inline void _Construct(_T1* __p, const _T2& __value) {
new (__p) _Tp1(__value); new ((void*) __p) _T1(__value);
} }
template <class _Tp1> template <class _T1>
inline void construct(_Tp1* __p) { inline void _Construct(_T1* __p) {
new (__p) _Tp1(); new ((void*) __p) _T1();
} }
template <class _Tp>
inline void _Destroy(_Tp* __pointer) {
__pointer->~_Tp();
}
template <class _ForwardIterator> template <class _ForwardIterator>
void void
__destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type) __destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type)
...@@ -74,12 +79,41 @@ __destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*) ...@@ -74,12 +79,41 @@ __destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*)
} }
template <class _ForwardIterator> template <class _ForwardIterator>
inline void destroy(_ForwardIterator __first, _ForwardIterator __last) { inline void _Destroy(_ForwardIterator __first, _ForwardIterator __last) {
__destroy(__first, __last, __VALUE_TYPE(__first)); __destroy(__first, __last, __VALUE_TYPE(__first));
} }
inline void destroy(char*, char*) {} inline void _Destroy(char*, char*) {}
inline void destroy(wchar_t*, wchar_t*) {} inline void _Destroy(int*, int*) {}
inline void _Destroy(long*, long*) {}
inline void _Destroy(float*, float*) {}
inline void _Destroy(double*, double*) {}
#ifdef __STL_HAS_WCHAR_T
inline void _Destroy(wchar_t*, wchar_t*) {}
#endif /* __STL_HAS_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);
}
__STL_END_NAMESPACE __STL_END_NAMESPACE
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
* You should not attempt to use it directly. * You should not attempt to use it directly.
*/ */
#include <bits/concept_checks.h>
#ifndef __SGI_STL_INTERNAL_DEQUE_H #ifndef __SGI_STL_INTERNAL_DEQUE_H
#define __SGI_STL_INTERNAL_DEQUE_H #define __SGI_STL_INTERNAL_DEQUE_H
...@@ -59,24 +61,10 @@ ...@@ -59,24 +61,10 @@
/* /*
* In previous versions of deque, node_size was fixed by the * In previous versions of deque, there was an extra template
* implementation. In this version, however, users can select * parameter so users could control the node size. This extension
* the node size. Deque has three template parameters; the third, * turns out to violate the C++ standard (it can be detected using
* a number of type size_t, is the number of elements per node. * template template parameters), and it has been removed.
* If the third template parameter is 0 (which is the default),
* then deque will use a default node size.
*
* The only reason for using an alternate node size is if your application
* requires a different performance tradeoff than the default. If,
* for example, your program contains many deques each of which contains
* only a few elements, then you might want to save memory (possibly
* by sacrificing some speed) by using smaller nodes.
*
* Unfortunately, some compilers have trouble with non-type template
* parameters; stl_config.h defines __STL_NON_TYPE_TMPL_PARAM_BUG if
* that is the case. If your compiler is one of them, then you will
* not be able to use alternate node sizes; you will have to use the
* default value.
*/ */
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
...@@ -88,27 +76,15 @@ __STL_BEGIN_NAMESPACE ...@@ -88,27 +76,15 @@ __STL_BEGIN_NAMESPACE
// Note: this function is simply a kludge to work around several compilers' // Note: this function is simply a kludge to work around several compilers'
// bugs in handling constant expressions. // bugs in handling constant expressions.
inline size_t inline size_t __deque_buf_size(size_t __size) {
__deque_buf_size(size_t __n, size_t __size) return __size < 512 ? size_t(512 / __size) : size_t(1);
{
return __n != 0 ? __n : (__size < 512 ? size_t(512 / __size) : size_t(1));
} }
#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz>
struct _Deque_iterator {
typedef _Deque_iterator<_Tp,_Tp&,_Tp*,__bufsiz> iterator;
typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*,__bufsiz> const_iterator;
static size_t
_S_buffer_size() { return __deque_buf_size(__bufsiz, sizeof(_Tp)); }
#else /* __STL_NON_TYPE_TMPL_PARAM_BUG */
template <class _Tp, class _Ref, class _Ptr> template <class _Tp, class _Ref, class _Ptr>
struct _Deque_iterator { struct _Deque_iterator {
typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator; typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator;
typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator; typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
static size_t static size_t _S_buffer_size() { return __deque_buf_size(sizeof(_Tp)); }
_S_buffer_size() { return __deque_buf_size(0, sizeof(_Tp)); }
#endif
typedef random_access_iterator_tag iterator_category; typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type; typedef _Tp value_type;
...@@ -219,29 +195,14 @@ struct _Deque_iterator { ...@@ -219,29 +195,14 @@ struct _Deque_iterator {
} }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION template <class _Tp, class _Ref, class _Ptr>
inline _Deque_iterator<_Tp, _Ref, _Ptr>
#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
{
template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz> return __x + __n;
inline random_access_iterator_tag
iterator_category(const _Deque_iterator<_Tp,_Ref,_Ptr,__bufsiz>&) {
return random_access_iterator_tag();
}
template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz>
inline _Tp*
value_type(const _Deque_iterator<_Tp,_Ref,_Ptr,__bufsiz>&) {
return 0;
}
template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz>
inline ptrdiff_t*
distance_type(const _Deque_iterator<_Tp,_Ref,_Ptr,__bufsiz>&) {
return 0;
} }
#else /* __STL_NON_TYPE_TMPL_PARAM_BUG */ #ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class _Tp, class _Ref, class _Ptr> template <class _Tp, class _Ref, class _Ptr>
inline random_access_iterator_tag inline random_access_iterator_tag
...@@ -251,17 +212,13 @@ iterator_category(const _Deque_iterator<_Tp,_Ref,_Ptr>&) ...@@ -251,17 +212,13 @@ iterator_category(const _Deque_iterator<_Tp,_Ref,_Ptr>&)
} }
template <class _Tp, class _Ref, class _Ptr> template <class _Tp, class _Ref, class _Ptr>
inline _Tp* inline _Tp* value_type(const _Deque_iterator<_Tp,_Ref,_Ptr>&) { return 0; }
value_type(const _Deque_iterator<_Tp,_Ref,_Ptr>&) { return 0; }
template <class _Tp, class _Ref, class _Ptr> template <class _Tp, class _Ref, class _Ptr>
inline ptrdiff_t* inline ptrdiff_t* distance_type(const _Deque_iterator<_Tp,_Ref,_Ptr>&) {
distance_type(const _Deque_iterator<_Tp,_Ref,_Ptr>&) {
return 0; return 0;
} }
#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */ #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
// Deque base class. It has two purposes. First, its constructor // Deque base class. It has two purposes. First, its constructor
...@@ -273,7 +230,7 @@ distance_type(const _Deque_iterator<_Tp,_Ref,_Ptr>&) { ...@@ -273,7 +230,7 @@ distance_type(const _Deque_iterator<_Tp,_Ref,_Ptr>&) {
#ifdef __STL_USE_STD_ALLOCATORS #ifdef __STL_USE_STD_ALLOCATORS
// Base class for ordinary allocators. // Base class for ordinary allocators.
template <class _Tp, class _Alloc, size_t __bufsiz, bool __is_static> template <class _Tp, class _Alloc, bool __is_static>
class _Deque_alloc_base { class _Deque_alloc_base {
public: public:
typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type; typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type;
...@@ -292,10 +249,10 @@ protected: ...@@ -292,10 +249,10 @@ protected:
_Map_allocator_type _M_map_allocator; _Map_allocator_type _M_map_allocator;
_Tp* _M_allocate_node() { _Tp* _M_allocate_node() {
return _M_node_allocator.allocate(__deque_buf_size(__bufsiz,sizeof(_Tp))); return _M_node_allocator.allocate(__deque_buf_size(sizeof(_Tp)));
} }
void _M_deallocate_node(_Tp* __p) { void _M_deallocate_node(_Tp* __p) {
_M_node_allocator.deallocate(__p, __deque_buf_size(__bufsiz,sizeof(_Tp))); _M_node_allocator.deallocate(__p, __deque_buf_size(sizeof(_Tp)));
} }
_Tp** _M_allocate_map(size_t __n) _Tp** _M_allocate_map(size_t __n)
{ return _M_map_allocator.allocate(__n); } { return _M_map_allocator.allocate(__n); }
...@@ -307,8 +264,8 @@ protected: ...@@ -307,8 +264,8 @@ protected:
}; };
// Specialization for instanceless allocators. // Specialization for instanceless allocators.
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
class _Deque_alloc_base<_Tp, _Alloc, __bufsiz, true> class _Deque_alloc_base<_Tp, _Alloc, true>
{ {
public: public:
typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type; typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type;
...@@ -321,12 +278,10 @@ protected: ...@@ -321,12 +278,10 @@ protected:
typedef typename _Alloc_traits<_Tp*, _Alloc>::_Alloc_type _Map_alloc_type; typedef typename _Alloc_traits<_Tp*, _Alloc>::_Alloc_type _Map_alloc_type;
_Tp* _M_allocate_node() { _Tp* _M_allocate_node() {
return _Node_alloc_type::allocate(__deque_buf_size(__bufsiz, return _Node_alloc_type::allocate(__deque_buf_size(sizeof(_Tp)));
sizeof(_Tp)));
} }
void _M_deallocate_node(_Tp* __p) { void _M_deallocate_node(_Tp* __p) {
_Node_alloc_type::deallocate(__p, __deque_buf_size(__bufsiz, _Node_alloc_type::deallocate(__p, __deque_buf_size(sizeof(_Tp)));
sizeof(_Tp)));
} }
_Tp** _M_allocate_map(size_t __n) _Tp** _M_allocate_map(size_t __n)
{ return _Map_alloc_type::allocate(__n); } { return _Map_alloc_type::allocate(__n); }
...@@ -337,18 +292,18 @@ protected: ...@@ -337,18 +292,18 @@ protected:
size_t _M_map_size; size_t _M_map_size;
}; };
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
class _Deque_base class _Deque_base
: public _Deque_alloc_base<_Tp,_Alloc,__bufsiz, : public _Deque_alloc_base<_Tp,_Alloc,
_Alloc_traits<_Tp, _Alloc>::_S_instanceless> _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
{ {
public: public:
typedef _Deque_alloc_base<_Tp,_Alloc,__bufsiz, typedef _Deque_alloc_base<_Tp,_Alloc,
_Alloc_traits<_Tp, _Alloc>::_S_instanceless> _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
_Base; _Base;
typedef typename _Base::allocator_type allocator_type; typedef typename _Base::allocator_type allocator_type;
typedef _Deque_iterator<_Tp,_Tp&,_Tp*,__bufsiz> iterator; typedef _Deque_iterator<_Tp,_Tp&,_Tp*> iterator;
typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*, __bufsiz> const_iterator; typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*> const_iterator;
_Deque_base(const allocator_type& __a, size_t __num_elements) _Deque_base(const allocator_type& __a, size_t __num_elements)
: _Base(__a), _M_start(), _M_finish() : _Base(__a), _M_start(), _M_finish()
...@@ -370,16 +325,11 @@ protected: ...@@ -370,16 +325,11 @@ protected:
#else /* __STL_USE_STD_ALLOCATORS */ #else /* __STL_USE_STD_ALLOCATORS */
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
class _Deque_base { class _Deque_base {
public: public:
#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG typedef _Deque_iterator<_Tp,_Tp&,_Tp*> iterator;
typedef _Deque_iterator<_Tp,_Tp&,_Tp*,__bufsiz> iterator; typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*> const_iterator;
typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*, __bufsiz> const_iterator;
#else /* __STL_NON_TYPE_TMPL_PARAM_BUG */
typedef _Deque_iterator<_Tp,_Tp&,_Tp*> iterator;
typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*> const_iterator;
#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
typedef _Alloc allocator_type; typedef _Alloc allocator_type;
allocator_type get_allocator() const { return allocator_type(); } allocator_type get_allocator() const { return allocator_type(); }
...@@ -408,11 +358,9 @@ protected: ...@@ -408,11 +358,9 @@ protected:
typedef simple_alloc<_Tp*, _Alloc> _Map_alloc_type; typedef simple_alloc<_Tp*, _Alloc> _Map_alloc_type;
_Tp* _M_allocate_node() _Tp* _M_allocate_node()
{ return _Node_alloc_type::allocate(__deque_buf_size(__bufsiz, { return _Node_alloc_type::allocate(__deque_buf_size(sizeof(_Tp))); }
sizeof(_Tp))); }
void _M_deallocate_node(_Tp* __p) void _M_deallocate_node(_Tp* __p)
{ _Node_alloc_type::deallocate(__p, __deque_buf_size(__bufsiz, { _Node_alloc_type::deallocate(__p, __deque_buf_size(sizeof(_Tp))); }
sizeof(_Tp))); }
_Tp** _M_allocate_map(size_t __n) _Tp** _M_allocate_map(size_t __n)
{ return _Map_alloc_type::allocate(__n); } { return _Map_alloc_type::allocate(__n); }
void _M_deallocate_map(_Tp** __p, size_t __n) void _M_deallocate_map(_Tp** __p, size_t __n)
...@@ -423,20 +371,20 @@ protected: ...@@ -423,20 +371,20 @@ protected:
// Non-inline member functions from _Deque_base. // Non-inline member functions from _Deque_base.
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
_Deque_base<_Tp,_Alloc,__bufsiz>::~_Deque_base() { _Deque_base<_Tp,_Alloc>::~_Deque_base() {
if (_M_map) { if (_M_map) {
_M_destroy_nodes(_M_start._M_node, _M_finish._M_node + 1); _M_destroy_nodes(_M_start._M_node, _M_finish._M_node + 1);
_M_deallocate_map(_M_map, _M_map_size); _M_deallocate_map(_M_map, _M_map_size);
} }
} }
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
void void
_Deque_base<_Tp,_Alloc,__bufsiz>::_M_initialize_map(size_t __num_elements) _Deque_base<_Tp,_Alloc>::_M_initialize_map(size_t __num_elements)
{ {
size_t __num_nodes = size_t __num_nodes =
__num_elements / __deque_buf_size(__bufsiz, sizeof(_Tp)) + 1; __num_elements / __deque_buf_size(sizeof(_Tp)) + 1;
_M_map_size = max((size_t) _S_initial_map_size, __num_nodes + 2); _M_map_size = max((size_t) _S_initial_map_size, __num_nodes + 2);
_M_map = _M_allocate_map(_M_map_size); _M_map = _M_allocate_map(_M_map_size);
...@@ -453,13 +401,11 @@ _Deque_base<_Tp,_Alloc,__bufsiz>::_M_initialize_map(size_t __num_elements) ...@@ -453,13 +401,11 @@ _Deque_base<_Tp,_Alloc,__bufsiz>::_M_initialize_map(size_t __num_elements)
_M_finish._M_set_node(__nfinish - 1); _M_finish._M_set_node(__nfinish - 1);
_M_start._M_cur = _M_start._M_first; _M_start._M_cur = _M_start._M_first;
_M_finish._M_cur = _M_finish._M_first + _M_finish._M_cur = _M_finish._M_first +
__num_elements % __deque_buf_size(__bufsiz, sizeof(_Tp)); __num_elements % __deque_buf_size(sizeof(_Tp));
} }
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
void void _Deque_base<_Tp,_Alloc>::_M_create_nodes(_Tp** __nstart, _Tp** __nfinish)
_Deque_base<_Tp,_Alloc,__bufsiz>::_M_create_nodes(_Tp** __nstart,
_Tp** __nfinish)
{ {
_Tp** __cur; _Tp** __cur;
__STL_TRY { __STL_TRY {
...@@ -469,22 +415,22 @@ _Deque_base<_Tp,_Alloc,__bufsiz>::_M_create_nodes(_Tp** __nstart, ...@@ -469,22 +415,22 @@ _Deque_base<_Tp,_Alloc,__bufsiz>::_M_create_nodes(_Tp** __nstart,
__STL_UNWIND(_M_destroy_nodes(__nstart, __cur)); __STL_UNWIND(_M_destroy_nodes(__nstart, __cur));
} }
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
void void
_Deque_base<_Tp,_Alloc,__bufsiz>::_M_destroy_nodes(_Tp** __nstart, _Deque_base<_Tp,_Alloc>::_M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish)
_Tp** __nfinish)
{ {
for (_Tp** __n = __nstart; __n < __nfinish; ++__n) for (_Tp** __n = __nstart; __n < __nfinish; ++__n)
_M_deallocate_node(*__n); _M_deallocate_node(*__n);
} }
// See __deque_buf_size(). The only reason that the default value is 0 template <class _Tp, class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
// is as a workaround for bugs in the way that some compilers handle class deque : protected _Deque_base<_Tp, _Alloc> {
// constant expressions.
template <class _Tp, class _Alloc = allocator<_Tp>, // requirements:
size_t __bufsiz = 0>
class deque : protected _Deque_base<_Tp, _Alloc, __bufsiz> { __STL_CLASS_REQUIRES(_Tp, _Assignable);
typedef _Deque_base<_Tp, _Alloc, __bufsiz> _Base;
typedef _Deque_base<_Tp, _Alloc> _Base;
public: // Basic types public: // Basic types
typedef _Tp value_type; typedef _Tp value_type;
typedef value_type* pointer; typedef value_type* pointer;
...@@ -514,8 +460,7 @@ public: // Iterators ...@@ -514,8 +460,7 @@ public: // Iterators
protected: // Internal typedefs protected: // Internal typedefs
typedef pointer* _Map_pointer; typedef pointer* _Map_pointer;
static size_t _S_buffer_size() static size_t _S_buffer_size() { return __deque_buf_size(sizeof(_Tp)); }
{ return __deque_buf_size(__bufsiz, sizeof(_Tp)); }
protected: protected:
#ifdef __STL_USE_NAMESPACES #ifdef __STL_USE_NAMESPACES
...@@ -951,37 +896,15 @@ protected: // Allocation of _M_map and nodes ...@@ -951,37 +896,15 @@ protected: // Allocation of _M_map and nodes
} }
void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front); void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
#ifdef __STL_NON_TYPE_TMPL_PARAM_BUG
public:
bool operator==(const deque<_Tp,_Alloc,0>& __x) const {
return size() == __x.size() && equal(begin(), end(), __x.begin());
}
bool operator!=(const deque<_Tp,_Alloc,0>& __x) const {
return size() != __x.size() || !equal(begin(), end(), __x.begin());
}
bool operator<(const deque<_Tp,_Alloc,0>& __x) const {
return lexicographical_compare(begin(), end(), __x.begin(), __x.end());
}
bool operator>(const deque<_Tp,_Alloc,0>& __x) const {
return __x < *this;
}
bool operator<=(const deque<_Tp,_Alloc,0>& __x) const {
return !(__x < *this);
}
bool operator>=(const deque<_Tp,_Alloc,0>& __x) const {
return !(*this < __x);
}
#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
}; };
// Non-inline member functions // Non-inline member functions
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
template <class _InputIter> template <class _InputIter>
void deque<_Tp, _Alloc, __bufsize> void deque<_Tp, _Alloc>
::_M_assign_aux(_InputIter __first, _InputIter __last, input_iterator_tag) ::_M_assign_aux(_InputIter __first, _InputIter __last, input_iterator_tag)
{ {
iterator __cur = begin(); iterator __cur = begin();
...@@ -995,11 +918,9 @@ void deque<_Tp, _Alloc, __bufsize> ...@@ -995,11 +918,9 @@ void deque<_Tp, _Alloc, __bufsize>
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp, _Alloc>::_M_fill_insert(iterator __pos,
deque<_Tp, _Alloc, __bufsize>::_M_fill_insert(iterator __pos, size_type __n, const value_type& __x)
size_type __n,
const value_type& __x)
{ {
if (__pos._M_cur == _M_start._M_cur) { if (__pos._M_cur == _M_start._M_cur) {
iterator __new_start = _M_reserve_elements_at_front(__n); iterator __new_start = _M_reserve_elements_at_front(__n);
...@@ -1024,10 +945,10 @@ deque<_Tp, _Alloc, __bufsize>::_M_fill_insert(iterator __pos, ...@@ -1024,10 +945,10 @@ deque<_Tp, _Alloc, __bufsize>::_M_fill_insert(iterator __pos,
#ifndef __STL_MEMBER_TEMPLATES #ifndef __STL_MEMBER_TEMPLATES
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void deque<_Tp, _Alloc, __bufsize>::insert(iterator __pos, void deque<_Tp, _Alloc>::insert(iterator __pos,
const value_type* __first, const value_type* __first,
const value_type* __last) { const value_type* __last) {
size_type __n = __last - __first; size_type __n = __last - __first;
if (__pos._M_cur == _M_start._M_cur) { if (__pos._M_cur == _M_start._M_cur) {
iterator __new_start = _M_reserve_elements_at_front(__n); iterator __new_start = _M_reserve_elements_at_front(__n);
...@@ -1050,10 +971,9 @@ void deque<_Tp, _Alloc, __bufsize>::insert(iterator __pos, ...@@ -1050,10 +971,9 @@ void deque<_Tp, _Alloc, __bufsize>::insert(iterator __pos,
_M_insert_aux(__pos, __first, __last, __n); _M_insert_aux(__pos, __first, __last, __n);
} }
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos, void deque<_Tp,_Alloc>::insert(iterator __pos,
const_iterator __first, const_iterator __first, const_iterator __last)
const_iterator __last)
{ {
size_type __n = __last - __first; size_type __n = __last - __first;
if (__pos._M_cur == _M_start._M_cur) { if (__pos._M_cur == _M_start._M_cur) {
...@@ -1079,9 +999,9 @@ void deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos, ...@@ -1079,9 +999,9 @@ void deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos,
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
deque<_Tp,_Alloc,__bufsize>::iterator typename deque<_Tp,_Alloc>::iterator
deque<_Tp,_Alloc,__bufsize>::erase(iterator __first, iterator __last) deque<_Tp,_Alloc>::erase(iterator __first, iterator __last)
{ {
if (__first == _M_start && __last == _M_finish) { if (__first == _M_start && __last == _M_finish) {
clear(); clear();
...@@ -1108,8 +1028,8 @@ deque<_Tp,_Alloc,__bufsize>::erase(iterator __first, iterator __last) ...@@ -1108,8 +1028,8 @@ deque<_Tp,_Alloc,__bufsize>::erase(iterator __first, iterator __last)
} }
} }
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void deque<_Tp,_Alloc,__bufsize>::clear() void deque<_Tp,_Alloc>::clear()
{ {
for (_Map_pointer __node = _M_start._M_node + 1; for (_Map_pointer __node = _M_start._M_node + 1;
__node < _M_finish._M_node; __node < _M_finish._M_node;
...@@ -1131,9 +1051,8 @@ void deque<_Tp,_Alloc,__bufsize>::clear() ...@@ -1131,9 +1051,8 @@ void deque<_Tp,_Alloc,__bufsize>::clear()
// Precondition: _M_start and _M_finish have already been initialized, // Precondition: _M_start and _M_finish have already been initialized,
// but none of the deque's elements have yet been constructed. // but none of the deque's elements have yet been constructed.
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_fill_initialize(const value_type& __value) {
deque<_Tp,_Alloc,__bufsize>::_M_fill_initialize(const value_type& __value) {
_Map_pointer __cur; _Map_pointer __cur;
__STL_TRY { __STL_TRY {
for (__cur = _M_start._M_node; __cur < _M_finish._M_node; ++__cur) for (__cur = _M_start._M_node; __cur < _M_finish._M_node; ++__cur)
...@@ -1145,12 +1064,10 @@ deque<_Tp,_Alloc,__bufsize>::_M_fill_initialize(const value_type& __value) { ...@@ -1145,12 +1064,10 @@ deque<_Tp,_Alloc,__bufsize>::_M_fill_initialize(const value_type& __value) {
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc> template <class _InputIterator>
template <class _InputIterator> void deque<_Tp,_Alloc>::_M_range_initialize(_InputIterator __first,
void _InputIterator __last,
deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_InputIterator __first, input_iterator_tag)
_InputIterator __last,
input_iterator_tag)
{ {
_M_initialize_map(0); _M_initialize_map(0);
__STL_TRY { __STL_TRY {
...@@ -1160,12 +1077,10 @@ deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_InputIterator __first, ...@@ -1160,12 +1077,10 @@ deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_InputIterator __first,
__STL_UNWIND(clear()); __STL_UNWIND(clear());
} }
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc> template <class _ForwardIterator>
template <class _ForwardIterator> void deque<_Tp,_Alloc>::_M_range_initialize(_ForwardIterator __first,
void _ForwardIterator __last,
deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_ForwardIterator __first, forward_iterator_tag)
_ForwardIterator __last,
forward_iterator_tag)
{ {
size_type __n = 0; size_type __n = 0;
distance(__first, __last, __n); distance(__first, __last, __n);
...@@ -1175,7 +1090,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_ForwardIterator __first, ...@@ -1175,7 +1090,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_ForwardIterator __first,
__STL_TRY { __STL_TRY {
for (__cur_node = _M_start._M_node; for (__cur_node = _M_start._M_node;
__cur_node < _M_finish._M_node; __cur_node < _M_finish._M_node;
++__cur_node) { ++__cur_node) {
_ForwardIterator __mid = __first; _ForwardIterator __mid = __first;
advance(__mid, _S_buffer_size()); advance(__mid, _S_buffer_size());
uninitialized_copy(__first, __mid, *__cur_node); uninitialized_copy(__first, __mid, *__cur_node);
...@@ -1189,9 +1104,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_ForwardIterator __first, ...@@ -1189,9 +1104,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_ForwardIterator __first,
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
// Called only if _M_finish._M_cur == _M_finish._M_last - 1. // Called only if _M_finish._M_cur == _M_finish._M_last - 1.
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_push_back_aux(const value_type& __t)
deque<_Tp,_Alloc,__bufsize>::_M_push_back_aux(const value_type& __t)
{ {
value_type __t_copy = __t; value_type __t_copy = __t;
_M_reserve_map_at_back(); _M_reserve_map_at_back();
...@@ -1205,9 +1119,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_push_back_aux(const value_type& __t) ...@@ -1205,9 +1119,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_push_back_aux(const value_type& __t)
} }
// Called only if _M_finish._M_cur == _M_finish._M_last - 1. // Called only if _M_finish._M_cur == _M_finish._M_last - 1.
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_push_back_aux()
deque<_Tp,_Alloc,__bufsize>::_M_push_back_aux()
{ {
_M_reserve_map_at_back(); _M_reserve_map_at_back();
*(_M_finish._M_node + 1) = _M_allocate_node(); *(_M_finish._M_node + 1) = _M_allocate_node();
...@@ -1220,9 +1133,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_push_back_aux() ...@@ -1220,9 +1133,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_push_back_aux()
} }
// Called only if _M_start._M_cur == _M_start._M_first. // Called only if _M_start._M_cur == _M_start._M_first.
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_push_front_aux(const value_type& __t)
deque<_Tp,_Alloc,__bufsize>::_M_push_front_aux(const value_type& __t)
{ {
value_type __t_copy = __t; value_type __t_copy = __t;
_M_reserve_map_at_front(); _M_reserve_map_at_front();
...@@ -1236,9 +1148,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_push_front_aux(const value_type& __t) ...@@ -1236,9 +1148,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_push_front_aux(const value_type& __t)
} }
// Called only if _M_start._M_cur == _M_start._M_first. // Called only if _M_start._M_cur == _M_start._M_first.
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_push_front_aux()
deque<_Tp,_Alloc,__bufsize>::_M_push_front_aux()
{ {
_M_reserve_map_at_front(); _M_reserve_map_at_front();
*(_M_start._M_node - 1) = _M_allocate_node(); *(_M_start._M_node - 1) = _M_allocate_node();
...@@ -1251,9 +1162,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_push_front_aux() ...@@ -1251,9 +1162,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_push_front_aux()
} }
// Called only if _M_finish._M_cur == _M_finish._M_first. // Called only if _M_finish._M_cur == _M_finish._M_first.
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_pop_back_aux()
deque<_Tp,_Alloc,__bufsize>::_M_pop_back_aux()
{ {
_M_deallocate_node(_M_finish._M_first); _M_deallocate_node(_M_finish._M_first);
_M_finish._M_set_node(_M_finish._M_node - 1); _M_finish._M_set_node(_M_finish._M_node - 1);
...@@ -1265,9 +1175,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_pop_back_aux() ...@@ -1265,9 +1175,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_pop_back_aux()
// if the deque has at least one element (a precondition for this member // 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 // function), and if _M_start._M_cur == _M_start._M_last, then the deque
// must have at least two nodes. // must have at least two nodes.
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_pop_front_aux()
deque<_Tp,_Alloc,__bufsize>::_M_pop_front_aux()
{ {
destroy(_M_start._M_cur); destroy(_M_start._M_cur);
_M_deallocate_node(_M_start._M_first); _M_deallocate_node(_M_start._M_first);
...@@ -1277,24 +1186,19 @@ deque<_Tp,_Alloc,__bufsize>::_M_pop_front_aux() ...@@ -1277,24 +1186,19 @@ deque<_Tp,_Alloc,__bufsize>::_M_pop_front_aux()
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc> template <class _InputIterator>
template <class _InputIterator> void deque<_Tp,_Alloc>::insert(iterator __pos,
void _InputIterator __first, _InputIterator __last,
deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos, input_iterator_tag)
_InputIterator __first,
_InputIterator __last,
input_iterator_tag)
{ {
copy(__first, __last, inserter(*this, __pos)); copy(__first, __last, inserter(*this, __pos));
} }
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc> template <class _ForwardIterator>
template <class _ForwardIterator> void
void deque<_Tp,_Alloc>::insert(iterator __pos,
deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos, _ForwardIterator __first, _ForwardIterator __last,
_ForwardIterator __first, forward_iterator_tag) {
_ForwardIterator __last,
forward_iterator_tag) {
size_type __n = 0; size_type __n = 0;
distance(__first, __last, __n); distance(__first, __last, __n);
if (__pos._M_cur == _M_start._M_cur) { if (__pos._M_cur == _M_start._M_cur) {
...@@ -1320,10 +1224,9 @@ deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos, ...@@ -1320,10 +1224,9 @@ deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos,
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
typename deque<_Tp, _Alloc, __bufsize>::iterator typename deque<_Tp, _Alloc>::iterator
deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, deque<_Tp,_Alloc>::_M_insert_aux(iterator __pos, const value_type& __x)
const value_type& __x)
{ {
difference_type __index = __pos - _M_start; difference_type __index = __pos - _M_start;
value_type __x_copy = __x; value_type __x_copy = __x;
...@@ -1351,9 +1254,9 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, ...@@ -1351,9 +1254,9 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
return __pos; return __pos;
} }
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
typename deque<_Tp,_Alloc,__bufsize>::iterator typename deque<_Tp,_Alloc>::iterator
deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos) deque<_Tp,_Alloc>::_M_insert_aux(iterator __pos)
{ {
difference_type __index = __pos - _M_start; difference_type __index = __pos - _M_start;
if (static_cast<size_type>(__index) < size() / 2) { if (static_cast<size_type>(__index) < size() / 2) {
...@@ -1380,16 +1283,15 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos) ...@@ -1380,16 +1283,15 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos)
return __pos; return __pos;
} }
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_insert_aux(iterator __pos,
deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, size_type __n,
size_type __n, const value_type& __x)
const value_type& __x)
{ {
const difference_type __elems_before = __pos - _M_start; const difference_type __elems_before = __pos - _M_start;
size_type __length = size(); size_type __length = this->size();
value_type __x_copy = __x; value_type __x_copy = __x;
if (static_cast<size_type>(__elems_before) < __length / 2) { if (__elems_before < difference_type(__length / 2)) {
iterator __new_start = _M_reserve_elements_at_front(__n); iterator __new_start = _M_reserve_elements_at_front(__n);
iterator __old_start = _M_start; iterator __old_start = _M_start;
__pos = _M_start + __elems_before; __pos = _M_start + __elems_before;
...@@ -1403,7 +1305,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, ...@@ -1403,7 +1305,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
} }
else { else {
__uninitialized_copy_fill(_M_start, __pos, __new_start, __uninitialized_copy_fill(_M_start, __pos, __new_start,
_M_start, __x_copy); _M_start, __x_copy);
_M_start = __new_start; _M_start = __new_start;
fill(__old_start, __pos, __x_copy); fill(__old_start, __pos, __x_copy);
} }
...@@ -1438,13 +1340,11 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, ...@@ -1438,13 +1340,11 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc> template <class _ForwardIterator>
template <class _ForwardIterator> void deque<_Tp,_Alloc>::_M_insert_aux(iterator __pos,
void _ForwardIterator __first,
deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, _ForwardIterator __last,
_ForwardIterator __first, size_type __n)
_ForwardIterator __last,
size_type __n)
{ {
const difference_type __elemsbefore = __pos - _M_start; const difference_type __elemsbefore = __pos - _M_start;
size_type __length = size(); size_type __length = size();
...@@ -1500,12 +1400,11 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, ...@@ -1500,12 +1400,11 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_MEMBER_TEMPLATES */
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_insert_aux(iterator __pos,
deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, const value_type* __first,
const value_type* __first, const value_type* __last,
const value_type* __last, size_type __n)
size_type __n)
{ {
const difference_type __elemsbefore = __pos - _M_start; const difference_type __elemsbefore = __pos - _M_start;
size_type __length = size(); size_type __length = size();
...@@ -1523,7 +1422,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, ...@@ -1523,7 +1422,7 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
} }
else { else {
const value_type* __mid = const value_type* __mid =
__first + (difference_type(__n) - __elemsbefore); __first + (difference_type(__n) - __elemsbefore);
__uninitialized_copy_copy(_M_start, __pos, __first, __mid, __uninitialized_copy_copy(_M_start, __pos, __first, __mid,
__new_start); __new_start);
_M_start = __new_start; _M_start = __new_start;
...@@ -1558,12 +1457,11 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, ...@@ -1558,12 +1457,11 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
} }
} }
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_insert_aux(iterator __pos,
deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, const_iterator __first,
const_iterator __first, const_iterator __last,
const_iterator __last, size_type __n)
size_type __n)
{ {
const difference_type __elemsbefore = __pos - _M_start; const difference_type __elemsbefore = __pos - _M_start;
size_type __length = size(); size_type __length = size();
...@@ -1616,9 +1514,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos, ...@@ -1616,9 +1514,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_new_elements_at_front(size_type __new_elems)
deque<_Tp,_Alloc,__bufsize>::_M_new_elements_at_front(size_type __new_elems)
{ {
size_type __new_nodes size_type __new_nodes
= (__new_elems + _S_buffer_size() - 1) / _S_buffer_size(); = (__new_elems + _S_buffer_size() - 1) / _S_buffer_size();
...@@ -1637,9 +1534,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_new_elements_at_front(size_type __new_elems) ...@@ -1637,9 +1534,8 @@ deque<_Tp,_Alloc,__bufsize>::_M_new_elements_at_front(size_type __new_elems)
# endif /* __STL_USE_EXCEPTIONS */ # endif /* __STL_USE_EXCEPTIONS */
} }
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_new_elements_at_back(size_type __new_elems)
deque<_Tp,_Alloc,__bufsize>::_M_new_elements_at_back(size_type __new_elems)
{ {
size_type __new_nodes size_type __new_nodes
= (__new_elems + _S_buffer_size() - 1) / _S_buffer_size(); = (__new_elems + _S_buffer_size() - 1) / _S_buffer_size();
...@@ -1658,10 +1554,9 @@ deque<_Tp,_Alloc,__bufsize>::_M_new_elements_at_back(size_type __new_elems) ...@@ -1658,10 +1554,9 @@ deque<_Tp,_Alloc,__bufsize>::_M_new_elements_at_back(size_type __new_elems)
# endif /* __STL_USE_EXCEPTIONS */ # endif /* __STL_USE_EXCEPTIONS */
} }
template <class _Tp, class _Alloc, size_t __bufsize> template <class _Tp, class _Alloc>
void void deque<_Tp,_Alloc>::_M_reallocate_map(size_type __nodes_to_add,
deque<_Tp,_Alloc,__bufsize>::_M_reallocate_map(size_type __nodes_to_add, bool __add_at_front)
bool __add_at_front)
{ {
size_type __old_num_nodes = _M_finish._M_node - _M_start._M_node + 1; 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; size_type __new_num_nodes = __old_num_nodes + __nodes_to_add;
...@@ -1697,62 +1592,51 @@ deque<_Tp,_Alloc,__bufsize>::_M_reallocate_map(size_type __nodes_to_add, ...@@ -1697,62 +1592,51 @@ deque<_Tp,_Alloc,__bufsize>::_M_reallocate_map(size_type __nodes_to_add,
// Nonmember functions. // Nonmember functions.
#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG template <class _Tp, class _Alloc>
inline bool operator==(const deque<_Tp, _Alloc>& __x,
template <class _Tp, class _Alloc, size_t __bufsiz> const deque<_Tp, _Alloc>& __y) {
inline bool operator==(const deque<_Tp, _Alloc, __bufsiz>& __x,
const deque<_Tp, _Alloc, __bufsiz>& __y)
{
return __x.size() == __y.size() && return __x.size() == __y.size() &&
equal(__x.begin(), __x.end(), __y.begin()); equal(__x.begin(), __x.end(), __y.begin());
} }
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
inline bool operator<(const deque<_Tp, _Alloc, __bufsiz>& __x, inline bool operator<(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc, __bufsiz>& __y) const deque<_Tp, _Alloc>& __y) {
{
return lexicographical_compare(__x.begin(), __x.end(), return lexicographical_compare(__x.begin(), __x.end(),
__y.begin(), __y.end()); __y.begin(), __y.end());
} }
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
inline bool operator!=(const deque<_Tp, _Alloc, __bufsiz>& __x, inline bool operator!=(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc, __bufsiz>& __y) const deque<_Tp, _Alloc>& __y) {
{
return !(__x == __y); return !(__x == __y);
} }
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
inline bool operator>(const deque<_Tp, _Alloc, __bufsiz>& __x, inline bool operator>(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc, __bufsiz>& __y) const deque<_Tp, _Alloc>& __y) {
{
return __y < __x; return __y < __x;
} }
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
inline bool operator<=(const deque<_Tp, _Alloc, __bufsiz>& __x, inline bool operator<=(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc, __bufsiz>& __y) const deque<_Tp, _Alloc>& __y) {
{
return !(__y < __x); return !(__y < __x);
} }
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
inline bool operator>=(const deque<_Tp, _Alloc, __bufsiz>& __x, inline bool operator>=(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc, __bufsiz>& __y) const deque<_Tp, _Alloc>& __y) {
{
return !(__x < __y); return !(__x < __y);
} }
template <class _Tp, class _Alloc, size_t __bufsiz> template <class _Tp, class _Alloc>
inline void inline void swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y) {
swap(deque<_Tp,_Alloc,__bufsiz>& __x, deque<_Tp,_Alloc,__bufsiz>& __y)
{
__x.swap(__y); __x.swap(__y);
} }
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */ #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174 #pragma reset woff 1174
......
...@@ -411,7 +411,7 @@ struct _Constant_binary_fun { ...@@ -411,7 +411,7 @@ struct _Constant_binary_fun {
template <class _Result> template <class _Result>
struct constant_void_fun : public _Constant_void_fun<_Result> { struct constant_void_fun : public _Constant_void_fun<_Result> {
constant_void_fun(const _Result& __v) : _Constant_void_fun<_Result>(_v) {} constant_void_fun(const _Result& __v) : _Constant_void_fun<_Result>(__v) {}
}; };
......
...@@ -65,6 +65,9 @@ template <class _RandomAccessIterator> ...@@ -65,6 +65,9 @@ template <class _RandomAccessIterator>
inline void inline void
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{ {
__STL_REQUIRES(_RandomAccessIterator, _Mutable_RandomAccessIterator);
__STL_REQUIRES(typename iterator_traits<_RandomAccessIterator>::value_type,
_LessThanComparable);
__push_heap_aux(__first, __last, __push_heap_aux(__first, __last,
__DISTANCE_TYPE(__first), __VALUE_TYPE(__first)); __DISTANCE_TYPE(__first), __VALUE_TYPE(__first));
} }
...@@ -100,6 +103,7 @@ inline void ...@@ -100,6 +103,7 @@ inline void
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Compare __comp) _Compare __comp)
{ {
__STL_REQUIRES(_RandomAccessIterator, _Mutable_RandomAccessIterator);
__push_heap_aux(__first, __last, __comp, __push_heap_aux(__first, __last, __comp,
__DISTANCE_TYPE(__first), __VALUE_TYPE(__first)); __DISTANCE_TYPE(__first), __VALUE_TYPE(__first));
} }
...@@ -147,6 +151,9 @@ template <class _RandomAccessIterator> ...@@ -147,6 +151,9 @@ template <class _RandomAccessIterator>
inline void pop_heap(_RandomAccessIterator __first, inline void pop_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last) _RandomAccessIterator __last)
{ {
__STL_REQUIRES(_RandomAccessIterator, _Mutable_RandomAccessIterator);
__STL_REQUIRES(typename iterator_traits<_RandomAccessIterator>::value_type,
_LessThanComparable);
__pop_heap_aux(__first, __last, __VALUE_TYPE(__first)); __pop_heap_aux(__first, __last, __VALUE_TYPE(__first));
} }
...@@ -198,7 +205,8 @@ inline void ...@@ -198,7 +205,8 @@ inline void
pop_heap(_RandomAccessIterator __first, pop_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp) _RandomAccessIterator __last, _Compare __comp)
{ {
__pop_heap_aux(__first, __last, __VALUE_TYPE(__first), __comp); __STL_REQUIRES(_RandomAccessIterator, _Mutable_RandomAccessIterator);
__pop_heap_aux(__first, __last, __VALUE_TYPE(__first), __comp);
} }
template <class _RandomAccessIterator, class _Tp, class _Distance> template <class _RandomAccessIterator, class _Tp, class _Distance>
...@@ -221,6 +229,9 @@ template <class _RandomAccessIterator> ...@@ -221,6 +229,9 @@ template <class _RandomAccessIterator>
inline void inline void
make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{ {
__STL_REQUIRES(_RandomAccessIterator, _Mutable_RandomAccessIterator);
__STL_REQUIRES(typename iterator_traits<_RandomAccessIterator>::value_type,
_LessThanComparable);
__make_heap(__first, __last, __make_heap(__first, __last,
__VALUE_TYPE(__first), __DISTANCE_TYPE(__first)); __VALUE_TYPE(__first), __DISTANCE_TYPE(__first));
} }
...@@ -248,6 +259,7 @@ inline void ...@@ -248,6 +259,7 @@ inline void
make_heap(_RandomAccessIterator __first, make_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp) _RandomAccessIterator __last, _Compare __comp)
{ {
__STL_REQUIRES(_RandomAccessIterator, _Mutable_RandomAccessIterator);
__make_heap(__first, __last, __comp, __make_heap(__first, __last, __comp,
__VALUE_TYPE(__first), __DISTANCE_TYPE(__first)); __VALUE_TYPE(__first), __DISTANCE_TYPE(__first));
} }
...@@ -255,6 +267,9 @@ make_heap(_RandomAccessIterator __first, ...@@ -255,6 +267,9 @@ make_heap(_RandomAccessIterator __first,
template <class _RandomAccessIterator> template <class _RandomAccessIterator>
void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{ {
__STL_REQUIRES(_RandomAccessIterator, _Mutable_RandomAccessIterator);
__STL_REQUIRES(typename iterator_traits<_RandomAccessIterator>::value_type,
_LessThanComparable);
while (__last - __first > 1) while (__last - __first > 1)
pop_heap(__first, __last--); pop_heap(__first, __last--);
} }
...@@ -264,6 +279,7 @@ void ...@@ -264,6 +279,7 @@ void
sort_heap(_RandomAccessIterator __first, sort_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp) _RandomAccessIterator __last, _Compare __comp)
{ {
__STL_REQUIRES(_RandomAccessIterator, _Mutable_RandomAccessIterator);
while (__last - __first > 1) while (__last - __first > 1)
pop_heap(__first, __last--, __comp); pop_heap(__first, __last--, __comp);
} }
......
...@@ -513,7 +513,7 @@ operator!=(const reverse_iterator<_RandomAccessIterator, _Tp, ...@@ -513,7 +513,7 @@ operator!=(const reverse_iterator<_RandomAccessIterator, _Tp,
_Reference, _Distance>& __x, _Reference, _Distance>& __x,
const reverse_iterator<_RandomAccessIterator, _Tp, const reverse_iterator<_RandomAccessIterator, _Tp,
_Reference, _Distance>& __y) { _Reference, _Distance>& __y) {
return !(__x == __y); } return !(__x == __y);
} }
template <class _RandomAccessIterator, class _Tp, template <class _RandomAccessIterator, class _Tp,
...@@ -679,6 +679,8 @@ private: ...@@ -679,6 +679,8 @@ private:
// operator* or operator++ has been called, _M_is_initialized is false. // operator* or operator++ has been called, _M_is_initialized is false.
template<class _CharT, class _Traits> template<class _CharT, class _Traits>
class istreambuf_iterator class istreambuf_iterator
: public iterator<input_iterator_tag, _CharT,
typename _Traits::off_type, _CharT*, _CharT&>
{ {
public: public:
typedef _CharT char_type; typedef _CharT char_type;
...@@ -687,12 +689,6 @@ public: ...@@ -687,12 +689,6 @@ public:
typedef basic_streambuf<_CharT, _Traits> streambuf_type; typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_istream<_CharT, _Traits> istream_type; typedef basic_istream<_CharT, _Traits> istream_type;
typedef input_iterator_tag iterator_category;
typedef _CharT value_type;
typedef typename _Traits::off_type difference_type;
typedef const _CharT* pointer;
typedef const _CharT& reference;
public: public:
istreambuf_iterator(streambuf_type* __p = 0) { this->_M_init(__p); } istreambuf_iterator(streambuf_type* __p = 0) { this->_M_init(__p); }
istreambuf_iterator(istream_type& __is) { this->_M_init(__is.rdbuf()); } istreambuf_iterator(istream_type& __is) { this->_M_init(__is.rdbuf()); }
...@@ -791,6 +787,7 @@ inline bool operator!=(const istreambuf_iterator<_CharT, _Traits>& __x, ...@@ -791,6 +787,7 @@ inline bool operator!=(const istreambuf_iterator<_CharT, _Traits>& __x,
// The default template argument is declared in iosfwd // The default template argument is declared in iosfwd
template<class _CharT, class _Traits> template<class _CharT, class _Traits>
class ostreambuf_iterator class ostreambuf_iterator
: public iterator<output_iterator_tag, void, void, void, void>
{ {
public: public:
typedef _CharT char_type; typedef _CharT char_type;
...@@ -799,16 +796,10 @@ public: ...@@ -799,16 +796,10 @@ public:
typedef basic_streambuf<_CharT, _Traits> streambuf_type; typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_ostream<_CharT, _Traits> ostream_type; typedef basic_ostream<_CharT, _Traits> ostream_type;
typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
public: public:
ostreambuf_iterator(streambuf_type* __buf) : _M_buf(__buf), _M_ok(__buf) {} ostreambuf_iterator(streambuf_type* __buf) : _M_buf(__buf), _M_ok(__buf) {}
ostreambuf_iterator(ostream_type& __o) ostreambuf_iterator(ostream_type& __o)
: _M_buf(__o.rdbuf()), _M_ok(__o.rdbuf()) {} : _M_buf(__o.rdbuf()), _M_ok(__o.rdbuf() != 0) {}
ostreambuf_iterator& operator=(char_type __c) { ostreambuf_iterator& operator=(char_type __c) {
_M_ok = _M_ok && !traits_type::eq_int_type(_M_buf->sputc(__c), _M_ok = _M_ok && !traits_type::eq_int_type(_M_buf->sputc(__c),
...@@ -837,15 +828,15 @@ inline bool operator==(const istream_iterator<_Tp, _Dist>&, ...@@ -837,15 +828,15 @@ inline bool operator==(const istream_iterator<_Tp, _Dist>&,
template <class _Tp, class _Dist> template <class _Tp, class _Dist>
class istream_iterator { class istream_iterator {
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_TEMPLATE_FRIENDS
template <class _T1, class _D1> template <class _T1, class _D1>
friend bool operator==(const istream_iterator<_T1, _D1>&, friend bool operator==(const istream_iterator<_T1, _D1>&,
const istream_iterator<_T1, _D1>&); const istream_iterator<_T1, _D1>&);
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_TEMPLATE_FRIENDS */
friend bool __STD_QUALIFIER friend bool __STD_QUALIFIER
operator== __STL_NULL_TMPL_ARGS (const istream_iterator&, operator== __STL_NULL_TMPL_ARGS (const istream_iterator&,
const istream_iterator&); const istream_iterator&);
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_TEMPLATE_FRIENDS */
protected: protected:
istream* _M_stream; istream* _M_stream;
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
// The internal file stl_iterator.h contains predefined iterators, // The internal file stl_iterator.h contains predefined iterators,
// such as front_insert_iterator and istream_iterator. // such as front_insert_iterator and istream_iterator.
#include <bits/concept_checks.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
struct input_iterator_tag {}; struct input_iterator_tag {};
...@@ -274,6 +276,7 @@ inline void __distance(_RandomAccessIterator __first, ...@@ -274,6 +276,7 @@ inline void __distance(_RandomAccessIterator __first,
_RandomAccessIterator __last, _RandomAccessIterator __last,
_Distance& __n, random_access_iterator_tag) _Distance& __n, random_access_iterator_tag)
{ {
__STL_REQUIRES(_RandomAccessIterator, _RandomAccessIterator);
__n += __last - __first; __n += __last - __first;
} }
...@@ -281,6 +284,7 @@ template <class _InputIterator, class _Distance> ...@@ -281,6 +284,7 @@ template <class _InputIterator, class _Distance>
inline void distance(_InputIterator __first, inline void distance(_InputIterator __first,
_InputIterator __last, _Distance& __n) _InputIterator __last, _Distance& __n)
{ {
__STL_REQUIRES(_InputIterator, _InputIterator);
__distance(__first, __last, __n, iterator_category(__first)); __distance(__first, __last, __n, iterator_category(__first));
} }
...@@ -301,6 +305,7 @@ template <class _RandomAccessIterator> ...@@ -301,6 +305,7 @@ template <class _RandomAccessIterator>
inline typename iterator_traits<_RandomAccessIterator>::difference_type inline typename iterator_traits<_RandomAccessIterator>::difference_type
__distance(_RandomAccessIterator __first, _RandomAccessIterator __last, __distance(_RandomAccessIterator __first, _RandomAccessIterator __last,
random_access_iterator_tag) { random_access_iterator_tag) {
__STL_REQUIRES(_RandomAccessIterator, _RandomAccessIterator);
return __last - __first; return __last - __first;
} }
...@@ -309,6 +314,7 @@ inline typename iterator_traits<_InputIterator>::difference_type ...@@ -309,6 +314,7 @@ inline typename iterator_traits<_InputIterator>::difference_type
distance(_InputIterator __first, _InputIterator __last) { distance(_InputIterator __first, _InputIterator __last) {
typedef typename iterator_traits<_InputIterator>::iterator_category typedef typename iterator_traits<_InputIterator>::iterator_category
_Category; _Category;
__STL_REQUIRES(_InputIterator, _InputIterator);
return __distance(__first, __last, _Category()); return __distance(__first, __last, _Category());
} }
...@@ -326,6 +332,7 @@ inline void __advance(_InputIter& __i, _Distance __n, input_iterator_tag) { ...@@ -326,6 +332,7 @@ inline void __advance(_InputIter& __i, _Distance __n, input_iterator_tag) {
template <class _BidirectionalIterator, class _Distance> template <class _BidirectionalIterator, class _Distance>
inline void __advance(_BidirectionalIterator& __i, _Distance __n, inline void __advance(_BidirectionalIterator& __i, _Distance __n,
bidirectional_iterator_tag) { bidirectional_iterator_tag) {
__STL_REQUIRES(_BidirectionalIterator, _BidirectionalIterator);
if (__n >= 0) if (__n >= 0)
while (__n--) ++__i; while (__n--) ++__i;
else else
...@@ -339,11 +346,13 @@ inline void __advance(_BidirectionalIterator& __i, _Distance __n, ...@@ -339,11 +346,13 @@ inline void __advance(_BidirectionalIterator& __i, _Distance __n,
template <class _RandomAccessIterator, class _Distance> template <class _RandomAccessIterator, class _Distance>
inline void __advance(_RandomAccessIterator& __i, _Distance __n, inline void __advance(_RandomAccessIterator& __i, _Distance __n,
random_access_iterator_tag) { random_access_iterator_tag) {
__STL_REQUIRES(_RandomAccessIterator, _RandomAccessIterator);
__i += __n; __i += __n;
} }
template <class _InputIterator, class _Distance> template <class _InputIterator, class _Distance>
inline void advance(_InputIterator& __i, _Distance __n) { inline void advance(_InputIterator& __i, _Distance __n) {
__STL_REQUIRES(_InputIterator, _InputIterator);
__advance(__i, __n, iterator_category(__i)); __advance(__i, __n, iterator_category(__i));
} }
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef __SGI_STL_INTERNAL_LIST_H #ifndef __SGI_STL_INTERNAL_LIST_H
#define __SGI_STL_INTERNAL_LIST_H #define __SGI_STL_INTERNAL_LIST_H
#include <bits/concept_checks.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
...@@ -38,67 +40,82 @@ __STL_BEGIN_NAMESPACE ...@@ -38,67 +40,82 @@ __STL_BEGIN_NAMESPACE
#pragma set woff 1375 #pragma set woff 1375
#endif #endif
struct _List_node_base {
_List_node_base* _M_next;
_List_node_base* _M_prev;
};
template <class _Tp> template <class _Tp>
struct _List_node { struct _List_node : public _List_node_base {
typedef void* _Void_pointer;
_Void_pointer _M_next;
_Void_pointer _M_prev;
_Tp _M_data; _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> template<class _Tp, class _Ref, class _Ptr>
struct _List_iterator { struct _List_iterator : public _List_iterator_base {
typedef _List_iterator<_Tp,_Tp&,_Tp*> iterator; typedef _List_iterator<_Tp,_Tp&,_Tp*> iterator;
typedef _List_iterator<_Tp,const _Tp&,const _Tp*> const_iterator; typedef _List_iterator<_Tp,const _Tp&,const _Tp*> const_iterator;
typedef _List_iterator<_Tp,_Ref,_Ptr> _Self; typedef _List_iterator<_Tp,_Ref,_Ptr> _Self;
typedef bidirectional_iterator_tag iterator_category;
typedef _Tp value_type; typedef _Tp value_type;
typedef _Ptr pointer; typedef _Ptr pointer;
typedef _Ref reference; typedef _Ref reference;
typedef _List_node<_Tp> _Node; typedef _List_node<_Tp> _Node;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
_Node* _M_node;
_List_iterator(_Node* __x) : _M_node(__x) {} _List_iterator(_Node* __x) : _List_iterator_base(__x) {}
_List_iterator() {} _List_iterator() {}
_List_iterator(const iterator& __x) : _M_node(__x._M_node) {} _List_iterator(const iterator& __x) : _List_iterator_base(__x._M_node) {}
bool operator==(const _Self& __x) const { return _M_node == __x._M_node; } reference operator*() const { return ((_Node*) _M_node)->_M_data; }
bool operator!=(const _Self& __x) const { return _M_node != __x._M_node; }
reference operator*() const { return (*_M_node)._M_data; }
#ifndef __SGI_STL_NO_ARROW_OPERATOR #ifndef __SGI_STL_NO_ARROW_OPERATOR
pointer operator->() const { return &(operator*()); } pointer operator->() const { return &(operator*()); }
#endif /* __SGI_STL_NO_ARROW_OPERATOR */ #endif /* __SGI_STL_NO_ARROW_OPERATOR */
_Self& operator++() { _Self& operator++() {
_M_node = (_Node*)(_M_node->_M_next); this->_M_incr();
return *this; return *this;
} }
_Self operator++(int) { _Self operator++(int) {
_Self __tmp = *this; _Self __tmp = *this;
++*this; this->_M_incr();
return __tmp; return __tmp;
} }
_Self& operator--() { _Self& operator--() {
_M_node = (_Node*)(_M_node->_M_prev); this->_M_decr();
return *this; return *this;
} }
_Self operator--(int) { _Self operator--(int) {
_Self __tmp = *this; _Self __tmp = *this;
--*this; this->_M_decr();
return __tmp; return __tmp;
} }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION #ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class _Tp, class _Ref, class _Ptr>
inline bidirectional_iterator_tag inline bidirectional_iterator_tag
iterator_category(const _List_iterator<_Tp, _Ref, _Ptr>&) iterator_category(const _List_iterator_base&)
{ {
return bidirectional_iterator_tag(); return bidirectional_iterator_tag();
} }
...@@ -110,9 +127,8 @@ value_type(const _List_iterator<_Tp, _Ref, _Ptr>&) ...@@ -110,9 +127,8 @@ value_type(const _List_iterator<_Tp, _Ref, _Ptr>&)
return 0; return 0;
} }
template <class _Tp, class _Ref, class _Ptr>
inline ptrdiff_t* inline ptrdiff_t*
distance_type(const _List_iterator<_Tp, _Ref, _Ptr>&) distance_type(const _List_iterator_base&)
{ {
return 0; return 0;
} }
...@@ -236,7 +252,7 @@ _List_base<_Tp,_Alloc>::clear() ...@@ -236,7 +252,7 @@ _List_base<_Tp,_Alloc>::clear()
while (__cur != _M_node) { while (__cur != _M_node) {
_List_node<_Tp>* __tmp = __cur; _List_node<_Tp>* __tmp = __cur;
__cur = (_List_node<_Tp>*) __cur->_M_next; __cur = (_List_node<_Tp>*) __cur->_M_next;
destroy(&__tmp->_M_data); _Destroy(&__tmp->_M_data);
_M_put_node(__tmp); _M_put_node(__tmp);
} }
_M_node->_M_next = _M_node; _M_node->_M_next = _M_node;
...@@ -245,6 +261,10 @@ _List_base<_Tp,_Alloc>::clear() ...@@ -245,6 +261,10 @@ _List_base<_Tp,_Alloc>::clear()
template <class _Tp, class _Alloc = allocator<_Tp> > template <class _Tp, class _Alloc = allocator<_Tp> >
class list : protected _List_base<_Tp, _Alloc> { class list : protected _List_base<_Tp, _Alloc> {
// requirements:
__STL_CLASS_REQUIRES(_Tp, _Assignable);
typedef _List_base<_Tp, _Alloc> _Base; typedef _List_base<_Tp, _Alloc> _Base;
protected: protected:
typedef void* _Void_pointer; typedef void* _Void_pointer;
...@@ -290,7 +310,7 @@ protected: ...@@ -290,7 +310,7 @@ protected:
{ {
_Node* __p = _M_get_node(); _Node* __p = _M_get_node();
__STL_TRY { __STL_TRY {
construct(&__p->_M_data, __x); _Construct(&__p->_M_data, __x);
} }
__STL_UNWIND(_M_put_node(__p)); __STL_UNWIND(_M_put_node(__p));
return __p; return __p;
...@@ -300,7 +320,7 @@ protected: ...@@ -300,7 +320,7 @@ protected:
{ {
_Node* __p = _M_get_node(); _Node* __p = _M_get_node();
__STL_TRY { __STL_TRY {
construct(&__p->_M_data); _Construct(&__p->_M_data);
} }
__STL_UNWIND(_M_put_node(__p)); __STL_UNWIND(_M_put_node(__p));
return __p; return __p;
...@@ -344,7 +364,7 @@ public: ...@@ -344,7 +364,7 @@ public:
_Node* __tmp = _M_create_node(__x); _Node* __tmp = _M_create_node(__x);
__tmp->_M_next = __position._M_node; __tmp->_M_next = __position._M_node;
__tmp->_M_prev = __position._M_node->_M_prev; __tmp->_M_prev = __position._M_node->_M_prev;
((_Node*) (__position._M_node->_M_prev))->_M_next = __tmp; __position._M_node->_M_prev->_M_next = __tmp;
__position._M_node->_M_prev = __tmp; __position._M_node->_M_prev = __tmp;
return __tmp; return __tmp;
} }
...@@ -384,19 +404,20 @@ public: ...@@ -384,19 +404,20 @@ public:
void push_back() {insert(end());} void push_back() {insert(end());}
iterator erase(iterator __position) { iterator erase(iterator __position) {
_Node* __next_node = (_Node*) (__position._M_node->_M_next); _List_node_base* __next_node = __position._M_node->_M_next;
_Node* __prev_node = (_Node*) (__position._M_node->_M_prev); _List_node_base* __prev_node = __position._M_node->_M_prev;
_Node* __n = (_Node*) __position._M_node;
__prev_node->_M_next = __next_node; __prev_node->_M_next = __next_node;
__next_node->_M_prev = __prev_node; __next_node->_M_prev = __prev_node;
destroy(&__position._M_node->_M_data); _Destroy(&__n->_M_data);
_M_put_node(__position._M_node); _M_put_node(__n);
return iterator(__next_node); return iterator((_Node*) __next_node);
} }
iterator erase(iterator __first, iterator __last); iterator erase(iterator __first, iterator __last);
void clear() { _Base::clear(); } void clear() { _Base::clear(); }
void resize(size_type __new_size, const _Tp& __x); void resize(size_type __new_size, const _Tp& __x);
void resize(size_type __new_size) { resize(__new_size, _Tp()); } void resize(size_type __new_size) { this->resize(__new_size, _Tp()); }
void pop_front() { erase(begin()); } void pop_front() { erase(begin()); }
void pop_back() { void pop_back() {
...@@ -426,11 +447,11 @@ public: ...@@ -426,11 +447,11 @@ public:
list(const _Tp* __first, const _Tp* __last, list(const _Tp* __first, const _Tp* __last,
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _Base(__a) : _Base(__a)
{ insert(begin(), __first, __last); } { this->insert(begin(), __first, __last); }
list(const_iterator __first, const_iterator __last, list(const_iterator __first, const_iterator __last,
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _Base(__a) : _Base(__a)
{ insert(begin(), __first, __last); } { this->insert(begin(), __first, __last); }
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
list(const list<_Tp, _Alloc>& __x) : _Base(__x.get_allocator()) list(const list<_Tp, _Alloc>& __x) : _Base(__x.get_allocator())
...@@ -472,14 +493,14 @@ protected: ...@@ -472,14 +493,14 @@ protected:
void transfer(iterator __position, iterator __first, iterator __last) { void transfer(iterator __position, iterator __first, iterator __last) {
if (__position != __last) { if (__position != __last) {
// Remove [first, last) from its old position. // Remove [first, last) from its old position.
((_Node*) (__last._M_node->_M_prev))->_M_next = __position._M_node; __last._M_node->_M_prev->_M_next = __position._M_node;
((_Node*) (__first._M_node->_M_prev))->_M_next = __last._M_node; __first._M_node->_M_prev->_M_next = __last._M_node;
((_Node*) (__position._M_node->_M_prev))->_M_next = __first._M_node; __position._M_node->_M_prev->_M_next = __first._M_node;
// Splice [first, last) into its new position. // Splice [first, last) into its new position.
_Node* __tmp = (_Node*) (__position._M_node->_M_prev); _List_node_base* __tmp = __position._M_node->_M_prev;
__position._M_node->_M_prev = __last._M_node->_M_prev; __position._M_node->_M_prev = __last._M_node->_M_prev;
__last._M_node->_M_prev = __first._M_node->_M_prev; __last._M_node->_M_prev = __first._M_node->_M_prev;
__first._M_node->_M_prev = __tmp; __first._M_node->_M_prev = __tmp;
} }
} }
...@@ -487,17 +508,17 @@ protected: ...@@ -487,17 +508,17 @@ protected:
public: public:
void splice(iterator __position, list& __x) { void splice(iterator __position, list& __x) {
if (!__x.empty()) if (!__x.empty())
transfer(__position, __x.begin(), __x.end()); this->transfer(__position, __x.begin(), __x.end());
} }
void splice(iterator __position, list&, iterator __i) { void splice(iterator __position, list&, iterator __i) {
iterator __j = __i; iterator __j = __i;
++__j; ++__j;
if (__position == __i || __position == __j) return; if (__position == __i || __position == __j) return;
transfer(__position, __i, __j); this->transfer(__position, __i, __j);
} }
void splice(iterator __position, list&, iterator __first, iterator __last) { void splice(iterator __position, list&, iterator __first, iterator __last) {
if (__first != __last) if (__first != __last)
transfer(__position, __first, __last); this->transfer(__position, __first, __last);
} }
void remove(const _Tp& __value); void remove(const _Tp& __value);
void unique(); void unique();
...@@ -617,8 +638,8 @@ list<_Tp, _Alloc>::_M_fill_insert(iterator __position, ...@@ -617,8 +638,8 @@ list<_Tp, _Alloc>::_M_fill_insert(iterator __position,
} }
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>
list<_Tp,_Alloc>::iterator list<_Tp, _Alloc>::erase(iterator __first, typename list<_Tp,_Alloc>::iterator list<_Tp, _Alloc>::erase(iterator __first,
iterator __last) iterator __last)
{ {
while (__first != __last) while (__first != __last)
erase(__first++); erase(__first++);
...@@ -733,28 +754,26 @@ void list<_Tp, _Alloc>::merge(list<_Tp, _Alloc>& __x) ...@@ -733,28 +754,26 @@ void list<_Tp, _Alloc>::merge(list<_Tp, _Alloc>& __x)
if (__first2 != __last2) transfer(__last1, __first2, __last2); 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> template <class _Tp, class _Alloc>
void list<_Tp, _Alloc>::reverse() inline void list<_Tp, _Alloc>::reverse()
{ {
// Do nothing if the list has length 0 or 1. __List_base_reverse(this->_M_node);
if (_M_node->_M_next != _M_node &&
((_Node*) (_M_node->_M_next))->_M_next != _M_node) {
iterator __first = begin();
++__first;
while (__first != end()) {
iterator __old = __first;
++__first;
transfer(begin(), __old, __first);
}
}
} }
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>
void list<_Tp, _Alloc>::sort() void list<_Tp, _Alloc>::sort()
{ {
// Do nothing if the list has length 0 or 1. // Do nothing if the list has length 0 or 1.
if (_M_node->_M_next != _M_node && if (_M_node->_M_next != _M_node && _M_node->_M_next->_M_next != _M_node) {
((_Node*) (_M_node->_M_next))->_M_next != _M_node) {
list<_Tp, _Alloc> __carry; list<_Tp, _Alloc> __carry;
list<_Tp, _Alloc> __counter[64]; list<_Tp, _Alloc> __counter[64];
int __fill = 0; int __fill = 0;
...@@ -829,8 +848,7 @@ template <class _Tp, class _Alloc> template <class _StrictWeakOrdering> ...@@ -829,8 +848,7 @@ template <class _Tp, class _Alloc> template <class _StrictWeakOrdering>
void list<_Tp, _Alloc>::sort(_StrictWeakOrdering __comp) void list<_Tp, _Alloc>::sort(_StrictWeakOrdering __comp)
{ {
// Do nothing if the list has length 0 or 1. // Do nothing if the list has length 0 or 1.
if (_M_node->_M_next != _M_node && if (_M_node->_M_next != _M_node && _M_node->_M_next->_M_next != _M_node) {
((_Node*) (_M_node->_M_next))->_M_next != _M_node) {
list<_Tp, _Alloc> __carry; list<_Tp, _Alloc> __carry;
list<_Tp, _Alloc> __counter[64]; list<_Tp, _Alloc> __counter[64];
int __fill = 0; int __fill = 0;
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef _CPP_BITS_STL_MAP_H #ifndef _CPP_BITS_STL_MAP_H
#define _CPP_BITS_STL_MAP_H 1 #define _CPP_BITS_STL_MAP_H 1
#include <bits/concept_checks.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
...@@ -43,6 +45,11 @@ template <class _Key, class _Tp, class _Compare = less<_Key>, ...@@ -43,6 +45,11 @@ template <class _Key, class _Tp, class _Compare = less<_Key>,
class map { class map {
public: public:
// requirements:
__STL_CLASS_REQUIRES(_Tp, _Assignable);
__STL_CLASS_BINARY_FUNCTION_CHECK(_Compare, bool, _Key, _Key);
// typedefs: // typedefs:
typedef _Key key_type; typedef _Key key_type;
...@@ -181,7 +188,9 @@ public: ...@@ -181,7 +188,9 @@ public:
iterator find(const key_type& __x) { return _M_t.find(__x); } iterator find(const key_type& __x) { return _M_t.find(__x); }
const_iterator find(const key_type& __x) const { 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); } 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); } iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); }
const_iterator lower_bound(const key_type& __x) const { const_iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x); return _M_t.lower_bound(__x);
...@@ -198,19 +207,19 @@ public: ...@@ -198,19 +207,19 @@ public:
return _M_t.equal_range(__x); return _M_t.equal_range(__x);
} }
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_TEMPLATE_FRIENDS
template <class _K1, class _T1, class _C1, class _A1> template <class _K1, class _T1, class _C1, class _A1>
friend bool operator== (const map<_K1, _T1, _C1, _A1>&, friend bool operator== (const map<_K1, _T1, _C1, _A1>&,
const map<_K1, _T1, _C1, _A1>&); const map<_K1, _T1, _C1, _A1>&);
template <class _K1, class _T1, class _C1, class _A1> template <class _K1, class _T1, class _C1, class _A1>
friend bool operator< (const map<_K1, _T1, _C1, _A1>&, friend bool operator< (const map<_K1, _T1, _C1, _A1>&,
const map<_K1, _T1, _C1, _A1>&); const map<_K1, _T1, _C1, _A1>&);
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_TEMPLATE_FRIENDS */
friend bool __STD_QUALIFIER friend bool __STD_QUALIFIER
operator== __STL_NULL_TMPL_ARGS (const map&, const map&); operator== __STL_NULL_TMPL_ARGS (const map&, const map&);
friend bool __STD_QUALIFIER friend bool __STD_QUALIFIER
operator< __STL_NULL_TMPL_ARGS (const map&, const map&); operator< __STL_NULL_TMPL_ARGS (const map&, const map&);
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_TEMPLATE_FRIENDS */
}; };
template <class _Key, class _Tp, class _Compare, class _Alloc> template <class _Key, class _Tp, class _Compare, class _Alloc>
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef __SGI_STL_INTERNAL_MULTIMAP_H #ifndef __SGI_STL_INTERNAL_MULTIMAP_H
#define __SGI_STL_INTERNAL_MULTIMAP_H #define __SGI_STL_INTERNAL_MULTIMAP_H
#include <bits/concept_checks.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
...@@ -55,6 +57,11 @@ inline bool operator<(const multimap<_Key,_Tp,_Compare,_Alloc>& __x, ...@@ -55,6 +57,11 @@ inline bool operator<(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
template <class _Key, class _Tp, class _Compare, class _Alloc> template <class _Key, class _Tp, class _Compare, class _Alloc>
class multimap { class multimap {
// requirements:
__STL_CLASS_REQUIRES(_Tp, _Assignable);
__STL_CLASS_BINARY_FUNCTION_CHECK(_Compare, bool, _Key, _Key);
public: public:
// typedefs: // typedefs:
...@@ -200,19 +207,19 @@ public: ...@@ -200,19 +207,19 @@ public:
return _M_t.equal_range(__x); return _M_t.equal_range(__x);
} }
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_TEMPLATE_FRIENDS
template <class _K1, class _T1, class _C1, class _A1> template <class _K1, class _T1, class _C1, class _A1>
friend bool operator== (const multimap<_K1, _T1, _C1, _A1>&, friend bool operator== (const multimap<_K1, _T1, _C1, _A1>&,
const multimap<_K1, _T1, _C1, _A1>&); const multimap<_K1, _T1, _C1, _A1>&);
template <class _K1, class _T1, class _C1, class _A1> template <class _K1, class _T1, class _C1, class _A1>
friend bool operator< (const multimap<_K1, _T1, _C1, _A1>&, friend bool operator< (const multimap<_K1, _T1, _C1, _A1>&,
const multimap<_K1, _T1, _C1, _A1>&); const multimap<_K1, _T1, _C1, _A1>&);
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_TEMPLATE_FRIENDS */
friend bool __STD_QUALIFIER friend bool __STD_QUALIFIER
operator== __STL_NULL_TMPL_ARGS (const multimap&, const multimap&); operator== __STL_NULL_TMPL_ARGS (const multimap&, const multimap&);
friend bool __STD_QUALIFIER friend bool __STD_QUALIFIER
operator< __STL_NULL_TMPL_ARGS (const multimap&, const multimap&); operator< __STL_NULL_TMPL_ARGS (const multimap&, const multimap&);
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_TEMPLATE_FRIENDS */
}; };
template <class _Key, class _Tp, class _Compare, class _Alloc> template <class _Key, class _Tp, class _Compare, class _Alloc>
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef __SGI_STL_INTERNAL_MULTISET_H #ifndef __SGI_STL_INTERNAL_MULTISET_H
#define __SGI_STL_INTERNAL_MULTISET_H #define __SGI_STL_INTERNAL_MULTISET_H
#include <bits/concept_checks.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
...@@ -54,7 +56,13 @@ inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x, ...@@ -54,7 +56,13 @@ inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x,
template <class _Key, class _Compare, class _Alloc> template <class _Key, class _Compare, class _Alloc>
class multiset { class multiset {
// requirements:
__STL_CLASS_REQUIRES(_Key, _Assignable);
__STL_CLASS_BINARY_FUNCTION_CHECK(_Compare, bool, _Key, _Key);
public: public:
// typedefs: // typedefs:
typedef _Key key_type; typedef _Key key_type;
...@@ -191,19 +199,19 @@ public: ...@@ -191,19 +199,19 @@ public:
return _M_t.equal_range(__x); return _M_t.equal_range(__x);
} }
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_TEMPLATE_FRIENDS
template <class _K1, class _C1, class _A1> template <class _K1, class _C1, class _A1>
friend bool operator== (const multiset<_K1,_C1,_A1>&, friend bool operator== (const multiset<_K1,_C1,_A1>&,
const multiset<_K1,_C1,_A1>&); const multiset<_K1,_C1,_A1>&);
template <class _K1, class _C1, class _A1> template <class _K1, class _C1, class _A1>
friend bool operator< (const multiset<_K1,_C1,_A1>&, friend bool operator< (const multiset<_K1,_C1,_A1>&,
const multiset<_K1,_C1,_A1>&); const multiset<_K1,_C1,_A1>&);
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_TEMPLATE_FRIENDS */
friend bool __STD_QUALIFIER friend bool __STD_QUALIFIER
operator== __STL_NULL_TMPL_ARGS (const multiset&, const multiset&); operator== __STL_NULL_TMPL_ARGS (const multiset&, const multiset&);
friend bool __STD_QUALIFIER friend bool __STD_QUALIFIER
operator< __STL_NULL_TMPL_ARGS (const multiset&, const multiset&); operator< __STL_NULL_TMPL_ARGS (const multiset&, const multiset&);
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_TEMPLATE_FRIENDS */
}; };
template <class _Key, class _Compare, class _Alloc> template <class _Key, class _Compare, class _Alloc>
......
...@@ -37,6 +37,7 @@ __STL_BEGIN_NAMESPACE ...@@ -37,6 +37,7 @@ __STL_BEGIN_NAMESPACE
template <class _InputIterator, class _Tp> template <class _InputIterator, class _Tp>
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init) _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
{ {
__STL_REQUIRES(_InputIterator, _InputIterator);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
__init = __init + *__first; __init = __init + *__first;
return __init; return __init;
...@@ -46,6 +47,7 @@ template <class _InputIterator, class _Tp, class _BinaryOperation> ...@@ -46,6 +47,7 @@ template <class _InputIterator, class _Tp, class _BinaryOperation>
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
_BinaryOperation __binary_op) _BinaryOperation __binary_op)
{ {
__STL_REQUIRES(_InputIterator, _InputIterator);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
__init = __binary_op(__init, *__first); __init = __binary_op(__init, *__first);
return __init; return __init;
...@@ -55,6 +57,8 @@ template <class _InputIterator1, class _InputIterator2, class _Tp> ...@@ -55,6 +57,8 @@ template <class _InputIterator1, class _InputIterator2, class _Tp>
_Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init) _InputIterator2 __first2, _Tp __init)
{ {
__STL_REQUIRES(_InputIterator2, _InputIterator);
__STL_REQUIRES(_InputIterator2, _InputIterator);
for ( ; __first1 != __last1; ++__first1, ++__first2) for ( ; __first1 != __last1; ++__first1, ++__first2)
__init = __init + (*__first1 * *__first2); __init = __init + (*__first1 * *__first2);
return __init; return __init;
...@@ -67,6 +71,8 @@ _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1, ...@@ -67,6 +71,8 @@ _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
_BinaryOperation1 __binary_op1, _BinaryOperation1 __binary_op1,
_BinaryOperation2 __binary_op2) _BinaryOperation2 __binary_op2)
{ {
__STL_REQUIRES(_InputIterator2, _InputIterator);
__STL_REQUIRES(_InputIterator2, _InputIterator);
for ( ; __first1 != __last1; ++__first1, ++__first2) for ( ; __first1 != __last1; ++__first1, ++__first2)
__init = __binary_op1(__init, __binary_op2(*__first1, *__first2)); __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
return __init; return __init;
...@@ -90,6 +96,8 @@ _OutputIterator ...@@ -90,6 +96,8 @@ _OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last, partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result) _OutputIterator __result)
{ {
__STL_REQUIRES(_InputIterator, _InputIterator);
__STL_REQUIRES(_OutputIterator, _OutputIterator);
if (__first == __last) return __result; if (__first == __last) return __result;
*__result = *__first; *__result = *__first;
return __partial_sum(__first, __last, __result, __VALUE_TYPE(__first)); return __partial_sum(__first, __last, __result, __VALUE_TYPE(__first));
...@@ -114,6 +122,8 @@ _OutputIterator ...@@ -114,6 +122,8 @@ _OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last, partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op) _OutputIterator __result, _BinaryOperation __binary_op)
{ {
__STL_REQUIRES(_InputIterator, _InputIterator);
__STL_REQUIRES(_OutputIterator, _OutputIterator);
if (__first == __last) return __result; if (__first == __last) return __result;
*__result = *__first; *__result = *__first;
return __partial_sum(__first, __last, __result, __VALUE_TYPE(__first), return __partial_sum(__first, __last, __result, __VALUE_TYPE(__first),
...@@ -139,6 +149,8 @@ _OutputIterator ...@@ -139,6 +149,8 @@ _OutputIterator
adjacent_difference(_InputIterator __first, adjacent_difference(_InputIterator __first,
_InputIterator __last, _OutputIterator __result) _InputIterator __last, _OutputIterator __result)
{ {
__STL_REQUIRES(_InputIterator, _InputIterator);
__STL_REQUIRES(_OutputIterator, _OutputIterator);
if (__first == __last) return __result; if (__first == __last) return __result;
*__result = *__first; *__result = *__first;
return __adjacent_difference(__first, __last, __result, return __adjacent_difference(__first, __last, __result,
...@@ -165,6 +177,8 @@ _OutputIterator ...@@ -165,6 +177,8 @@ _OutputIterator
adjacent_difference(_InputIterator __first, _InputIterator __last, adjacent_difference(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op) _OutputIterator __result, _BinaryOperation __binary_op)
{ {
__STL_REQUIRES(_InputIterator, _InputIterator);
__STL_REQUIRES(_OutputIterator, _OutputIterator);
if (__first == __last) return __result; if (__first == __last) return __result;
*__result = *__first; *__result = *__first;
return __adjacent_difference(__first, __last, __result, return __adjacent_difference(__first, __last, __result,
...@@ -222,10 +236,12 @@ inline _Tp power(_Tp __x, _Integer __n) ...@@ -222,10 +236,12 @@ inline _Tp power(_Tp __x, _Integer __n)
// iota is not part of the C++ standard. It is an extension. // iota is not part of the C++ standard. It is an extension.
template <class _ForwardIterator, class _Tp> template <class _ForwardIter, class _Tp>
void void
iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value) iota(_ForwardIter __first, _ForwardIter __last, _Tp __value)
{ {
__STL_REQUIRES(_ForwardIter, _Mutable_ForwardIterator);
__STL_CONVERTIBLE(_Tp, typename iterator_traits<_ForwardIter>::value_type);
while (__first != __last) while (__first != __last)
*__first++ = __value++; *__first++ = __value++;
} }
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef __SGI_STL_INTERNAL_QUEUE_H #ifndef __SGI_STL_INTERNAL_QUEUE_H
#define __SGI_STL_INTERNAL_QUEUE_H #define __SGI_STL_INTERNAL_QUEUE_H
#include <bits/sequence_concepts.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
// Forward declarations of operators < and ==, needed for friend declaration. // Forward declarations of operators < and ==, needed for friend declaration.
...@@ -49,6 +51,15 @@ inline bool operator<(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&); ...@@ -49,6 +51,15 @@ inline bool operator<(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&);
template <class _Tp, class _Sequence> template <class _Tp, class _Sequence>
class queue { class queue {
// requirements:
__STL_CLASS_REQUIRES(_Tp, _Assignable);
__STL_CLASS_REQUIRES(_Sequence, _FrontInsertionSequence);
__STL_CLASS_REQUIRES(_Sequence, _BackInsertionSequence);
typedef typename _Sequence::value_type _Sequence_value_type;
__STL_CLASS_REQUIRES_SAME_TYPE(_Tp, _Sequence_value_type);
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
template <class _Tp1, class _Seq1> template <class _Tp1, class _Seq1>
friend bool operator== (const queue<_Tp1, _Seq1>&, friend bool operator== (const queue<_Tp1, _Seq1>&,
...@@ -133,10 +144,20 @@ operator>=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) ...@@ -133,10 +144,20 @@ operator>=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y)
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */ #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
template <class _Tp, template <class _Tp,
class _Sequence = vector<_Tp>, class _Sequence __STL_DEPENDENT_DEFAULT_TMPL(vector<_Tp>),
class _Compare = less<typename _Sequence::value_type> > class _Compare
__STL_DEPENDENT_DEFAULT_TMPL(less<typename _Sequence::value_type>) >
class priority_queue { class priority_queue {
public: public:
// requirements:
__STL_CLASS_REQUIRES(_Tp, _Assignable);
__STL_CLASS_REQUIRES(_Sequence, _Sequence);
__STL_CLASS_REQUIRES(_Sequence, _RandomAccessContainer);
typedef typename _Sequence::value_type _Sequence_value_type;
__STL_CLASS_REQUIRES_SAME_TYPE(_Tp, _Sequence_value_type);
__STL_CLASS_BINARY_FUNCTION_CHECK(_Compare, bool, _Tp, _Tp);
typedef typename _Sequence::value_type value_type; typedef typename _Sequence::value_type value_type;
typedef typename _Sequence::size_type size_type; typedef typename _Sequence::size_type size_type;
typedef _Sequence container_type; typedef _Sequence container_type;
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef __SGI_STL_INTERNAL_SET_H #ifndef __SGI_STL_INTERNAL_SET_H
#define __SGI_STL_INTERNAL_SET_H #define __SGI_STL_INTERNAL_SET_H
#include <bits/concept_checks.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
...@@ -55,6 +57,11 @@ inline bool operator<(const set<_Key,_Compare,_Alloc>& __x, ...@@ -55,6 +57,11 @@ inline bool operator<(const set<_Key,_Compare,_Alloc>& __x,
template <class _Key, class _Compare, class _Alloc> template <class _Key, class _Compare, class _Alloc>
class set { class set {
// requirements:
__STL_CLASS_REQUIRES(_Key, _Assignable);
__STL_CLASS_BINARY_FUNCTION_CHECK(_Compare, bool, _Key, _Key);
public: public:
// typedefs: // typedefs:
...@@ -175,7 +182,9 @@ public: ...@@ -175,7 +182,9 @@ public:
// set operations: // set operations:
iterator find(const key_type& __x) const { return _M_t.find(__x); } 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); } 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) const { iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x); return _M_t.lower_bound(__x);
} }
...@@ -186,17 +195,17 @@ public: ...@@ -186,17 +195,17 @@ public:
return _M_t.equal_range(__x); return _M_t.equal_range(__x);
} }
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_TEMPLATE_FRIENDS
template <class _K1, class _C1, class _A1> template <class _K1, class _C1, class _A1>
friend bool operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&); friend bool operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
template <class _K1, class _C1, class _A1> template <class _K1, class _C1, class _A1>
friend bool operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&); friend bool operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_TEMPLATE_FRIENDS */
friend bool __STD_QUALIFIER friend bool __STD_QUALIFIER
operator== __STL_NULL_TMPL_ARGS (const set&, const set&); operator== __STL_NULL_TMPL_ARGS (const set&, const set&);
friend bool __STD_QUALIFIER friend bool __STD_QUALIFIER
operator< __STL_NULL_TMPL_ARGS (const set&, const set&); operator< __STL_NULL_TMPL_ARGS (const set&, const set&);
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_TEMPLATE_FRIENDS */
}; };
template <class _Key, class _Compare, class _Alloc> template <class _Key, class _Compare, class _Alloc>
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef __SGI_STL_INTERNAL_STACK_H #ifndef __SGI_STL_INTERNAL_STACK_H
#define __SGI_STL_INTERNAL_STACK_H #define __SGI_STL_INTERNAL_STACK_H
#include <bits/sequence_concepts.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
// Forward declarations of operators == and <, needed for friend declaration. // Forward declarations of operators == and <, needed for friend declaration.
...@@ -49,6 +51,14 @@ bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y); ...@@ -49,6 +51,14 @@ bool operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y);
template <class _Tp, class _Sequence> template <class _Tp, class _Sequence>
class stack { class stack {
// requirements:
__STL_CLASS_REQUIRES(_Tp, _Assignable);
__STL_CLASS_REQUIRES(_Sequence, _BackInsertionSequence);
typedef typename _Sequence::value_type _Sequence_value_type;
__STL_CLASS_REQUIRES_SAME_TYPE(_Tp, _Sequence_value_type);
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
template <class _Tp1, class _Seq1> template <class _Tp1, class _Seq1>
friend bool operator== (const stack<_Tp1, _Seq1>&, friend bool operator== (const stack<_Tp1, _Seq1>&,
......
...@@ -15,12 +15,11 @@ ...@@ -15,12 +15,11 @@
#define __SGI_STL_STRING_FWD_H #define __SGI_STL_STRING_FWD_H
#include <bits/stl_config.h> #include <bits/stl_config.h>
//#include <bits/std_cstddef.h>
#include <bits/stl_alloc.h> #include <bits/stl_alloc.h>
#include <bits/char_traits.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
template <class _CharT> struct char_traits;
template <class _CharT, template <class _CharT,
class _Traits = char_traits<_CharT>, class _Traits = char_traits<_CharT>,
class _Alloc = allocator<_CharT> > class _Alloc = allocator<_CharT> >
......
...@@ -119,7 +119,7 @@ struct _Refcount_Base ...@@ -119,7 +119,7 @@ struct _Refcount_Base
// In some cases the operation is emulated with a lock. // In some cases the operation is emulated with a lock.
# ifdef __STL_SGI_THREADS # ifdef __STL_SGI_THREADS
inline unsigned long _Atomic_swap(unsigned long * __p, unsigned long __q) { inline unsigned long _Atomic_swap(unsigned long * __p, unsigned long __q) {
# if __mips < 3 || !(defined (_ABIN32) || defined(_ABI64)) # if __mips < 3 || !(defined (_ABIN32) || defined(_ABI64))
return test_and_set(__p, __q); return test_and_set(__p, __q);
# else # else
return __test_and_set(__p, (unsigned long)__q); return __test_and_set(__p, (unsigned long)__q);
...@@ -133,7 +133,7 @@ struct _Refcount_Base ...@@ -133,7 +133,7 @@ struct _Refcount_Base
// We use a template here only to get a unique initialized instance. // We use a template here only to get a unique initialized instance.
template<int __dummy> template<int __dummy>
struct _Swap_lock_struct { struct _Swap_lock_struct {
static pthread_mutex_t _S_swap_lock; static pthread_mutex_t _S_swap_lock;
}; };
template<int __dummy> template<int __dummy>
...@@ -154,7 +154,7 @@ struct _Refcount_Base ...@@ -154,7 +154,7 @@ struct _Refcount_Base
// We use a template here only to get a unique initialized instance. // We use a template here only to get a unique initialized instance.
template<int __dummy> template<int __dummy>
struct _Swap_lock_struct { struct _Swap_lock_struct {
static mutex_t _S_swap_lock; static mutex_t _S_swap_lock;
}; };
template<int __dummy> template<int __dummy>
...@@ -176,7 +176,7 @@ struct _Refcount_Base ...@@ -176,7 +176,7 @@ struct _Refcount_Base
// We use a template here only to get a unique initialized instance. // We use a template here only to get a unique initialized instance.
template<int __dummy> template<int __dummy>
struct _Swap_lock_struct { struct _Swap_lock_struct {
static mutex_t _S_swap_lock; static mutex_t _S_swap_lock;
}; };
# if ( __STL_STATIC_TEMPLATE_DATA > 0 ) # if ( __STL_STATIC_TEMPLATE_DATA > 0 )
...@@ -185,7 +185,7 @@ struct _Refcount_Base ...@@ -185,7 +185,7 @@ struct _Refcount_Base
_Swap_lock_struct<__dummy>::_S_swap_lock = DEFAULTMUTEX; _Swap_lock_struct<__dummy>::_S_swap_lock = DEFAULTMUTEX;
# else # else
__DECLARE_INSTANCE(mutex_t, _Swap_lock_struct<__dummy>::_S_swap_lock, __DECLARE_INSTANCE(mutex_t, _Swap_lock_struct<__dummy>::_S_swap_lock,
=DEFAULTMUTEX); =DEFAULTMUTEX);
# endif /* ( __STL_STATIC_TEMPLATE_DATA > 0 ) */ # endif /* ( __STL_STATIC_TEMPLATE_DATA > 0 ) */
// This should be portable, but performance is expected // This should be portable, but performance is expected
...@@ -218,6 +218,23 @@ struct _Refcount_Base ...@@ -218,6 +218,23 @@ struct _Refcount_Base
// constructors, no base classes, no virtual functions, and no private or // constructors, no base classes, no virtual functions, and no private or
// protected members. // 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;
struct _STL_mutex_lock struct _STL_mutex_lock
{ {
#if defined(__STL_SGI_THREADS) || defined(__STL_WIN32THREADS) #if defined(__STL_SGI_THREADS) || defined(__STL_WIN32THREADS)
...@@ -232,32 +249,25 @@ struct _STL_mutex_lock ...@@ -232,32 +249,25 @@ struct _STL_mutex_lock
__ts.tv_nsec = 1 << __log_nsec; __ts.tv_nsec = 1 << __log_nsec;
nanosleep(&__ts, 0); nanosleep(&__ts, 0);
# elif defined(__STL_WIN32THREADS) # elif defined(__STL_WIN32THREADS)
if (__log_nsec <= 20) { if (__log_nsec <= 20) {
Sleep(0); Sleep(0);
} else { } else {
Sleep(1 << (__log_nsec - 20)); Sleep(1 << (__log_nsec - 20));
} }
# else # else
# error unimplemented # error unimplemented
# endif # endif
} }
void _M_acquire_lock() { void _M_acquire_lock() {
const unsigned __low_spin_max = 30; // spins if we suspect uniprocessor
const unsigned __high_spin_max = 1000; // spins for multiprocessor
static unsigned __spin_max = __low_spin_max;
unsigned __my_spin_max;
static unsigned __last_spins = 0;
unsigned __my_last_spins;
volatile unsigned __junk;
int __i;
volatile unsigned long* __lock = &this->_M_lock; volatile unsigned long* __lock = &this->_M_lock;
if (!_Atomic_swap((unsigned long*)__lock, 1)) { if (!_Atomic_swap((unsigned long*)__lock, 1)) {
return; return;
} }
__my_spin_max = __spin_max; unsigned __my_spin_max = _STL_mutex_spin<0>::__max;
__my_last_spins = __last_spins; unsigned __my_last_spins = _STL_mutex_spin<0>::__last;
__junk = 17; // Value doesn't matter. volatile unsigned __junk = 17; // Value doesn't matter.
unsigned __i;
for (__i = 0; __i < __my_spin_max; __i++) { for (__i = 0; __i < __my_spin_max; __i++) {
if (__i < __my_last_spins/2 || *__lock) { if (__i < __my_last_spins/2 || *__lock) {
__junk *= __junk; __junk *= __junk; __junk *= __junk; __junk *= __junk;
...@@ -269,13 +279,13 @@ struct _STL_mutex_lock ...@@ -269,13 +279,13 @@ struct _STL_mutex_lock
// Spinning worked. Thus we're probably not being scheduled // Spinning worked. Thus we're probably not being scheduled
// against the other process with which we were contending. // against the other process with which we were contending.
// Thus it makes sense to spin longer the next time. // Thus it makes sense to spin longer the next time.
__last_spins = __i; _STL_mutex_spin<0>::__last = __i;
__spin_max = __high_spin_max; _STL_mutex_spin<0>::__max = _STL_mutex_spin<0>::__high_max;
return; return;
} }
} }
// We are probably being scheduled against the other process. Sleep. // We are probably being scheduled against the other process. Sleep.
__spin_max = __low_spin_max; _STL_mutex_spin<0>::__max = _STL_mutex_spin<0>::__low_max;
for (__i = 0 ;; ++__i) { for (__i = 0 ;; ++__i) {
int __log_nsec = __i + 6; int __log_nsec = __i + 6;
...@@ -292,7 +302,7 @@ struct _STL_mutex_lock ...@@ -292,7 +302,7 @@ struct _STL_mutex_lock
asm("sync"); asm("sync");
*__lock = 0; *__lock = 0;
# elif defined(__STL_SGI_THREADS) && __mips >= 3 \ # elif defined(__STL_SGI_THREADS) && __mips >= 3 \
&& (defined (_ABIN32) || defined(_ABI64)) && (defined (_ABIN32) || defined(_ABI64))
__lock_release(__lock); __lock_release(__lock);
# else # else
*__lock = 0; *__lock = 0;
......
...@@ -970,7 +970,7 @@ _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc> ...@@ -970,7 +970,7 @@ _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>
{ {
if (__position._M_node == _M_header->_M_left) { // begin() if (__position._M_node == _M_header->_M_left) { // begin()
if (size() > 0 && if (size() > 0 &&
! _M_key_compare(_S_key(__position._M_node), _KeyOfValue()(__v))) !_M_key_compare(_S_key(__position._M_node), _KeyOfValue()(__v)))
return _M_insert(__position._M_node, __position._M_node, __v); return _M_insert(__position._M_node, __position._M_node, __v);
// first argument just needs to be non-null // first argument just needs to be non-null
else else
......
...@@ -57,10 +57,10 @@ __uninitialized_copy_aux(_InputIter __first, _InputIter __last, ...@@ -57,10 +57,10 @@ __uninitialized_copy_aux(_InputIter __first, _InputIter __last,
_ForwardIter __cur = __result; _ForwardIter __cur = __result;
__STL_TRY { __STL_TRY {
for ( ; __first != __last; ++__first, ++__cur) for ( ; __first != __last; ++__first, ++__cur)
construct(&*__cur, *__first); _Construct(&*__cur, *__first);
return __cur; return __cur;
} }
__STL_UNWIND(destroy(__result, __cur)); __STL_UNWIND(_Destroy(__result, __cur));
} }
...@@ -107,10 +107,10 @@ __uninitialized_copy_n(_InputIter __first, _Size __count, ...@@ -107,10 +107,10 @@ __uninitialized_copy_n(_InputIter __first, _Size __count,
_ForwardIter __cur = __result; _ForwardIter __cur = __result;
__STL_TRY { __STL_TRY {
for ( ; __count > 0 ; --__count, ++__first, ++__cur) for ( ; __count > 0 ; --__count, ++__first, ++__cur)
construct(&*__cur, *__first); _Construct(&*__cur, *__first);
return pair<_InputIter, _ForwardIter>(__first, __cur); return pair<_InputIter, _ForwardIter>(__first, __cur);
} }
__STL_UNWIND(destroy(__result, __cur)); __STL_UNWIND(_Destroy(__result, __cur));
} }
template <class _RandomAccessIter, class _Size, class _ForwardIter> template <class _RandomAccessIter, class _Size, class _ForwardIter>
...@@ -158,9 +158,9 @@ __uninitialized_fill_aux(_ForwardIter __first, _ForwardIter __last, ...@@ -158,9 +158,9 @@ __uninitialized_fill_aux(_ForwardIter __first, _ForwardIter __last,
_ForwardIter __cur = __first; _ForwardIter __cur = __first;
__STL_TRY { __STL_TRY {
for ( ; __cur != __last; ++__cur) for ( ; __cur != __last; ++__cur)
construct(&*__cur, __x); _Construct(&*__cur, __x);
} }
__STL_UNWIND(destroy(__first, __cur)); __STL_UNWIND(_Destroy(__first, __cur));
} }
template <class _ForwardIter, class _Tp, class _Tp1> template <class _ForwardIter, class _Tp, class _Tp1>
...@@ -198,10 +198,10 @@ __uninitialized_fill_n_aux(_ForwardIter __first, _Size __n, ...@@ -198,10 +198,10 @@ __uninitialized_fill_n_aux(_ForwardIter __first, _Size __n,
_ForwardIter __cur = __first; _ForwardIter __cur = __first;
__STL_TRY { __STL_TRY {
for ( ; __n > 0; --__n, ++__cur) for ( ; __n > 0; --__n, ++__cur)
construct(&*__cur, __x); _Construct(&*__cur, __x);
return __cur; return __cur;
} }
__STL_UNWIND(destroy(__first, __cur)); __STL_UNWIND(_Destroy(__first, __cur));
} }
template <class _ForwardIter, class _Size, class _Tp, class _Tp1> template <class _ForwardIter, class _Size, class _Tp, class _Tp1>
...@@ -237,7 +237,7 @@ __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1, ...@@ -237,7 +237,7 @@ __uninitialized_copy_copy(_InputIter1 __first1, _InputIter1 __last1,
__STL_TRY { __STL_TRY {
return uninitialized_copy(__first2, __last2, __mid); return uninitialized_copy(__first2, __last2, __mid);
} }
__STL_UNWIND(destroy(__result, __mid)); __STL_UNWIND(_Destroy(__result, __mid));
} }
// __uninitialized_fill_copy // __uninitialized_fill_copy
...@@ -253,7 +253,7 @@ __uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid, ...@@ -253,7 +253,7 @@ __uninitialized_fill_copy(_ForwardIter __result, _ForwardIter __mid,
__STL_TRY { __STL_TRY {
return uninitialized_copy(__first, __last, __mid); return uninitialized_copy(__first, __last, __mid);
} }
__STL_UNWIND(destroy(__result, __mid)); __STL_UNWIND(_Destroy(__result, __mid));
} }
// __uninitialized_copy_fill // __uninitialized_copy_fill
...@@ -269,7 +269,7 @@ __uninitialized_copy_fill(_InputIter __first1, _InputIter __last1, ...@@ -269,7 +269,7 @@ __uninitialized_copy_fill(_InputIter __first1, _InputIter __last1,
__STL_TRY { __STL_TRY {
uninitialized_fill(__mid2, __last2, __x); uninitialized_fill(__mid2, __last2, __x);
} }
__STL_UNWIND(destroy(__first2, __mid2)); __STL_UNWIND(_Destroy(__first2, __mid2));
} }
__STL_END_NAMESPACE __STL_END_NAMESPACE
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include <bits/exception_support.h> #include <bits/exception_support.h>
#include <bits/concept_checks.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
...@@ -154,6 +156,10 @@ protected: ...@@ -154,6 +156,10 @@ protected:
template <class _Tp, class _Alloc = allocator<_Tp> > template <class _Tp, class _Alloc = allocator<_Tp> >
class vector : protected _Vector_base<_Tp, _Alloc> class vector : protected _Vector_base<_Tp, _Alloc>
{ {
// requirements:
__STL_CLASS_REQUIRES(_Tp, _Assignable);
private: private:
typedef _Vector_base<_Tp, _Alloc> _Base; typedef _Vector_base<_Tp, _Alloc> _Base;
typedef vector<_Tp, _Alloc> vector_type; typedef vector<_Tp, _Alloc> vector_type;
......
...@@ -165,6 +165,7 @@ public: ...@@ -165,6 +165,7 @@ public:
operator== __STL_NULL_TMPL_ARGS (const hash_map&, const hash_map&); operator== __STL_NULL_TMPL_ARGS (const hash_map&, const hash_map&);
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
#include <bits/concept_checks.h>
iterator begin() { return _M_ht.begin(); } iterator begin() { return _M_ht.begin(); }
iterator end() { return _M_ht.end(); } iterator end() { return _M_ht.end(); }
...@@ -260,6 +261,20 @@ template <class _Key, class _Tp, class _HashFcn, class _EqualKey, ...@@ -260,6 +261,20 @@ template <class _Key, class _Tp, class _HashFcn, class _EqualKey,
class _Alloc> class _Alloc>
class hash_multimap class hash_multimap
{ {
// requirements:
__STL_CLASS_REQUIRES(_Key, _Assignable);
__STL_CLASS_REQUIRES(_Tp, _Assignable);
__STL_CLASS_UNARY_FUNCTION_CHECK(_HashFcn, size_t, _Key);
__STL_CLASS_BINARY_FUNCTION_CHECK(_EqualKey, bool, _Key, _Key);
// requirements:
__STL_CLASS_REQUIRES(_Key, _Assignable);
__STL_CLASS_REQUIRES(_Tp, _Assignable);
__STL_CLASS_UNARY_FUNCTION_CHECK(_HashFcn, size_t, _Key);
__STL_CLASS_BINARY_FUNCTION_CHECK(_EqualKey, bool, _Key, _Key);
private: private:
typedef hashtable<pair<const _Key, _Tp>, _Key, _HashFcn, typedef hashtable<pair<const _Key, _Tp>, _Key, _HashFcn,
_Select1st<pair<const _Key, _Tp> >, _EqualKey, _Alloc> _Select1st<pair<const _Key, _Tp> >, _EqualKey, _Alloc>
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include <ext/stl_hashtable.h> #include <ext/stl_hashtable.h>
#include <bits/concept_checks.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
...@@ -56,6 +58,12 @@ operator==(const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs1, ...@@ -56,6 +58,12 @@ operator==(const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs1,
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc> template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
class hash_set class hash_set
{ {
// requirements:
__STL_CLASS_REQUIRES(_Value, _Assignable);
__STL_CLASS_UNARY_FUNCTION_CHECK(_HashFcn, size_t, _Value);
__STL_CLASS_BINARY_FUNCTION_CHECK(_EqualKey, bool, _Value, _Value);
private: private:
typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>, typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>,
_EqualKey, _Alloc> _Ht; _EqualKey, _Alloc> _Ht;
...@@ -254,6 +262,12 @@ operator==(const hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs1, ...@@ -254,6 +262,12 @@ operator==(const hash_multiset<_Val,_HashFcn,_EqualKey,_Alloc>& __hs1,
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc> template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
class hash_multiset class hash_multiset
{ {
// requirements:
__STL_CLASS_REQUIRES(_Value, _Assignable);
__STL_CLASS_UNARY_FUNCTION_CHECK(_HashFcn, size_t, _Value);
__STL_CLASS_BINARY_FUNCTION_CHECK(_EqualKey, bool, _Value, _Value);
private: private:
typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>, typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>,
_EqualKey, _Alloc> _Ht; _EqualKey, _Alloc> _Ht;
......
...@@ -1525,35 +1525,36 @@ const _CharT* rope<_CharT,_Alloc>::replace_with_c_str() { ...@@ -1525,35 +1525,36 @@ const _CharT* rope<_CharT,_Alloc>::replace_with_c_str() {
// Algorithm specializations. More should be added. // Algorithm specializations. More should be added.
#ifndef _MSC_VER template<class _Rope_iterator> // was templated on CharT and Alloc
// I couldn't get this to work with VC++ void // VC++ workaround
template<class _CharT,class _Alloc> _Rope_rotate(_Rope_iterator __first,
void _Rope_iterator __middle,
_Rope_rotate(_Rope_iterator<_CharT,_Alloc> __first, _Rope_iterator __last)
_Rope_iterator<_CharT,_Alloc> __middle,
_Rope_iterator<_CharT,_Alloc> __last)
{ {
__stl_assert(__first.container() == __middle.container() typedef typename _Rope_iterator::value_type _CharT;
&& __middle.container() == __last.container()); typedef typename _Rope_iterator::_allocator_type _Alloc;
rope<_CharT,_Alloc>& __r(__first.container());
rope<_CharT,_Alloc> __prefix = __r.substr(0, __first.index()); __stl_assert(__first.container() == __middle.container()
rope<_CharT,_Alloc> __suffix = && __middle.container() == __last.container());
__r.substr(__last.index(), __r.size() - __last.index()); rope<_CharT,_Alloc>& __r(__first.container());
rope<_CharT,_Alloc> __part1 = rope<_CharT,_Alloc> __prefix = __r.substr(0, __first.index());
__r.substr(__middle.index(), __last.index() - __middle.index()); rope<_CharT,_Alloc> __suffix =
rope<_CharT,_Alloc> __part2 = __r.substr(__last.index(), __r.size() - __last.index());
__r.substr(__first.index(), __middle.index() - __first.index()); rope<_CharT,_Alloc> __part1 =
__r = __prefix; __r.substr(__middle.index(), __last.index() - __middle.index());
__r += __part1; rope<_CharT,_Alloc> __part2 =
__r += __part2; __r.substr(__first.index(), __middle.index() - __first.index());
__r += __suffix; __r = __prefix;
__r += __part1;
__r += __part2;
__r += __suffix;
} }
#if !defined(__GNUC__) #if !defined(__GNUC__)
// Appears to confuse g++ // Appears to confuse g++
inline void rotate(_Rope_iterator<char,allocator<char> > __first, inline void rotate(_Rope_iterator<char,__STL_DEFAULT_ALLOCATOR(char)> __first,
_Rope_iterator<char,allocator<char> > __middle, _Rope_iterator<char,__STL_DEFAULT_ALLOCATOR(char)> __middle,
_Rope_iterator<char,allocator<char> > __last) { _Rope_iterator<char,__STL_DEFAULT_ALLOCATOR(char)> __last) {
_Rope_rotate(__first, __middle, __last); _Rope_rotate(__first, __middle, __last);
} }
#endif #endif
...@@ -1567,13 +1568,13 @@ inline void rotate(_Rope_iterator<char,allocator<char> > __first, ...@@ -1567,13 +1568,13 @@ inline void rotate(_Rope_iterator<char,allocator<char> > __first,
// for unicode strings. Unsigned short may be a better character // for unicode strings. Unsigned short may be a better character
// type. // type.
inline void rotate( inline void rotate(
_Rope_iterator<wchar_t, allocator<char> > __first, _Rope_iterator<wchar_t,__STL_DEFAULT_ALLOCATOR(char)> __first,
_Rope_iterator<wchar_t, allocator<char> > __middle, _Rope_iterator<wchar_t,__STL_DEFAULT_ALLOCATOR(char)> __middle,
_Rope_iterator<wchar_t, allocator<char> > __last) { _Rope_iterator<wchar_t,__STL_DEFAULT_ALLOCATOR(char)> __last) {
_Rope_rotate(__first, __middle, __last); _Rope_rotate(__first, __middle, __last);
} }
# endif # endif
#endif /* _MSC_VER */
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174 #pragma reset woff 1174
......
...@@ -16,13 +16,10 @@ ...@@ -16,13 +16,10 @@
* You should not attempt to use it directly. * You should not attempt to use it directly.
*/ */
#ifndef _CPP_BITS_STL_SLIST_H #ifndef __SGI_STL_INTERNAL_SLIST_H
#define _CPP_BITS_STL_SLIST_H 1 #define __SGI_STL_INTERNAL_SLIST_H
#include <bits/stl_algobase.h> #include <bits/concept_checks.h>
#include <bits/stl_alloc.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
__STL_BEGIN_NAMESPACE __STL_BEGIN_NAMESPACE
...@@ -140,11 +137,11 @@ struct _Slist_iterator : public _Slist_iterator_base ...@@ -140,11 +137,11 @@ struct _Slist_iterator : public _Slist_iterator_base
{ {
typedef _Slist_iterator<_Tp, _Tp&, _Tp*> iterator; typedef _Slist_iterator<_Tp, _Tp&, _Tp*> iterator;
typedef _Slist_iterator<_Tp, const _Tp&, const _Tp*> const_iterator; typedef _Slist_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
typedef _Slist_iterator<_Tp, _Ref, _Ptr> _Self; typedef _Slist_iterator<_Tp, _Ref, _Ptr> _Self;
typedef _Tp value_type; typedef _Tp value_type;
typedef _Ptr pointer; typedef _Ptr pointer;
typedef _Ref reference; typedef _Ref reference;
typedef _Slist_node<_Tp> _Node; typedef _Slist_node<_Tp> _Node;
_Slist_iterator(_Node* __x) : _Slist_iterator_base(__x) {} _Slist_iterator(_Node* __x) : _Slist_iterator_base(__x) {}
...@@ -248,8 +245,9 @@ struct _Slist_base ...@@ -248,8 +245,9 @@ struct _Slist_base
_Base; _Base;
typedef typename _Base::allocator_type allocator_type; typedef typename _Base::allocator_type allocator_type;
_Slist_base(const allocator_type& __a) : _Base(__a) { _M_head._M_next = 0; } _Slist_base(const allocator_type& __a)
~_Slist_base() { _M_erase_after(&_M_head, 0); } : _Base(__a) { this->_M_head._M_next = 0; }
~_Slist_base() { _M_erase_after(&this->_M_head, 0); }
protected: protected:
...@@ -300,7 +298,7 @@ protected: ...@@ -300,7 +298,7 @@ protected:
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>
_Slist_node_base* _Slist_node_base*
_Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first, _Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first,
_Slist_node_base* __last_node) { _Slist_node_base* __last_node) {
_Slist_node<_Tp>* __cur = (_Slist_node<_Tp>*) (__before_first->_M_next); _Slist_node<_Tp>* __cur = (_Slist_node<_Tp>*) (__before_first->_M_next);
while (__cur != __last_node) { while (__cur != __last_node) {
_Slist_node<_Tp>* __tmp = __cur; _Slist_node<_Tp>* __tmp = __cur;
...@@ -312,9 +310,13 @@ _Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first, ...@@ -312,9 +310,13 @@ _Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first,
return __last_node; return __last_node;
} }
template <class _Tp, class _Alloc = allocator<_Tp> > template <class _Tp, class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
class slist : private _Slist_base<_Tp,_Alloc> class slist : private _Slist_base<_Tp,_Alloc>
{ {
// requirements:
__STL_CLASS_REQUIRES(_Tp, _Assignable);
private: private:
typedef _Slist_base<_Tp,_Alloc> _Base; typedef _Slist_base<_Tp,_Alloc> _Base;
public: public:
...@@ -334,46 +336,38 @@ public: ...@@ -334,46 +336,38 @@ public:
private: private:
typedef _Slist_node<_Tp> _Node; typedef _Slist_node<_Tp> _Node;
typedef _Slist_node_base _Node_base; typedef _Slist_node_base _Node_base;
typedef _Slist_iterator_base _Iterator_base; typedef _Slist_iterator_base _Iterator_base;
_Node* _M_create_node(const value_type& __x) { _Node* _M_create_node(const value_type& __x) {
_Node* __node = _M_get_node(); _Node* __node = this->_M_get_node();
__STL_TRY { __STL_TRY {
construct(&__node->_M_data, __x); construct(&__node->_M_data, __x);
__node->_M_next = 0; __node->_M_next = 0;
} }
__STL_UNWIND(_M_put_node(__node)); __STL_UNWIND(this->_M_put_node(__node));
return __node; return __node;
} }
_Node* _M_create_node() { _Node* _M_create_node() {
_Node* __node = _M_get_node(); _Node* __node = this->_M_get_node();
__STL_TRY { __STL_TRY {
construct(&__node->_M_data); construct(&__node->_M_data);
__node->_M_next = 0; __node->_M_next = 0;
} }
__STL_UNWIND(_M_put_node(__node)); __STL_UNWIND(this->_M_put_node(__node));
return __node; return __node;
} }
private:
#ifdef __STL_USE_NAMESPACES
using _Base::_M_get_node;
using _Base::_M_put_node;
using _Base::_M_erase_after;
using _Base::_M_head;
#endif /* __STL_USE_NAMESPACES */
public: public:
explicit slist(const allocator_type& __a = allocator_type()) : _Base(__a) {} explicit slist(const allocator_type& __a = allocator_type()) : _Base(__a) {}
slist(size_type __n, const value_type& __x, slist(size_type __n, const value_type& __x,
const allocator_type& __a = allocator_type()) : _Base(__a) const allocator_type& __a = allocator_type()) : _Base(__a)
{ _M_insert_after_fill(&_M_head, __n, __x); } { _M_insert_after_fill(&this->_M_head, __n, __x); }
explicit slist(size_type __n) : _Base(allocator_type()) explicit slist(size_type __n) : _Base(allocator_type())
{ _M_insert_after_fill(&_M_head, __n, value_type()); } { _M_insert_after_fill(&this->_M_head, __n, value_type()); }
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
// We don't need any dispatching tricks here, because _M_insert_after_range // We don't need any dispatching tricks here, because _M_insert_after_range
...@@ -381,19 +375,19 @@ public: ...@@ -381,19 +375,19 @@ public:
template <class _InputIterator> template <class _InputIterator>
slist(_InputIterator __first, _InputIterator __last, slist(_InputIterator __first, _InputIterator __last,
const allocator_type& __a = allocator_type()) : _Base(__a) const allocator_type& __a = allocator_type()) : _Base(__a)
{ _M_insert_after_range(&_M_head, __first, __last); } { _M_insert_after_range(&this->_M_head, __first, __last); }
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_MEMBER_TEMPLATES */
slist(const_iterator __first, const_iterator __last, slist(const_iterator __first, const_iterator __last,
const allocator_type& __a = allocator_type()) : _Base(__a) const allocator_type& __a = allocator_type()) : _Base(__a)
{ _M_insert_after_range(&_M_head, __first, __last); } { _M_insert_after_range(&this->_M_head, __first, __last); }
slist(const value_type* __first, const value_type* __last, slist(const value_type* __first, const value_type* __last,
const allocator_type& __a = allocator_type()) : _Base(__a) const allocator_type& __a = allocator_type()) : _Base(__a)
{ _M_insert_after_range(&_M_head, __first, __last); } { _M_insert_after_range(&this->_M_head, __first, __last); }
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
slist(const slist& __x) : _Base(__x.get_allocator()) slist(const slist& __x) : _Base(__x.get_allocator())
{ _M_insert_after_range(&_M_head, __x.begin(), __x.end()); } { _M_insert_after_range(&this->_M_head, __x.begin(), __x.end()); }
slist& operator= (const slist& __x); slist& operator= (const slist& __x);
...@@ -431,9 +425,9 @@ public: ...@@ -431,9 +425,9 @@ public:
public: public:
iterator begin() { return iterator((_Node*)_M_head._M_next); } iterator begin() { return iterator((_Node*)this->_M_head._M_next); }
const_iterator begin() const const_iterator begin() const
{ return const_iterator((_Node*)_M_head._M_next);} { return const_iterator((_Node*)this->_M_head._M_next);}
iterator end() { return iterator(0); } iterator end() { return iterator(0); }
const_iterator end() const { return const_iterator(0); } const_iterator end() const { return const_iterator(0); }
...@@ -445,43 +439,41 @@ public: ...@@ -445,43 +439,41 @@ public:
// slist, before_begin() is not the same iterator as end(). It // slist, before_begin() is not the same iterator as end(). It
// is always necessary to increment before_begin() at least once to // is always necessary to increment before_begin() at least once to
// obtain end(). // obtain end().
iterator before_begin() { return iterator((_Node*) &_M_head); } iterator before_begin() { return iterator((_Node*) &this->_M_head); }
const_iterator before_begin() const const_iterator before_begin() const
{ return const_iterator((_Node*) &_M_head); } { return const_iterator((_Node*) &this->_M_head); }
size_type size() const { return __slist_size(_M_head._M_next); } size_type size() const { return __slist_size(this->_M_head._M_next); }
size_type max_size() const { return size_type(-1); } size_type max_size() const { return size_type(-1); }
bool empty() const { return _M_head._M_next == 0; } bool empty() const { return this->_M_head._M_next == 0; }
void swap(slist& __x) { __STD::swap(_M_head._M_next, __x._M_head._M_next); }
public: void swap(slist& __x)
friend bool operator== __STL_NULL_TMPL_ARGS (const slist<_Tp,_Alloc>& _SL1, { __STD::swap(this->_M_head._M_next, __x._M_head._M_next); }
const slist<_Tp,_Alloc>& _SL2);
public: public:
reference front() { return ((_Node*) _M_head._M_next)->_M_data; } reference front() { return ((_Node*) this->_M_head._M_next)->_M_data; }
const_reference front() const const_reference front() const
{ return ((_Node*) _M_head._M_next)->_M_data; } { return ((_Node*) this->_M_head._M_next)->_M_data; }
void push_front(const value_type& __x) { void push_front(const value_type& __x) {
__slist_make_link(&_M_head, _M_create_node(__x)); __slist_make_link(&this->_M_head, _M_create_node(__x));
} }
void push_front() { __slist_make_link(&_M_head, _M_create_node());} void push_front() { __slist_make_link(&this->_M_head, _M_create_node()); }
void pop_front() { void pop_front() {
_Node* __node = (_Node*) _M_head._M_next; _Node* __node = (_Node*) this->_M_head._M_next;
_M_head._M_next = __node->_M_next; this->_M_head._M_next = __node->_M_next;
destroy(&__node->_M_data); destroy(&__node->_M_data);
_M_put_node(__node); this->_M_put_node(__node);
} }
iterator previous(const_iterator __pos) { iterator previous(const_iterator __pos) {
return iterator((_Node*) __slist_previous(&_M_head, __pos._M_node)); return iterator((_Node*) __slist_previous(&this->_M_head, __pos._M_node));
} }
const_iterator previous(const_iterator __pos) const { const_iterator previous(const_iterator __pos) const {
return const_iterator((_Node*) __slist_previous(&_M_head, __pos._M_node)); return const_iterator((_Node*) __slist_previous(&this->_M_head,
__pos._M_node));
} }
private: private:
...@@ -582,17 +574,20 @@ public: ...@@ -582,17 +574,20 @@ public:
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
iterator insert(iterator __pos, const value_type& __x) { iterator insert(iterator __pos, const value_type& __x) {
return iterator(_M_insert_after(__slist_previous(&_M_head, __pos._M_node), return iterator(_M_insert_after(__slist_previous(&this->_M_head,
__pos._M_node),
__x)); __x));
} }
iterator insert(iterator __pos) { iterator insert(iterator __pos) {
return iterator(_M_insert_after(__slist_previous(&_M_head, __pos._M_node), return iterator(_M_insert_after(__slist_previous(&this->_M_head,
__pos._M_node),
value_type())); value_type()));
} }
void insert(iterator __pos, size_type __n, const value_type& __x) { void insert(iterator __pos, size_type __n, const value_type& __x) {
_M_insert_after_fill(__slist_previous(&_M_head, __pos._M_node), __n, __x); _M_insert_after_fill(__slist_previous(&this->_M_head, __pos._M_node),
__n, __x);
} }
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
...@@ -601,19 +596,19 @@ public: ...@@ -601,19 +596,19 @@ public:
// already does them. // already does them.
template <class _InIter> template <class _InIter>
void insert(iterator __pos, _InIter __first, _InIter __last) { void insert(iterator __pos, _InIter __first, _InIter __last) {
_M_insert_after_range(__slist_previous(&_M_head, __pos._M_node), _M_insert_after_range(__slist_previous(&this->_M_head, __pos._M_node),
__first, __last); __first, __last);
} }
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_MEMBER_TEMPLATES */
void insert(iterator __pos, const_iterator __first, const_iterator __last) { void insert(iterator __pos, const_iterator __first, const_iterator __last) {
_M_insert_after_range(__slist_previous(&_M_head, __pos._M_node), _M_insert_after_range(__slist_previous(&this->_M_head, __pos._M_node),
__first, __last); __first, __last);
} }
void insert(iterator __pos, const value_type* __first, void insert(iterator __pos, const value_type* __first,
const value_type* __last) { const value_type* __last) {
_M_insert_after_range(__slist_previous(&_M_head, __pos._M_node), _M_insert_after_range(__slist_previous(&this->_M_head, __pos._M_node),
__first, __last); __first, __last);
} }
...@@ -622,25 +617,25 @@ public: ...@@ -622,25 +617,25 @@ public:
public: public:
iterator erase_after(iterator __pos) { iterator erase_after(iterator __pos) {
return iterator((_Node*) _M_erase_after(__pos._M_node)); return iterator((_Node*) this->_M_erase_after(__pos._M_node));
} }
iterator erase_after(iterator __before_first, iterator __last) { iterator erase_after(iterator __before_first, iterator __last) {
return iterator((_Node*) _M_erase_after(__before_first._M_node, return iterator((_Node*) this->_M_erase_after(__before_first._M_node,
__last._M_node)); __last._M_node));
} }
iterator erase(iterator __pos) { iterator erase(iterator __pos) {
return (_Node*) _M_erase_after(__slist_previous(&_M_head, return (_Node*) this->_M_erase_after(__slist_previous(&this->_M_head,
__pos._M_node)); __pos._M_node));
} }
iterator erase(iterator __first, iterator __last) { iterator erase(iterator __first, iterator __last) {
return (_Node*) _M_erase_after( return (_Node*) this->_M_erase_after(
__slist_previous(&_M_head, __first._M_node), __last._M_node); __slist_previous(&this->_M_head, __first._M_node), __last._M_node);
} }
void resize(size_type new_size, const _Tp& __x); void resize(size_type new_size, const _Tp& __x);
void resize(size_type new_size) { resize(new_size, _Tp()); } void resize(size_type new_size) { resize(new_size, _Tp()); }
void clear() { _M_erase_after(&_M_head, 0); } void clear() { this->_M_erase_after(&this->_M_head, 0); }
public: public:
// Moves the range [__before_first + 1, __before_last + 1) to *this, // Moves the range [__before_first + 1, __before_last + 1) to *this,
...@@ -673,13 +668,13 @@ public: ...@@ -673,13 +668,13 @@ public:
// Linear in distance(begin(), __pos), and linear in __x.size(). // Linear in distance(begin(), __pos), and linear in __x.size().
void splice(iterator __pos, slist& __x) { void splice(iterator __pos, slist& __x) {
if (__x._M_head._M_next) if (__x._M_head._M_next)
__slist_splice_after(__slist_previous(&_M_head, __pos._M_node), __slist_splice_after(__slist_previous(&this->_M_head, __pos._M_node),
&__x._M_head, __slist_previous(&__x._M_head, 0)); &__x._M_head, __slist_previous(&__x._M_head, 0));
} }
// Linear in distance(begin(), __pos), and in distance(__x.begin(), __i). // Linear in distance(begin(), __pos), and in distance(__x.begin(), __i).
void splice(iterator __pos, slist& __x, iterator __i) { void splice(iterator __pos, slist& __x, iterator __i) {
__slist_splice_after(__slist_previous(&_M_head, __pos._M_node), __slist_splice_after(__slist_previous(&this->_M_head, __pos._M_node),
__slist_previous(&__x._M_head, __i._M_node), __slist_previous(&__x._M_head, __i._M_node),
__i._M_node); __i._M_node);
} }
...@@ -689,15 +684,15 @@ public: ...@@ -689,15 +684,15 @@ public:
void splice(iterator __pos, slist& __x, iterator __first, iterator __last) void splice(iterator __pos, slist& __x, iterator __first, iterator __last)
{ {
if (__first != __last) if (__first != __last)
__slist_splice_after(__slist_previous(&_M_head, __pos._M_node), __slist_splice_after(__slist_previous(&this->_M_head, __pos._M_node),
__slist_previous(&__x._M_head, __first._M_node), __slist_previous(&__x._M_head, __first._M_node),
__slist_previous(__first._M_node, __last._M_node)); __slist_previous(__first._M_node, __last._M_node));
} }
public: public:
void reverse() { void reverse() {
if (_M_head._M_next) if (this->_M_head._M_next)
_M_head._M_next = __slist_reverse(_M_head._M_next); this->_M_head._M_next = __slist_reverse(this->_M_head._M_next);
} }
void remove(const _Tp& __val); void remove(const _Tp& __val);
...@@ -724,8 +719,8 @@ template <class _Tp, class _Alloc> ...@@ -724,8 +719,8 @@ template <class _Tp, class _Alloc>
slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x) slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x)
{ {
if (&__x != this) { if (&__x != this) {
_Node_base* __p1 = &_M_head; _Node_base* __p1 = &this->_M_head;
_Node* __n1 = (_Node*) _M_head._M_next; _Node* __n1 = (_Node*) this->_M_head._M_next;
const _Node* __n2 = (const _Node*) __x._M_head._M_next; const _Node* __n2 = (const _Node*) __x._M_head._M_next;
while (__n1 && __n2) { while (__n1 && __n2) {
__n1->_M_data = __n2->_M_data; __n1->_M_data = __n2->_M_data;
...@@ -734,7 +729,7 @@ slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x) ...@@ -734,7 +729,7 @@ slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x)
__n2 = (const _Node*) __n2->_M_next; __n2 = (const _Node*) __n2->_M_next;
} }
if (__n2 == 0) if (__n2 == 0)
_M_erase_after(__p1, 0); this->_M_erase_after(__p1, 0);
else else
_M_insert_after_range(__p1, const_iterator((_Node*)__n2), _M_insert_after_range(__p1, const_iterator((_Node*)__n2),
const_iterator(0)); const_iterator(0));
...@@ -744,8 +739,8 @@ slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x) ...@@ -744,8 +739,8 @@ slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x)
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>
void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) { void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
_Node_base* __prev = &_M_head; _Node_base* __prev = &this->_M_head;
_Node* __node = (_Node*) _M_head._M_next; _Node* __node = (_Node*) this->_M_head._M_next;
for ( ; __node != 0 && __n > 0 ; --__n) { for ( ; __node != 0 && __n > 0 ; --__n) {
__node->_M_data = __val; __node->_M_data = __val;
__prev = __node; __prev = __node;
...@@ -754,7 +749,7 @@ void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) { ...@@ -754,7 +749,7 @@ void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
if (__n > 0) if (__n > 0)
_M_insert_after_fill(__prev, __n, __val); _M_insert_after_fill(__prev, __n, __val);
else else
_M_erase_after(__prev, 0); this->_M_erase_after(__prev, 0);
} }
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
...@@ -762,10 +757,10 @@ void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) { ...@@ -762,10 +757,10 @@ void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
template <class _Tp, class _Alloc> template <class _InputIter> template <class _Tp, class _Alloc> template <class _InputIter>
void void
slist<_Tp, _Alloc>::_M_assign_dispatch(_InputIter __first, _InputIter __last, slist<_Tp, _Alloc>::_M_assign_dispatch(_InputIter __first, _InputIter __last,
__false_type) __false_type)
{ {
_Node_base* __prev = &_M_head; _Node_base* __prev = &this->_M_head;
_Node* __node = (_Node*) _M_head._M_next; _Node* __node = (_Node*) this->_M_head._M_next;
while (__node != 0 && __first != __last) { while (__node != 0 && __first != __last) {
__node->_M_data = *__first; __node->_M_data = *__first;
__prev = __node; __prev = __node;
...@@ -775,7 +770,7 @@ slist<_Tp, _Alloc>::_M_assign_dispatch(_InputIter __first, _InputIter __last, ...@@ -775,7 +770,7 @@ slist<_Tp, _Alloc>::_M_assign_dispatch(_InputIter __first, _InputIter __last,
if (__first != __last) if (__first != __last)
_M_insert_after_range(__prev, __first, __last); _M_insert_after_range(__prev, __first, __last);
else else
_M_erase_after(__prev, 0); this->_M_erase_after(__prev, 0);
} }
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
...@@ -784,19 +779,23 @@ template <class _Tp, class _Alloc> ...@@ -784,19 +779,23 @@ template <class _Tp, class _Alloc>
inline bool inline bool
operator==(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2) operator==(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2)
{ {
typedef typename slist<_Tp,_Alloc>::_Node _Node; typedef typename slist<_Tp,_Alloc>::const_iterator const_iterator;
_Node* __n1 = (_Node*) _SL1._M_head._M_next; const_iterator __end1 = _SL1.end();
_Node* __n2 = (_Node*) _SL2._M_head._M_next; const_iterator __end2 = _SL2.end();
while (__n1 && __n2 && __n1->_M_data == __n2->_M_data) {
__n1 = (_Node*) __n1->_M_next; const_iterator __i1 = _SL1.begin();
__n2 = (_Node*) __n2->_M_next; const_iterator __i2 = _SL2.begin();
} while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) {
return __n1 == 0 && __n2 == 0; ++__i1;
++__i2;
}
return __i1 == __end1 && __i2 == __end2;
} }
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>
inline bool operator<(const slist<_Tp,_Alloc>& _SL1, inline bool
const slist<_Tp,_Alloc>& _SL2) operator<(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2)
{ {
return lexicographical_compare(_SL1.begin(), _SL1.end(), return lexicographical_compare(_SL1.begin(), _SL1.end(),
_SL2.begin(), _SL2.end()); _SL2.begin(), _SL2.end());
...@@ -805,6 +804,30 @@ inline bool operator<(const slist<_Tp,_Alloc>& _SL1, ...@@ -805,6 +804,30 @@ inline bool operator<(const slist<_Tp,_Alloc>& _SL1,
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>
inline bool
operator!=(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2) {
return !(_SL1 == _SL2);
}
template <class _Tp, class _Alloc>
inline bool
operator>(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2) {
return _SL2 < _SL1;
}
template <class _Tp, class _Alloc>
inline bool
operator<=(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2) {
return !(_SL2 < _SL1);
}
template <class _Tp, class _Alloc>
inline bool
operator>=(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2) {
return !(_SL1 < _SL2);
}
template <class _Tp, class _Alloc>
inline void swap(slist<_Tp,_Alloc>& __x, slist<_Tp,_Alloc>& __y) { inline void swap(slist<_Tp,_Alloc>& __x, slist<_Tp,_Alloc>& __y) {
__x.swap(__y); __x.swap(__y);
} }
...@@ -815,13 +838,13 @@ inline void swap(slist<_Tp,_Alloc>& __x, slist<_Tp,_Alloc>& __y) { ...@@ -815,13 +838,13 @@ inline void swap(slist<_Tp,_Alloc>& __x, slist<_Tp,_Alloc>& __y) {
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>
void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x) void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x)
{ {
_Node_base* __cur = &_M_head; _Node_base* __cur = &this->_M_head;
while (__cur->_M_next != 0 && __len > 0) { while (__cur->_M_next != 0 && __len > 0) {
--__len; --__len;
__cur = __cur->_M_next; __cur = __cur->_M_next;
} }
if (__cur->_M_next) if (__cur->_M_next)
_M_erase_after(__cur, 0); this->_M_erase_after(__cur, 0);
else else
_M_insert_after_fill(__cur, __len, __x); _M_insert_after_fill(__cur, __len, __x);
} }
...@@ -829,10 +852,10 @@ void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x) ...@@ -829,10 +852,10 @@ void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x)
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>
void slist<_Tp,_Alloc>::remove(const _Tp& __val) void slist<_Tp,_Alloc>::remove(const _Tp& __val)
{ {
_Node_base* __cur = &_M_head; _Node_base* __cur = &this->_M_head;
while (__cur && __cur->_M_next) { while (__cur && __cur->_M_next) {
if (((_Node*) __cur->_M_next)->_M_data == __val) if (((_Node*) __cur->_M_next)->_M_data == __val)
_M_erase_after(__cur); this->_M_erase_after(__cur);
else else
__cur = __cur->_M_next; __cur = __cur->_M_next;
} }
...@@ -841,12 +864,12 @@ void slist<_Tp,_Alloc>::remove(const _Tp& __val) ...@@ -841,12 +864,12 @@ void slist<_Tp,_Alloc>::remove(const _Tp& __val)
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>
void slist<_Tp,_Alloc>::unique() void slist<_Tp,_Alloc>::unique()
{ {
_Node_base* __cur = _M_head._M_next; _Node_base* __cur = this->_M_head._M_next;
if (__cur) { if (__cur) {
while (__cur->_M_next) { while (__cur->_M_next) {
if (((_Node*)__cur)->_M_data == if (((_Node*)__cur)->_M_data ==
((_Node*)(__cur->_M_next))->_M_data) ((_Node*)(__cur->_M_next))->_M_data)
_M_erase_after(__cur); this->_M_erase_after(__cur);
else else
__cur = __cur->_M_next; __cur = __cur->_M_next;
} }
...@@ -856,7 +879,7 @@ void slist<_Tp,_Alloc>::unique() ...@@ -856,7 +879,7 @@ void slist<_Tp,_Alloc>::unique()
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>
void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x) void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x)
{ {
_Node_base* __n1 = &_M_head; _Node_base* __n1 = &this->_M_head;
while (__n1->_M_next && __x._M_head._M_next) { while (__n1->_M_next && __x._M_head._M_next) {
if (((_Node*) __x._M_head._M_next)->_M_data < if (((_Node*) __x._M_head._M_next)->_M_data <
((_Node*) __n1->_M_next)->_M_data) ((_Node*) __n1->_M_next)->_M_data)
...@@ -872,12 +895,13 @@ void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x) ...@@ -872,12 +895,13 @@ void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x)
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>
void slist<_Tp,_Alloc>::sort() void slist<_Tp,_Alloc>::sort()
{ {
if (_M_head._M_next && _M_head._M_next->_M_next) { if (this->_M_head._M_next && this->_M_head._M_next->_M_next) {
slist __carry; slist __carry;
slist __counter[64]; slist __counter[64];
int __fill = 0; int __fill = 0;
while (!empty()) { while (!empty()) {
__slist_splice_after(&__carry._M_head, &_M_head, _M_head._M_next); __slist_splice_after(&__carry._M_head,
&this->_M_head, this->_M_head._M_next);
int __i = 0; int __i = 0;
while (__i < __fill && !__counter[__i].empty()) { while (__i < __fill && !__counter[__i].empty()) {
__counter[__i].merge(__carry); __counter[__i].merge(__carry);
...@@ -901,10 +925,10 @@ template <class _Tp, class _Alloc> ...@@ -901,10 +925,10 @@ template <class _Tp, class _Alloc>
template <class _Predicate> template <class _Predicate>
void slist<_Tp,_Alloc>::remove_if(_Predicate __pred) void slist<_Tp,_Alloc>::remove_if(_Predicate __pred)
{ {
_Node_base* __cur = &_M_head; _Node_base* __cur = &this->_M_head;
while (__cur->_M_next) { while (__cur->_M_next) {
if (__pred(((_Node*) __cur->_M_next)->_M_data)) if (__pred(((_Node*) __cur->_M_next)->_M_data))
_M_erase_after(__cur); this->_M_erase_after(__cur);
else else
__cur = __cur->_M_next; __cur = __cur->_M_next;
} }
...@@ -913,12 +937,12 @@ void slist<_Tp,_Alloc>::remove_if(_Predicate __pred) ...@@ -913,12 +937,12 @@ void slist<_Tp,_Alloc>::remove_if(_Predicate __pred)
template <class _Tp, class _Alloc> template <class _BinaryPredicate> template <class _Tp, class _Alloc> template <class _BinaryPredicate>
void slist<_Tp,_Alloc>::unique(_BinaryPredicate __pred) void slist<_Tp,_Alloc>::unique(_BinaryPredicate __pred)
{ {
_Node* __cur = (_Node*) _M_head._M_next; _Node* __cur = (_Node*) this->_M_head._M_next;
if (__cur) { if (__cur) {
while (__cur->_M_next) { while (__cur->_M_next) {
if (__pred(((_Node*)__cur)->_M_data, if (__pred(((_Node*)__cur)->_M_data,
((_Node*)(__cur->_M_next))->_M_data)) ((_Node*)(__cur->_M_next))->_M_data))
_M_erase_after(__cur); this->_M_erase_after(__cur);
else else
__cur = (_Node*) __cur->_M_next; __cur = (_Node*) __cur->_M_next;
} }
...@@ -927,9 +951,9 @@ void slist<_Tp,_Alloc>::unique(_BinaryPredicate __pred) ...@@ -927,9 +951,9 @@ void slist<_Tp,_Alloc>::unique(_BinaryPredicate __pred)
template <class _Tp, class _Alloc> template <class _StrictWeakOrdering> template <class _Tp, class _Alloc> template <class _StrictWeakOrdering>
void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x, void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x,
_StrictWeakOrdering __comp) _StrictWeakOrdering __comp)
{ {
_Node_base* __n1 = &_M_head; _Node_base* __n1 = &this->_M_head;
while (__n1->_M_next && __x._M_head._M_next) { while (__n1->_M_next && __x._M_head._M_next) {
if (__comp(((_Node*) __x._M_head._M_next)->_M_data, if (__comp(((_Node*) __x._M_head._M_next)->_M_data,
((_Node*) __n1->_M_next)->_M_data)) ((_Node*) __n1->_M_next)->_M_data))
...@@ -945,12 +969,13 @@ void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x, ...@@ -945,12 +969,13 @@ void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x,
template <class _Tp, class _Alloc> template <class _StrictWeakOrdering> template <class _Tp, class _Alloc> template <class _StrictWeakOrdering>
void slist<_Tp,_Alloc>::sort(_StrictWeakOrdering __comp) void slist<_Tp,_Alloc>::sort(_StrictWeakOrdering __comp)
{ {
if (_M_head._M_next && _M_head._M_next->_M_next) { if (this->_M_head._M_next && this->_M_head._M_next->_M_next) {
slist __carry; slist __carry;
slist __counter[64]; slist __counter[64];
int __fill = 0; int __fill = 0;
while (!empty()) { while (!empty()) {
__slist_splice_after(&__carry._M_head, &_M_head, _M_head._M_next); __slist_splice_after(&__carry._M_head,
&this->_M_head, this->_M_head._M_next);
int __i = 0; int __i = 0;
while (__i < __fill && !__counter[__i].empty()) { while (__i < __fill && !__counter[__i].empty()) {
__counter[__i].merge(__carry, __comp); __counter[__i].merge(__carry, __comp);
...@@ -1016,7 +1041,7 @@ public: ...@@ -1016,7 +1041,7 @@ public:
__STL_END_NAMESPACE __STL_END_NAMESPACE
#endif /* _CPP_BITS_STL_SLIST_H */ #endif /* __SGI_STL_INTERNAL_SLIST_H */
// Local Variables: // Local Variables:
// mode:C++ // mode:C++
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* purpose. It is provided "as is" without express or implied warranty. * purpose. It is provided "as is" without express or implied warranty.
* *
* *
* Copyright (c) 1996,1997 * Copyright (c) 1996-1999
* Silicon Graphics Computer Systems, Inc. * Silicon Graphics Computer Systems, Inc.
* *
* Permission to use, copy, modify, distribute and sell this software * Permission to use, copy, modify, distribute and sell this software
...@@ -72,57 +72,95 @@ inline void swap(_Bit_reference __x, _Bit_reference __y) ...@@ -72,57 +72,95 @@ inline void swap(_Bit_reference __x, _Bit_reference __y)
__y = __tmp; __y = __tmp;
} }
struct _Bit_iterator : public random_access_iterator<bool, ptrdiff_t> { struct _Bit_iterator_base : public random_access_iterator<bool, ptrdiff_t>
typedef _Bit_reference reference; {
typedef _Bit_reference* pointer;
typedef _Bit_iterator iterator;
unsigned int* _M_p; unsigned int* _M_p;
unsigned int _M_offset; unsigned int _M_offset;
void bump_up() {
_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) { if (_M_offset++ == __WORD_BIT - 1) {
_M_offset = 0; _M_offset = 0;
++_M_p; ++_M_p;
} }
} }
void bump_down() { void _M_bump_down() {
if (_M_offset-- == 0) { if (_M_offset-- == 0) {
_M_offset = __WORD_BIT - 1; _M_offset = __WORD_BIT - 1;
--_M_p; --_M_p;
} }
} }
_Bit_iterator() : _M_p(0), _M_offset(0) {} 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(unsigned int* __x, unsigned int __y)
: _M_p(__x), _M_offset(__y) {} : _Bit_iterator_base(__x, __y) {}
reference operator*() const { return reference(_M_p, 1U << _M_offset); } reference operator*() const { return reference(_M_p, 1U << _M_offset); }
iterator& operator++() { iterator& operator++() {
bump_up(); _M_bump_up();
return *this; return *this;
} }
iterator operator++(int) { iterator operator++(int) {
iterator __tmp = *this; iterator __tmp = *this;
bump_up(); _M_bump_up();
return __tmp; return __tmp;
} }
iterator& operator--() { iterator& operator--() {
bump_down(); _M_bump_down();
return *this; return *this;
} }
iterator operator--(int) { iterator operator--(int) {
iterator __tmp = *this; iterator __tmp = *this;
bump_down(); _M_bump_down();
return __tmp; return __tmp;
} }
iterator& operator+=(difference_type __i) { iterator& operator+=(difference_type __i) {
difference_type __n = __i + _M_offset; _M_incr(__i);
_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;
return *this; return *this;
} }
iterator& operator-=(difference_type __i) { iterator& operator-=(difference_type __i) {
...@@ -137,82 +175,50 @@ struct _Bit_iterator : public random_access_iterator<bool, ptrdiff_t> { ...@@ -137,82 +175,50 @@ struct _Bit_iterator : public random_access_iterator<bool, ptrdiff_t> {
iterator __tmp = *this; iterator __tmp = *this;
return __tmp -= __i; return __tmp -= __i;
} }
difference_type operator-(iterator __x) const {
return __WORD_BIT * (_M_p - __x._M_p) + _M_offset - __x._M_offset;
}
reference operator[](difference_type __i) { return *(*this + __i); } reference operator[](difference_type __i) { return *(*this + __i); }
bool operator==(const iterator& __x) const {
return _M_p == __x._M_p && _M_offset == __x._M_offset;
}
bool operator!=(const iterator& __x) const {
return _M_p != __x._M_p || _M_offset != __x._M_offset;
}
bool operator<(iterator __x) const {
return _M_p < __x._M_p || (_M_p == __x._M_p && _M_offset < __x._M_offset);
}
bool operator>(const iterator& __x) const { return __x < *this; }
bool operator<=(const iterator& __x) const { return !(__x < *this); }
bool operator>=(const iterator& __x) const { return !(*this < __x); }
}; };
struct _Bit_const_iterator inline _Bit_iterator
: public random_access_iterator<bool, ptrdiff_t> operator+(ptrdiff_t __n, const _Bit_iterator& __x) { return __x + __n; }
struct _Bit_const_iterator : public _Bit_iterator_base
{ {
typedef bool reference; typedef bool reference;
typedef bool const_reference; typedef bool const_reference;
typedef const bool* pointer; typedef const bool* pointer;
typedef _Bit_const_iterator const_iterator; typedef _Bit_const_iterator const_iterator;
unsigned int* _M_p; _Bit_const_iterator() : _Bit_iterator_base(0, 0) {}
unsigned int _M_offset;
void bump_up() {
if (_M_offset++ == __WORD_BIT - 1) {
_M_offset = 0;
++_M_p;
}
}
void bump_down() {
if (_M_offset-- == 0) {
_M_offset = __WORD_BIT - 1;
--_M_p;
}
}
_Bit_const_iterator() : _M_p(0), _M_offset(0) {}
_Bit_const_iterator(unsigned int* __x, unsigned int __y) _Bit_const_iterator(unsigned int* __x, unsigned int __y)
: _M_p(__x), _M_offset(__y) {} : _Bit_iterator_base(__x, __y) {}
_Bit_const_iterator(const _Bit_iterator& __x) _Bit_const_iterator(const _Bit_iterator& __x)
: _M_p(__x._M_p), _M_offset(__x._M_offset) {} : _Bit_iterator_base(__x._M_p, __x._M_offset) {}
const_reference operator*() const { const_reference operator*() const {
return _Bit_reference(_M_p, 1U << _M_offset); return _Bit_reference(_M_p, 1U << _M_offset);
} }
const_iterator& operator++() { const_iterator& operator++() {
bump_up(); _M_bump_up();
return *this; return *this;
} }
const_iterator operator++(int) { const_iterator operator++(int) {
const_iterator __tmp = *this; const_iterator __tmp = *this;
bump_up(); _M_bump_up();
return __tmp; return __tmp;
} }
const_iterator& operator--() { const_iterator& operator--() {
bump_down(); _M_bump_down();
return *this; return *this;
} }
const_iterator operator--(int) { const_iterator operator--(int) {
const_iterator __tmp = *this; const_iterator __tmp = *this;
bump_down(); _M_bump_down();
return __tmp; return __tmp;
} }
const_iterator& operator+=(difference_type __i) { const_iterator& operator+=(difference_type __i) {
difference_type __n = __i + _M_offset; _M_incr(__i);
_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;
return *this; return *this;
} }
const_iterator& operator-=(difference_type __i) { const_iterator& operator-=(difference_type __i) {
...@@ -227,28 +233,17 @@ struct _Bit_const_iterator ...@@ -227,28 +233,17 @@ struct _Bit_const_iterator
const_iterator __tmp = *this; const_iterator __tmp = *this;
return __tmp -= __i; return __tmp -= __i;
} }
difference_type operator-(const_iterator __x) const {
return __WORD_BIT * (_M_p - __x._M_p) + _M_offset - __x._M_offset;
}
const_reference operator[](difference_type __i) { const_reference operator[](difference_type __i) {
return *(*this + __i); return *(*this + __i);
} }
bool operator==(const const_iterator& __x) const {
return _M_p == __x._M_p && _M_offset == __x._M_offset;
}
bool operator!=(const const_iterator& __x) const {
return _M_p != __x._M_p || _M_offset != __x._M_offset;
}
bool operator<(const_iterator __x) const {
return _M_p < __x._M_p || (_M_p == __x._M_p && _M_offset < __x._M_offset);
}
bool operator>(const const_iterator& __x) const { return __x < *this; }
bool operator<=(const const_iterator& __x) const { return !(__x < *this); }
bool operator>=(const const_iterator& __x) const { return !(*this < __x); }
}; };
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 // Bit-vector base class, which encapsulates the difference between
// old SGI-style allocators and standard-conforming allocators. // old SGI-style allocators and standard-conforming allocators.
#ifdef __STL_USE_STD_ALLOCATORS #ifdef __STL_USE_STD_ALLOCATORS
...@@ -359,29 +354,26 @@ protected: ...@@ -359,29 +354,26 @@ protected:
// the default allocator. // the default allocator.
#if defined(__STL_CLASS_PARTIAL_SPECIALIZATION) && !defined(__STL_NO_BOOL) #if defined(__STL_CLASS_PARTIAL_SPECIALIZATION) && !defined(__STL_NO_BOOL)
#define __SGI_STL_VECBOOL_TEMPLATE # define __SGI_STL_VECBOOL_TEMPLATE
#define __BVECTOR vector # define __BVECTOR vector<bool, _Alloc>
#else # define __VECTOR vector
#undef __SGI_STL_VECBOOL_TEMPLATE # define __BVECTOR_BASE _Bvector_base<_Alloc>
#define __BVECTOR bit_vector # define __BVECTOR_TMPL_LIST template <class _Alloc>
#endif __STL_END_NAMESPACE
# include <bits/stl_vector.h>
# ifdef __SGI_STL_VECBOOL_TEMPLATE __STL_BEGIN_NAMESPACE
__STL_END_NAMESPACE #else /* __STL_CLASS_PARTIAL_SPECIALIZATION && !__STL_NO_BOOL */
# include <bits/stl_vector.h> # undef __SGI_STL_VECBOOL_TEMPLATE
__STL_BEGIN_NAMESPACE # define __BVECTOR bit_vector
template<class _Alloc> class vector<bool,_Alloc> # define __VECTOR bit_vector
: public _Bvector_base<_Alloc> # define __BVECTOR_BASE _Bvector_base<__STL_DEFAULT_ALLOCATOR(bool) >
# else /* __SGI_STL_VECBOOL_TEMPLATE */ # define __BVECTOR_TMPL_LIST
class bit_vector #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION && !__STL_NO_BOOL */
: public _Bvector_base<allocator<bool> >
# endif /* __SGI_STL_VECBOOL_TEMPLATE */
__BVECTOR_TMPL_LIST
class __BVECTOR : public __BVECTOR_BASE
{ {
# ifdef __SGI_STL_VECBOOL_TEMPLATE
typedef _Bvector_base<_Alloc> _Base;
# else /* __SGI_STL_VECBOOL_TEMPLATE */
typedef _Bvector_base<allocator<bool> > _Base;
# endif /* __SGI_STL_VECBOOL_TEMPLATE */
public: public:
typedef bool value_type; typedef bool value_type;
typedef size_t size_type; typedef size_t size_type;
...@@ -404,16 +396,18 @@ public: ...@@ -404,16 +396,18 @@ public:
reverse_iterator; reverse_iterator;
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */ #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
typedef typename _Base::allocator_type allocator_type; typedef typename __BVECTOR_BASE::allocator_type allocator_type;
allocator_type get_allocator() const { return _Base::get_allocator(); } allocator_type get_allocator() const {
return __BVECTOR_BASE::get_allocator();
}
protected: protected:
#ifdef __STL_USE_NAMESPACES #ifdef __STL_USE_NAMESPACES
using _Base::_M_bit_alloc; using __BVECTOR_BASE::_M_bit_alloc;
using _Base::_M_deallocate; using __BVECTOR_BASE::_M_deallocate;
using _Base::_M_start; using __BVECTOR_BASE::_M_start;
using _Base::_M_finish; using __BVECTOR_BASE::_M_finish;
using _Base::_M_end_of_storage; using __BVECTOR_BASE::_M_end_of_storage;
#endif /* __STL_USE_NAMESPACES */ #endif /* __STL_USE_NAMESPACES */
protected: protected:
...@@ -537,75 +531,80 @@ public: ...@@ -537,75 +531,80 @@ public:
{ _M_range_check(__n); return (*this)[__n]; } { _M_range_check(__n); return (*this)[__n]; }
#endif /* __STL_THROW_RANGE_ERRORS */ #endif /* __STL_THROW_RANGE_ERRORS */
explicit __BVECTOR(const allocator_type& __a = allocator_type()) explicit __VECTOR(const allocator_type& __a = allocator_type())
: _Base(__a) {} : __BVECTOR_BASE(__a) {}
__BVECTOR(size_type __n, bool __value, __VECTOR(size_type __n, bool __value,
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _Base(__a) : __BVECTOR_BASE(__a)
{ {
_M_initialize(__n); _M_initialize(__n);
fill(_M_start._M_p, _M_end_of_storage, __value ? ~0 : 0); fill(_M_start._M_p, _M_end_of_storage, __value ? ~0 : 0);
} }
explicit __BVECTOR(size_type __n) explicit __VECTOR(size_type __n)
: _Base(allocator_type()) : __BVECTOR_BASE(allocator_type())
{ {
_M_initialize(__n); _M_initialize(__n);
fill(_M_start._M_p, _M_end_of_storage, 0); fill(_M_start._M_p, _M_end_of_storage, 0);
} }
__BVECTOR(const __BVECTOR& __x) : _Base(__x.get_allocator()) { __VECTOR(const __VECTOR& __x) : __BVECTOR_BASE(__x.get_allocator()) {
_M_initialize(__x.size()); _M_initialize(__x.size());
copy(__x.begin(), __x.end(), _M_start); copy(__x.begin(), __x.end(), _M_start);
} }
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
// Check whether it's an integral type. If so, it's not an iterator. // Check whether it's an integral type. If so, it's not an iterator.
template <class _InputIterator>
__BVECTOR(_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> template <class _Integer>
void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) { void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) {
_M_initialize(__n); _M_initialize(__n);
fill(_M_start._M_p, _M_end_of_storage, __x ? ~0 : 0); fill(_M_start._M_p, _M_end_of_storage, __x ? ~0 : 0);
} }
template <class _InputIterator> template <class _InputIterator>
void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
__false_type) { __false_type) {
_M_initialize_range(__first, __last, __ITERATOR_CATEGORY(__first)); _M_initialize_range(__first, __last, __ITERATOR_CATEGORY(__first));
} }
template <class _InputIterator>
__VECTOR(_InputIterator __first, _InputIterator __last,
const allocator_type& __a = allocator_type())
: __BVECTOR_BASE(__a)
{
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_initialize_dispatch(__first, __last, _Integral());
}
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_MEMBER_TEMPLATES */
__BVECTOR(const_iterator __first, const_iterator __last,
const allocator_type& __a = allocator_type()) __VECTOR(const_iterator __first, const_iterator __last,
: _Base(__a) const allocator_type& __a = allocator_type())
: __BVECTOR_BASE(__a)
{ {
size_type __n = 0; size_type __n = 0;
distance(__first, __last, __n); distance(__first, __last, __n);
_M_initialize(__n); _M_initialize(__n);
copy(__first, __last, _M_start); copy(__first, __last, _M_start);
} }
__BVECTOR(const bool* __first, const bool* __last, __VECTOR(const bool* __first, const bool* __last,
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _Base(__a) : __BVECTOR_BASE(__a)
{ {
size_type __n = 0; size_type __n = 0;
distance(__first, __last, __n); distance(__first, __last, __n);
_M_initialize(__n); _M_initialize(__n);
copy(__first, __last, _M_start); copy(__first, __last, _M_start);
} }
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
~__BVECTOR() { } ~__VECTOR() { }
__BVECTOR& operator=(const __BVECTOR& __x) { __VECTOR& operator=(const __VECTOR& __x) {
if (&__x == this) return *this; if (&__x == this) return *this;
if (__x.size() > capacity()) { if (__x.size() > capacity()) {
_M_deallocate(); _M_deallocate();
...@@ -715,12 +714,6 @@ public: ...@@ -715,12 +714,6 @@ public:
#ifdef __STL_MEMBER_TEMPLATES #ifdef __STL_MEMBER_TEMPLATES
// Check whether it's an integral type. If so, it's not an iterator. // Check whether it's an integral type. If so, it's not an iterator.
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());
}
template <class _Integer> template <class _Integer>
void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x, void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
...@@ -734,6 +727,14 @@ public: ...@@ -734,6 +727,14 @@ public:
__false_type) { __false_type) {
_M_insert_range(__pos, __first, __last, __ITERATOR_CATEGORY(__first)); _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());
}
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_MEMBER_TEMPLATES */
void insert(iterator __position, void insert(iterator __position,
const_iterator __first, const_iterator __last) { const_iterator __first, const_iterator __last) {
...@@ -877,6 +878,9 @@ inline bool operator>=(const bit_vector& __x, const bit_vector& __y) ...@@ -877,6 +878,9 @@ inline bool operator>=(const bit_vector& __x, const bit_vector& __y)
#undef __SGI_STL_VECBOOL_TEMPLATE #undef __SGI_STL_VECBOOL_TEMPLATE
#undef __BVECTOR #undef __BVECTOR
#undef __VECTOR
#undef __BVECTOR_BASE
#undef __BVECTOR_TMPL_LIST
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174 #pragma reset woff 1174
......
...@@ -208,7 +208,7 @@ class _Rope_char_consumer { ...@@ -208,7 +208,7 @@ class _Rope_char_consumer {
// First a lot of forward declarations. The standard seems to require // First a lot of forward declarations. The standard seems to require
// much stricter "declaration before use" than many of the implementations // much stricter "declaration before use" than many of the implementations
// that preceded it. // that preceded it.
template<class _CharT, class _Alloc=allocator<_CharT> > class rope; template<class _CharT, class _Alloc=__STL_DEFAULT_ALLOCATOR(_CharT)> class rope;
template<class _CharT, class _Alloc> struct _Rope_RopeConcatenation; template<class _CharT, class _Alloc> struct _Rope_RopeConcatenation;
template<class _CharT, class _Alloc> struct _Rope_RopeLeaf; template<class _CharT, class _Alloc> struct _Rope_RopeLeaf;
template<class _CharT, class _Alloc> struct _Rope_RopeFunction; template<class _CharT, class _Alloc> struct _Rope_RopeFunction;
...@@ -304,7 +304,7 @@ struct _Rope_Concat_fn ...@@ -304,7 +304,7 @@ struct _Rope_Concat_fn
: public binary_function<rope<_CharT,_Alloc>, rope<_CharT,_Alloc>, : public binary_function<rope<_CharT,_Alloc>, rope<_CharT,_Alloc>,
rope<_CharT,_Alloc> > { rope<_CharT,_Alloc> > {
rope<_CharT,_Alloc> operator() (const rope<_CharT,_Alloc>& __x, rope<_CharT,_Alloc> operator() (const rope<_CharT,_Alloc>& __x,
const rope<_CharT,_Alloc>& __y) { const rope<_CharT,_Alloc>& __y) {
return __x + __y; return __x + __y;
} }
}; };
...@@ -492,14 +492,14 @@ struct _Rope_RopeRep : public _Rope_rep_base<_CharT,_Alloc> ...@@ -492,14 +492,14 @@ struct _Rope_RopeRep : public _Rope_rep_base<_CharT,_Alloc>
/* In the case of a leaf, this may point to */ /* In the case of a leaf, this may point to */
/* the same memory as the data field. */ /* the same memory as the data field. */
typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type
allocator_type; allocator_type;
_Rope_RopeRep(_Tag __t, int __d, bool __b, size_t __size, _Rope_RopeRep(_Tag __t, int __d, bool __b, size_t __size,
allocator_type __a) allocator_type __a)
: _Rope_rep_base<_CharT,_Alloc>(__size, __a) : _Rope_rep_base<_CharT,_Alloc>(__size, __a),
# ifndef __GC # ifndef __GC
, _Refcount_Base(1), _Refcount_Base(1),
# endif # endif
_M_tag(__t), _M_depth(__d), _M_is_balanced(__b), _M_c_string(0) _M_tag(__t), _M_is_balanced(__b), _M_depth(__d), _M_c_string(0)
{ } { }
# ifdef __GC # ifdef __GC
void _M_incr () {} void _M_incr () {}
...@@ -584,10 +584,10 @@ struct _Rope_RopeLeaf : public _Rope_RopeRep<_CharT,_Alloc> { ...@@ -584,10 +584,10 @@ struct _Rope_RopeLeaf : public _Rope_RopeRep<_CharT,_Alloc> {
/* in the GC case, in which it */ /* in the GC case, in which it */
/* doesn't matter. */ /* doesn't matter. */
typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type
allocator_type; allocator_type;
_Rope_RopeLeaf(__GC_CONST _CharT* __d, size_t __size, allocator_type __a) _Rope_RopeLeaf(__GC_CONST _CharT* __d, size_t __size, allocator_type __a)
: _Rope_RopeRep<_CharT,_Alloc>(_S_leaf, 0, true, __size, __a), : _Rope_RopeRep<_CharT,_Alloc>(_S_leaf, 0, true, __size, __a),
_M_data(__d) _M_data(__d)
{ {
__stl_assert(__size > 0); __stl_assert(__size > 0);
if (_S_is_basic_char_type((_CharT *)0)) { if (_S_is_basic_char_type((_CharT *)0)) {
...@@ -614,14 +614,16 @@ struct _Rope_RopeConcatenation : public _Rope_RopeRep<_CharT,_Alloc> { ...@@ -614,14 +614,16 @@ struct _Rope_RopeConcatenation : public _Rope_RopeRep<_CharT,_Alloc> {
_Rope_RopeRep<_CharT,_Alloc>* _M_left; _Rope_RopeRep<_CharT,_Alloc>* _M_left;
_Rope_RopeRep<_CharT,_Alloc>* _M_right; _Rope_RopeRep<_CharT,_Alloc>* _M_right;
typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type
allocator_type; allocator_type;
_Rope_RopeConcatenation(_Rope_RopeRep<_CharT,_Alloc>* __l, _Rope_RopeConcatenation(_Rope_RopeRep<_CharT,_Alloc>* __l,
_Rope_RopeRep<_CharT,_Alloc>* __r, _Rope_RopeRep<_CharT,_Alloc>* __r,
allocator_type __a) allocator_type __a)
: _Rope_RopeRep<_CharT,_Alloc>(
_S_concat, max(__l->_M_depth, __r->_M_depth) + 1, false, : _Rope_RopeRep<_CharT,_Alloc>(_S_concat,
__l->_M_size + __r->_M_size, __a), max(__l->_M_depth, __r->_M_depth) + 1,
_M_left(__l), _M_right(__r) false,
__l->_M_size + __r->_M_size, __a),
_M_left(__l), _M_right(__r)
{} {}
# ifndef __GC # ifndef __GC
~_Rope_RopeConcatenation() { ~_Rope_RopeConcatenation() {
...@@ -652,15 +654,15 @@ struct _Rope_RopeFunction : public _Rope_RopeRep<_CharT,_Alloc> { ...@@ -652,15 +654,15 @@ struct _Rope_RopeFunction : public _Rope_RopeRep<_CharT,_Alloc> {
} }
# endif # endif
typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type
allocator_type; allocator_type;
_Rope_RopeFunction(char_producer<_CharT>* __f, size_t __size, _Rope_RopeFunction(char_producer<_CharT>* __f, size_t __size,
bool __d, allocator_type __a) bool __d, allocator_type __a)
:_Rope_RopeRep<_CharT,_Alloc>(_S_function, 0, true, __size, __a), : _Rope_RopeRep<_CharT,_Alloc>(_S_function, 0, true, __size, __a)
_M_fn(__f) , _M_fn(__f)
# ifndef __GC # ifndef __GC
, _M_delete_when_done(__d) , _M_delete_when_done(__d)
# endif # endif
{ {
__stl_assert(__size > 0); __stl_assert(__size > 0);
# ifdef __GC # ifdef __GC
if (__d) { if (__d) {
...@@ -718,11 +720,13 @@ struct _Rope_RopeSubstring : public _Rope_RopeFunction<_CharT,_Alloc>, ...@@ -718,11 +720,13 @@ struct _Rope_RopeSubstring : public _Rope_RopeFunction<_CharT,_Alloc>,
} }
} }
typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type
allocator_type; allocator_type;
_Rope_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_t __s, _Rope_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_t __s,
size_t __l, allocator_type __a) size_t __l, allocator_type __a)
: _Rope_RopeFunction<_CharT,_Alloc>(this, __l, false, __a), _M_base(__b) : _Rope_RopeFunction<_CharT,_Alloc>(this, __l, false, __a),
, _M_start(__s) char_producer<_CharT>(),
_M_base(__b),
_M_start(__s)
{ {
__stl_assert(__l > 0); __stl_assert(__l > 0);
__stl_assert(__s + __l <= __b->_M_size); __stl_assert(__s + __l <= __b->_M_size);
...@@ -792,17 +796,16 @@ class _Rope_char_ref_proxy { ...@@ -792,17 +796,16 @@ class _Rope_char_ref_proxy {
bool _M_current_valid; bool _M_current_valid;
_My_rope* _M_root; // The whole rope. _My_rope* _M_root; // The whole rope.
public: public:
_Rope_char_ref_proxy(_My_rope* __r, size_t __p) : _Rope_char_ref_proxy(_My_rope* __r, size_t __p)
_M_pos(__p), _M_current_valid(false), _M_root(__r) {} : _M_pos(__p), _M_current_valid(false), _M_root(__r) {}
_Rope_char_ref_proxy(const _Rope_char_ref_proxy& __x) : _Rope_char_ref_proxy(const _Rope_char_ref_proxy& __x)
_M_pos(__x._M_pos), _M_current_valid(false), _M_root(__x._M_root) {} : _M_pos(__x._M_pos), _M_current_valid(false), _M_root(__x._M_root) {}
// Don't preserve cache if the reference can outlive the // Don't preserve cache if the reference can outlive the
// expression. We claim that's not possible without calling // expression. We claim that's not possible without calling
// a copy constructor or generating reference to a proxy // a copy constructor or generating reference to a proxy
// reference. We declare the latter to have undefined semantics. // reference. We declare the latter to have undefined semantics.
_Rope_char_ref_proxy(_My_rope* __r, size_t __p, _Rope_char_ref_proxy(_My_rope* __r, size_t __p, _CharT __c)
_CharT __c) : : _M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) {}
_M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) {}
inline operator _CharT () const; inline operator _CharT () const;
_Rope_char_ref_proxy& operator= (_CharT __c); _Rope_char_ref_proxy& operator= (_CharT __c);
_Rope_char_ptr_proxy<_CharT,_Alloc> operator& () const; _Rope_char_ptr_proxy<_CharT,_Alloc> operator& () const;
...@@ -834,7 +837,7 @@ class _Rope_char_ref_proxy { ...@@ -834,7 +837,7 @@ class _Rope_char_ref_proxy {
__b = __tmp; \ __b = __tmp; \
} }
_ROPE_SWAP_SPECIALIZATION(char,allocator<char>) _ROPE_SWAP_SPECIALIZATION(char,__STL_DEFAULT_ALLOCATOR(char))
#endif /* !__STL_FUNCTION_TMPL_PARTIAL_ORDER */ #endif /* !__STL_FUNCTION_TMPL_PARTIAL_ORDER */
...@@ -892,6 +895,7 @@ class _Rope_iterator_base ...@@ -892,6 +895,7 @@ class _Rope_iterator_base
: public random_access_iterator<_CharT, ptrdiff_t> { : public random_access_iterator<_CharT, ptrdiff_t> {
friend class rope<_CharT,_Alloc>; friend class rope<_CharT,_Alloc>;
public: public:
typedef _Alloc _allocator_type; // used in _Rope_rotate, VC++ workaround
typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep; typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
// Borland doesnt want this to be protected. // Borland doesnt want this to be protected.
protected: protected:
...@@ -940,7 +944,7 @@ class _Rope_iterator_base ...@@ -940,7 +944,7 @@ class _Rope_iterator_base
// cache is valid for previous posn. // cache is valid for previous posn.
_Rope_iterator_base() {} _Rope_iterator_base() {}
_Rope_iterator_base(_RopeRep* __root, size_t __pos) _Rope_iterator_base(_RopeRep* __root, size_t __pos)
: _M_root(__root), _M_current_pos(__pos), _M_buf_ptr(0) {} : _M_current_pos(__pos), _M_root(__root), _M_buf_ptr(0) {}
void _M_incr(size_t __n); void _M_incr(size_t __n);
void _M_decr(size_t __n); void _M_decr(size_t __n);
public: public:
...@@ -1111,7 +1115,7 @@ class _Rope_iterator : public _Rope_iterator_base<_CharT,_Alloc> { ...@@ -1111,7 +1115,7 @@ class _Rope_iterator : public _Rope_iterator_base<_CharT,_Alloc> {
_Rope_iterator(rope<_CharT,_Alloc>* __r, size_t __pos) _Rope_iterator(rope<_CharT,_Alloc>* __r, size_t __pos)
: _Rope_iterator_base<_CharT,_Alloc>(__r->_M_tree_ptr, __pos), : _Rope_iterator_base<_CharT,_Alloc>(__r->_M_tree_ptr, __pos),
_M_root_rope(__r) _M_root_rope(__r)
{ _RopeRep::_S_ref(_M_root); } { _RopeRep::_S_ref(_M_root); if (!(__r -> empty()))_S_setcache(*this); }
void _M_check(); void _M_check();
public: public:
...@@ -1323,7 +1327,7 @@ struct _Rope_base ...@@ -1323,7 +1327,7 @@ struct _Rope_base
_Base; _Base;
typedef typename _Base::allocator_type allocator_type; typedef typename _Base::allocator_type allocator_type;
typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep; typedef _Rope_RopeRep<_CharT,_Alloc> _RopeRep;
// The one in _Base may not be visible due to template rules. // The one in _Base may not be visible due to template rules.
_Rope_base(_RopeRep* __t, const allocator_type& __a) : _Base(__t, __a) {} _Rope_base(_RopeRep* __t, const allocator_type& __a) : _Base(__t, __a) {}
_Rope_base(const allocator_type& __a) : _Base(__a) {} _Rope_base(const allocator_type& __a) : _Base(__a) {}
}; };
...@@ -1586,7 +1590,7 @@ class rope : public _Rope_base<_CharT,_Alloc> { ...@@ -1586,7 +1590,7 @@ class rope : public _Rope_base<_CharT,_Alloc> {
// A version that potentially clobbers __r if __r->_M_ref_count == 1. // A version that potentially clobbers __r if __r->_M_ref_count == 1.
# endif # endif
private: private:
static size_t _S_char_ptr_len(const _CharT* __s); static size_t _S_char_ptr_len(const _CharT* __s);
// slightly generalized strlen // slightly generalized strlen
...@@ -1740,10 +1744,10 @@ class rope : public _Rope_base<_CharT,_Alloc> { ...@@ -1740,10 +1744,10 @@ class rope : public _Rope_base<_CharT,_Alloc> {
} }
void clear() void clear()
{ {
_S_unref(_M_tree_ptr); _S_unref(_M_tree_ptr);
_M_tree_ptr = 0; _M_tree_ptr = 0;
} }
void push_back(_CharT __x) void push_back(_CharT __x)
{ {
...@@ -2060,9 +2064,9 @@ class rope : public _Rope_base<_CharT,_Alloc> { ...@@ -2060,9 +2064,9 @@ class rope : public _Rope_base<_CharT,_Alloc> {
_Self_destruct_ptr __right(_S_substring(_M_tree_ptr, __p, size())); _Self_destruct_ptr __right(_S_substring(_M_tree_ptr, __p, size()));
_Self_destruct_ptr __left_result( _Self_destruct_ptr __left_result(
_S_concat_char_iter(__left, __i, __n)); _S_concat_char_iter(__left, __i, __n));
// _S_ destr_concat_char_iter should be safe here. // _S_ destr_concat_char_iter should be safe here.
// But as it stands it's probably not a win, since __left // But as it stands it's probably not a win, since __left
// is likely to have additional references. // is likely to have additional references.
_RopeRep* __result = _S_concat(__left_result, __right); _RopeRep* __result = _S_concat(__left_result, __right);
_S_unref(_M_tree_ptr); _S_unref(_M_tree_ptr);
_M_tree_ptr = __result; _M_tree_ptr = __result;
...@@ -2378,7 +2382,7 @@ class rope : public _Rope_base<_CharT,_Alloc> { ...@@ -2378,7 +2382,7 @@ class rope : public _Rope_base<_CharT,_Alloc> {
template <class _CharT, class _Alloc> template <class _CharT, class _Alloc>
const rope<_CharT, _Alloc>::size_type rope<_CharT, _Alloc>::npos = const rope<_CharT, _Alloc>::size_type rope<_CharT, _Alloc>::npos =
(size_type)(-1); (size_type)(-1);
template <class _CharT, class _Alloc> template <class _CharT, class _Alloc>
inline bool operator== (const _Rope_const_iterator<_CharT,_Alloc>& __x, inline bool operator== (const _Rope_const_iterator<_CharT,_Alloc>& __x,
...@@ -2637,8 +2641,8 @@ inline bool operator!= (const _Rope_char_ptr_proxy<_CharT,_Alloc>& __x, ...@@ -2637,8 +2641,8 @@ inline bool operator!= (const _Rope_char_ptr_proxy<_CharT,_Alloc>& __x,
#ifdef __STL_USE_NEW_IOSTREAMS #ifdef __STL_USE_NEW_IOSTREAMS
template<class _CharT, class _Traits, class _Alloc> template<class _CharT, class _Traits, class _Alloc>
basic_ostream<_CharT, _Traits>& operator<< basic_ostream<_CharT, _Traits>& operator<<
(basic_ostream<_CharT, _Traits>& __o, (basic_ostream<_CharT, _Traits>& __o,
const rope<_CharT, _Alloc>& __r); const rope<_CharT, _Alloc>& __r);
#else #else
template<class _CharT, class _Alloc> template<class _CharT, class _Alloc>
ostream& operator<< (ostream& __o, const rope<_CharT, _Alloc>& __r); ostream& operator<< (ostream& __o, const rope<_CharT, _Alloc>& __r);
......
...@@ -140,7 +140,8 @@ headers = \ ...@@ -140,7 +140,8 @@ headers = \
bits/stl_stack.h bits/stl_string_fwd.h bits/stl_tempbuf.h \ bits/stl_stack.h bits/stl_string_fwd.h bits/stl_tempbuf.h \
bits/stl_tree.h bits/stl_uninitialized.h bits/stl_vector.h \ bits/stl_tree.h bits/stl_uninitialized.h bits/stl_vector.h \
bits/type_traits.h bits/stl_range_errors.h bits/std_algorithm.h \ bits/type_traits.h bits/stl_range_errors.h bits/std_algorithm.h \
bits/std_strstream.h \ bits/concept_checks.h bits/container_concepts.h \
bits/sequence_concepts.h bits/std_strstream.h \
ext/ropeimpl.h ext/stl_rope.h \ ext/ropeimpl.h ext/stl_rope.h \
ext/stl_bvector.h bits/stl_config.h bits/stl_construct.h \ ext/stl_bvector.h bits/stl_config.h bits/stl_construct.h \
ext/stl_hashtable.h ext/stl_hash_fun.h \ ext/stl_hashtable.h ext/stl_hash_fun.h \
......
...@@ -220,7 +220,8 @@ headers = \ ...@@ -220,7 +220,8 @@ headers = \
bits/stl_stack.h bits/stl_string_fwd.h bits/stl_tempbuf.h \ bits/stl_stack.h bits/stl_string_fwd.h bits/stl_tempbuf.h \
bits/stl_tree.h bits/stl_uninitialized.h bits/stl_vector.h \ bits/stl_tree.h bits/stl_uninitialized.h bits/stl_vector.h \
bits/type_traits.h bits/stl_range_errors.h bits/std_algorithm.h \ bits/type_traits.h bits/stl_range_errors.h bits/std_algorithm.h \
bits/std_strstream.h \ bits/concept_checks.h bits/container_concepts.h \
bits/sequence_concepts.h bits/std_strstream.h \
ext/ropeimpl.h ext/stl_rope.h \ ext/ropeimpl.h ext/stl_rope.h \
ext/stl_bvector.h bits/stl_config.h bits/stl_construct.h \ ext/stl_bvector.h bits/stl_config.h bits/stl_construct.h \
ext/stl_hashtable.h ext/stl_hash_fun.h \ ext/stl_hashtable.h ext/stl_hash_fun.h \
......
...@@ -49,4 +49,8 @@ namespace std { ...@@ -49,4 +49,8 @@ namespace std {
vector<unsigned int>:: vector<unsigned int>::
_M_insert_aux(vector<unsigned int>::iterator, unsigned int const &); _M_insert_aux(vector<unsigned int>::iterator, unsigned int const &);
template
void
__sink_unused_warning<size_t>(size_t);
} //std } //std
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment