algo.h, [...]: Update To September 8 SGI release.

* algo.h, algobase.h, alloc.h, bvector.h, deque.h, hashtable.h,
	iterator.h, list.h, rope.h, ropeimpl.h, slist.h, stl_config.h,
	tree.h, vector.h: Update To September 8 SGI release.

From-SVN: r15211
This commit is contained in:
Jason Merrill 1997-09-10 02:49:45 +00:00 committed by Jason Merrill
parent c6b50f1082
commit ff893307d0
15 changed files with 778 additions and 463 deletions

View File

@ -1,3 +1,9 @@
Tue Sep 9 19:47:28 1997 Jason Merrill <jason@yorick.cygnus.com>
* algo.h, algobase.h, alloc.h, bvector.h, deque.h, hashtable.h,
iterator.h, list.h, rope.h, ropeimpl.h, slist.h, stl_config.h,
tree.h, vector.h: Update To September 8 SGI release.
Tue Sep 9 17:38:47 1997 Mark Mitchell <mmitchell@usa.net> Tue Sep 9 17:38:47 1997 Mark Mitchell <mmitchell@usa.net>
* stl_config.h (__STL_MEMBER_TEMPLATES): Enable. * stl_config.h (__STL_MEMBER_TEMPLATES): Enable.

View File

@ -236,6 +236,63 @@ inline ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1,
distance_type(first1), distance_type(first2)); distance_type(first1), distance_type(first2));
} }
template <class ForwardIterator, class Integer, class T>
ForwardIterator search_n(ForwardIterator first, ForwardIterator last,
Integer count, const T& value) {
if (count <= 0)
return first;
else {
first = find(first, last, value);
while (first != last) {
Integer n = count - 1;
ForwardIterator i = first;
++i;
while (i != last && n != 0 && *i == value) {
++i;
--n;
}
if (n == 0)
return first;
else
first = find(i, last, value);
}
return last;
}
}
template <class ForwardIterator, class Integer, class T, class BinaryPredicate>
ForwardIterator search_n(ForwardIterator first, ForwardIterator last,
Integer count, const T& value,
BinaryPredicate binary_pred) {
if (count <= 0)
return first;
else {
while (first != last) {
if (binary_pred(*first, value)) break;
++first;
}
while (first != last) {
Integer n = count - 1;
ForwardIterator i = first;
++i;
while (i != last && n != 0 && binary_pred(*i, value)) {
++i;
--n;
}
if (n == 0)
return first;
else {
while (i != last) {
if (binary_pred(*i, value)) break;
++i;
}
first = i;
}
}
return last;
}
}
template <class ForwardIterator1, class ForwardIterator2> template <class ForwardIterator1, class ForwardIterator2>
ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2) { ForwardIterator2 first2) {
@ -1400,15 +1457,6 @@ ForwardIterator __lower_bound(ForwardIterator first, ForwardIterator last,
return first; return first;
} }
template <class ForwardIterator, class T, class Distance>
inline ForwardIterator __lower_bound(ForwardIterator first,
ForwardIterator last,
const T& value, Distance*,
bidirectional_iterator_tag) {
return __lower_bound(first, last, value, (Distance*)0,
forward_iterator_tag());
}
template <class RandomAccessIterator, class T, class Distance> template <class RandomAccessIterator, class T, class Distance>
RandomAccessIterator __lower_bound(RandomAccessIterator first, RandomAccessIterator __lower_bound(RandomAccessIterator first,
RandomAccessIterator last, const T& value, RandomAccessIterator last, const T& value,
@ -1459,15 +1507,6 @@ ForwardIterator __lower_bound(ForwardIterator first, ForwardIterator last,
return first; return first;
} }
template <class ForwardIterator, class T, class Compare, class Distance>
inline ForwardIterator __lower_bound(ForwardIterator first,
ForwardIterator last,
const T& value, Compare comp, Distance*,
bidirectional_iterator_tag) {
return __lower_bound(first, last, value, comp, (Distance*)0,
forward_iterator_tag());
}
template <class RandomAccessIterator, class T, class Compare, class Distance> template <class RandomAccessIterator, class T, class Compare, class Distance>
RandomAccessIterator __lower_bound(RandomAccessIterator first, RandomAccessIterator __lower_bound(RandomAccessIterator first,
RandomAccessIterator last, RandomAccessIterator last,
@ -1520,15 +1559,6 @@ ForwardIterator __upper_bound(ForwardIterator first, ForwardIterator last,
return first; return first;
} }
template <class ForwardIterator, class T, class Distance>
inline ForwardIterator __upper_bound(ForwardIterator first,
ForwardIterator last,
const T& value, Distance*,
bidirectional_iterator_tag) {
return __upper_bound(first, last, value, (Distance*)0,
forward_iterator_tag());
}
template <class RandomAccessIterator, class T, class Distance> template <class RandomAccessIterator, class T, class Distance>
RandomAccessIterator __upper_bound(RandomAccessIterator first, RandomAccessIterator __upper_bound(RandomAccessIterator first,
RandomAccessIterator last, const T& value, RandomAccessIterator last, const T& value,
@ -1581,15 +1611,6 @@ ForwardIterator __upper_bound(ForwardIterator first, ForwardIterator last,
return first; return first;
} }
template <class ForwardIterator, class T, class Compare, class Distance>
inline ForwardIterator __upper_bound(ForwardIterator first,
ForwardIterator last,
const T& value, Compare comp, Distance*,
bidirectional_iterator_tag) {
return __upper_bound(first, last, value, comp, (Distance*)0,
forward_iterator_tag());
}
template <class RandomAccessIterator, class T, class Compare, class Distance> template <class RandomAccessIterator, class T, class Compare, class Distance>
RandomAccessIterator __upper_bound(RandomAccessIterator first, RandomAccessIterator __upper_bound(RandomAccessIterator first,
RandomAccessIterator last, RandomAccessIterator last,
@ -1648,14 +1669,6 @@ __equal_range(ForwardIterator first, ForwardIterator last, const T& value,
return pair<ForwardIterator, ForwardIterator>(first, first); return pair<ForwardIterator, ForwardIterator>(first, first);
} }
template <class ForwardIterator, class T, class Distance>
inline pair<ForwardIterator, ForwardIterator>
__equal_range(ForwardIterator first, ForwardIterator last, const T& value,
Distance*, bidirectional_iterator_tag) {
return __equal_range(first, last, value, (Distance*)0,
forward_iterator_tag());
}
template <class RandomAccessIterator, class T, class Distance> template <class RandomAccessIterator, class T, class Distance>
pair<RandomAccessIterator, RandomAccessIterator> pair<RandomAccessIterator, RandomAccessIterator>
__equal_range(RandomAccessIterator first, RandomAccessIterator last, __equal_range(RandomAccessIterator first, RandomAccessIterator last,
@ -1718,14 +1731,6 @@ __equal_range(ForwardIterator first, ForwardIterator last, const T& value,
return pair<ForwardIterator, ForwardIterator>(first, first); return pair<ForwardIterator, ForwardIterator>(first, first);
} }
template <class ForwardIterator, class T, class Compare, class Distance>
inline pair<ForwardIterator, ForwardIterator>
__equal_range(ForwardIterator first, ForwardIterator last, const T& value,
Compare comp, Distance*, bidirectional_iterator_tag) {
return __equal_range(first, last, value, comp, (Distance*)0,
forward_iterator_tag());
}
template <class RandomAccessIterator, class T, class Compare, class Distance> template <class RandomAccessIterator, class T, class Compare, class Distance>
pair<RandomAccessIterator, RandomAccessIterator> pair<RandomAccessIterator, RandomAccessIterator>
__equal_range(RandomAccessIterator first, RandomAccessIterator last, __equal_range(RandomAccessIterator first, RandomAccessIterator last,
@ -2543,6 +2548,213 @@ OutputIterator adjacent_difference(InputIterator first, InputIterator last,
binary_op); binary_op);
} }
template <class InputIterator, class ForwardIterator>
InputIterator find_first_of(InputIterator first1, InputIterator last1,
ForwardIterator first2, ForwardIterator last2)
{
for ( ; first1 != last1; ++first1)
for (ForwardIterator iter = first2; iter != last2; ++iter)
if (*first1 == *iter)
return first1;
return last1;
}
template <class InputIterator, class ForwardIterator, class BinaryPredicate>
InputIterator find_first_of(InputIterator first1, InputIterator last1,
ForwardIterator first2, ForwardIterator last2,
BinaryPredicate comp)
{
for ( ; first1 != last1; ++first1)
for (ForwardIterator iter = first2; iter != last2; ++iter)
if (comp(*first1, *iter))
return first1;
return last1;
}
// Search [first2, last2) as a subsequence in [first1, last1).
// find_end for forward iterators.
template <class ForwardIterator1, class ForwardIterator2>
ForwardIterator1 __find_end(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
forward_iterator_tag, forward_iterator_tag)
{
if (first2 == last2)
return last1;
else {
ForwardIterator1 result = last1;
while (1) {
ForwardIterator1 new_result = search(first1, last1, first2, last2);
if (new_result == last1)
return result;
else {
result = new_result;
first1 = new_result;
++first1;
}
}
}
}
template <class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
ForwardIterator1 __find_end(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
forward_iterator_tag, forward_iterator_tag,
BinaryPredicate comp)
{
if (first2 == last2)
return last1;
else {
ForwardIterator1 result = last1;
while (1) {
ForwardIterator1 new_result = search(first1, last1, first2, last2, comp);
if (new_result == last1)
return result;
else {
result = new_result;
first1 = new_result;
++first1;
}
}
}
}
// find_end for bidirectional iterators. Requires partial specialization.
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class BidirectionalIterator1, class BidirectionalIterator2>
BidirectionalIterator1
__find_end(BidirectionalIterator1 first1, BidirectionalIterator1 last1,
BidirectionalIterator2 first2, BidirectionalIterator2 last2,
bidirectional_iterator_tag, bidirectional_iterator_tag)
{
typedef reverse_iterator<BidirectionalIterator1> reviter1;
typedef reverse_iterator<BidirectionalIterator2> reviter2;
reviter1 rlast1(first1);
reviter2 rlast2(first2);
reviter1 rresult = search(reviter1(last1), rlast1, reviter2(last2), rlast2);
if (rresult == rlast1)
return last1;
else {
BidirectionalIterator1 result = rresult.base();
advance(result, -distance(first2, last2));
return result;
}
}
template <class BidirectionalIterator1, class BidirectionalIterator2,
class BinaryPredicate>
BidirectionalIterator1
__find_end(BidirectionalIterator1 first1, BidirectionalIterator1 last1,
BidirectionalIterator2 first2, BidirectionalIterator2 last2,
bidirectional_iterator_tag, bidirectional_iterator_tag,
BinaryPredicate comp)
{
typedef reverse_iterator<BidirectionalIterator1> reviter1;
typedef reverse_iterator<BidirectionalIterator2> reviter2;
reviter1 rlast1(first1);
reviter2 rlast2(first2);
reviter1 rresult = search(reviter1(last1), rlast1, reviter2(last2), rlast2,
comp);
if (rresult == rlast1)
return last1;
else {
BidirectionalIterator1 result = rresult.base();
advance(result, -distance(first2, last2));
return result;
}
}
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
// Dispatching functions.
template <class ForwardIterator, class BidirectionalIterator>
inline ForwardIterator
__find_end(ForwardIterator first1, ForwardIterator last1,
BidirectionalIterator first2, BidirectionalIterator last2,
forward_iterator_tag, bidirectional_iterator_tag)
{
return __find_end(first1, last1, first2, last2,
forward_iterator_tag(), forward_iterator_tag());
}
template <class BidirectionalIterator, class ForwardIterator>
inline BidirectionalIterator
__find_end(BidirectionalIterator first1, BidirectionalIterator last1,
ForwardIterator first2, ForwardIterator last2,
bidirectional_iterator_tag, forward_iterator_tag)
{
return __find_end(first1, last1, first2, last2,
forward_iterator_tag(), forward_iterator_tag());
}
template <class ForwardIterator, class BidirectionalIterator,
class BinaryPredicate>
inline ForwardIterator
__find_end(ForwardIterator first1, ForwardIterator last1,
BidirectionalIterator first2, BidirectionalIterator last2,
forward_iterator_tag, bidirectional_iterator_tag,
BinaryPredicate comp)
{
return __find_end(first1, last1, first2, last2,
forward_iterator_tag(), forward_iterator_tag(),
comp);
}
template <class BidirectionalIterator, class ForwardIterator,
class BinaryPredicate>
inline BidirectionalIterator
__find_end(BidirectionalIterator first1, BidirectionalIterator last1,
ForwardIterator first2, ForwardIterator last2,
bidirectional_iterator_tag, forward_iterator_tag,
BinaryPredicate comp)
{
return __find_end(first1, last1, first2, last2,
forward_iterator_tag(), forward_iterator_tag(),
comp);
}
template <class ForwardIterator1, class ForwardIterator2>
inline ForwardIterator1
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2)
{
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
return __find_end(first1, last1, first2, last2,
iterator_traits<ForwardIterator1>::iterator_category(),
iterator_traits<ForwardIterator2>::iterator_category());
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
return __find_end(first1, last1, first2, last2,
forward_iterator_tag(), forward_iterator_tag());
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
}
template <class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
inline ForwardIterator1
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate comp)
{
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
return __find_end(first1, last1, first2, last2,
iterator_traits<ForwardIterator1>::iterator_category(),
iterator_traits<ForwardIterator2>::iterator_category(),
comp);
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
return __find_end(first1, last1, first2, last2,
forward_iterator_tag(), forward_iterator_tag(),
comp);
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
}
// Returns x ** n, where n >= 0. Note that "multiplication" // Returns x ** n, where n >= 0. Note that "multiplication"
// is required to be associative, but not necessarily commutative. // is required to be associative, but not necessarily commutative.
@ -2551,18 +2763,18 @@ T power(T x, Integer n, MonoidOperation op) {
if (n == 0) if (n == 0)
return identity_element(op); return identity_element(op);
else { else {
while (n % 2 == 0) { while ((n & 1) == 0) {
n /= 2; n >>= 1;
x = op(x, x); x = op(x, x);
} }
T result = x; T result = x;
n /= 2; n >>= 1;
while (n != 0) { while (n != 0) {
x = op(x, x); x = op(x, x);
if (n % 2 != 0) if ((n & 1) != 0)
result = op(result, x); result = op(result, x);
n /= 2; n >>= 1;
} }
return result; return result;
} }

View File

@ -86,19 +86,6 @@ inline void __distance(InputIterator first, InputIterator last, Distance& n,
while (first != last) { ++first; ++n; } while (first != last) { ++first; ++n; }
} }
template <class ForwardIterator, class Distance>
inline void __distance(ForwardIterator first, ForwardIterator last,
Distance& n,
forward_iterator_tag) {
while (first != last) { ++first; ++n; }
}
template <class BidirectionalIterator, class Distance>
inline void __distance(BidirectionalIterator first, BidirectionalIterator last,
Distance& n, bidirectional_iterator_tag) {
while (first != last) { ++first; ++n; }
}
template <class RandomAccessIterator, class Distance> template <class RandomAccessIterator, class Distance>
inline void __distance(RandomAccessIterator first, RandomAccessIterator last, inline void __distance(RandomAccessIterator first, RandomAccessIterator last,
Distance& n, random_access_iterator_tag) { Distance& n, random_access_iterator_tag) {
@ -122,19 +109,6 @@ __distance(InputIterator first, InputIterator last, input_iterator_tag) {
return n; return n;
} }
template <class ForwardIterator>
inline iterator_traits<ForwardIterator>::difference_type
__distance(ForwardIterator first, ForwardIterator last, forward_iterator_tag) {
return __distance(first, last, input_iterator_tag());
}
template <class BidirectionalIterator>
inline iterator_traits<BidirectionalIterator>::difference_type
__distance(BidirectionalIterator first, BidirectionalIterator last,
bidirectional_iterator_tag) {
return __distance(first, last, input_iterator_tag());
}
template <class RandomAccessIterator> template <class RandomAccessIterator>
inline iterator_traits<RandomAccessIterator>::difference_type inline iterator_traits<RandomAccessIterator>::difference_type
__distance(RandomAccessIterator first, RandomAccessIterator last, __distance(RandomAccessIterator first, RandomAccessIterator last,
@ -156,11 +130,6 @@ inline void __advance(InputIterator& i, Distance n, input_iterator_tag) {
while (n--) ++i; while (n--) ++i;
} }
template <class ForwardIterator, class Distance>
inline void __advance(ForwardIterator& i, Distance n, forward_iterator_tag) {
while (n--) ++i;
}
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32) #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma set woff 1183 #pragma set woff 1183
#endif #endif
@ -198,20 +167,6 @@ inline OutputIterator __copy(InputIterator first, InputIterator last,
return result; return result;
} }
template <class InputIterator, class OutputIterator>
inline OutputIterator __copy(InputIterator first, InputIterator last,
OutputIterator result, forward_iterator_tag)
{
return __copy(first, last, result, input_iterator_tag());
}
template <class InputIterator, class OutputIterator>
inline OutputIterator __copy(InputIterator first, InputIterator last,
OutputIterator result, bidirectional_iterator_tag)
{
return __copy(first, last, result, input_iterator_tag());
}
template <class RandomAccessIterator, class OutputIterator, class Distance> template <class RandomAccessIterator, class OutputIterator, class Distance>
inline OutputIterator inline OutputIterator
__copy_d(RandomAccessIterator first, RandomAccessIterator last, __copy_d(RandomAccessIterator first, RandomAccessIterator last,
@ -365,20 +320,6 @@ OutputIterator __copy_n(InputIterator first, Size count,
return result; return result;
} }
template <class ForwardIterator, class Size, class OutputIterator>
inline OutputIterator __copy_n(ForwardIterator first, Size count,
OutputIterator result,
forward_iterator_tag) {
return __copy_n(first, count, result, input_iterator_tag());
}
template <class BidirectionalIterator, class Size, class OutputIterator>
inline OutputIterator __copy_n(BidirectionalIterator first, Size count,
OutputIterator result,
bidirectional_iterator_tag) {
return __copy_n(first, count, result, input_iterator_tag());
}
template <class RandomAccessIterator, class Size, class OutputIterator> template <class RandomAccessIterator, class Size, class OutputIterator>
inline OutputIterator __copy_n(RandomAccessIterator first, Size count, inline OutputIterator __copy_n(RandomAccessIterator first, Size count,
OutputIterator result, OutputIterator result,
@ -657,22 +598,6 @@ ForwardIterator __uninitialized_copy_n(InputIterator first, Size count,
# endif /* __STL_USE_EXCEPTIONS */ # endif /* __STL_USE_EXCEPTIONS */
} }
template <class ForwardIterator1, class Size, class ForwardIterator>
inline ForwardIterator
__uninitialized_copy_n(ForwardIterator1 first, Size count,
ForwardIterator result,
forward_iterator_tag) {
return __uninitialized_copy_n(first, count, result, input_iterator_tag());
}
template <class BidirectionalIterator, class Size, class ForwardIterator>
inline ForwardIterator
__uninitialized_copy_n(BidirectionalIterator first, Size count,
ForwardIterator result,
bidirectional_iterator_tag) {
return __uninitialized_copy_n(first, count, result, input_iterator_tag());
}
template <class RandomAccessIterator, class Size, class ForwardIterator> template <class RandomAccessIterator, class Size, class ForwardIterator>
inline ForwardIterator inline ForwardIterator
__uninitialized_copy_n(RandomAccessIterator first, Size count, __uninitialized_copy_n(RandomAccessIterator first, Size count,

View File

@ -49,7 +49,6 @@
#endif #endif
#ifdef __STL_WIN32THREADS #ifdef __STL_WIN32THREADS
# include <windows.h> # include <windows.h>
// This must precede stl_config.h
#endif #endif
#include <stddef.h> #include <stddef.h>
@ -91,7 +90,11 @@
// This should work without threads, with sproc threads, or with // This should work without threads, with sproc threads, or with
// pthreads. It is suboptimal in all cases. // pthreads. It is suboptimal in all cases.
// It is unlikely to even compile on nonSGI machines. // It is unlikely to even compile on nonSGI machines.
# include <malloc.h>
extern int __us_rsthread_malloc;
// The above is copied from malloc.h. Including <malloc.h>
// would be cleaner but fails with certain levels of standard
// conformance.
# define __NODE_ALLOCATOR_LOCK if (threads && __us_rsthread_malloc) \ # define __NODE_ALLOCATOR_LOCK if (threads && __us_rsthread_malloc) \
{ __lock(&__node_allocator_lock); } { __lock(&__node_allocator_lock); }
# define __NODE_ALLOCATOR_UNLOCK if (threads && __us_rsthread_malloc) \ # define __NODE_ALLOCATOR_UNLOCK if (threads && __us_rsthread_malloc) \
@ -383,15 +386,17 @@ public:
obj * __VOLATILE * my_free_list; obj * __VOLATILE * my_free_list;
obj * __RESTRICT result; obj * __RESTRICT result;
if (n > __MAX_BYTES) { if (n > (size_t) __MAX_BYTES) {
return(malloc_alloc::allocate(n)); return(malloc_alloc::allocate(n));
} }
my_free_list = free_list + FREELIST_INDEX(n); my_free_list = free_list + FREELIST_INDEX(n);
// Acquire the lock here with a constructor call. // Acquire the lock here with a constructor call.
// This ensures that it is released in exit or during stack // This ensures that it is released in exit or during stack
// unwinding. // unwinding.
# ifndef _NOTHREADS
/*REFERENCED*/ /*REFERENCED*/
lock lock_instance; lock lock_instance;
# endif
result = *my_free_list; result = *my_free_list;
if (result == 0) { if (result == 0) {
void *r = refill(ROUND_UP(n)); void *r = refill(ROUND_UP(n));
@ -407,14 +412,16 @@ public:
obj *q = (obj *)p; obj *q = (obj *)p;
obj * __VOLATILE * my_free_list; obj * __VOLATILE * my_free_list;
if (n > __MAX_BYTES) { if (n > (size_t) __MAX_BYTES) {
malloc_alloc::deallocate(p, n); malloc_alloc::deallocate(p, n);
return; return;
} }
my_free_list = free_list + FREELIST_INDEX(n); my_free_list = free_list + FREELIST_INDEX(n);
// acquire lock // acquire lock
# ifndef _NOTHREADS
/*REFERENCED*/ /*REFERENCED*/
lock lock_instance; lock lock_instance;
# endif /* _NOTHREADS */
q -> free_list_link = *my_free_list; q -> free_list_link = *my_free_list;
*my_free_list = q; *my_free_list = q;
// lock is released here // lock is released here
@ -480,6 +487,7 @@ __default_alloc_template<threads, inst>::chunk_alloc(size_t size, int& nobjs)
// right free list. // right free list.
} }
} }
end_free = 0; // In case of exception.
start_free = (char *)malloc_alloc::allocate(bytes_to_get); start_free = (char *)malloc_alloc::allocate(bytes_to_get);
// This should either throw an // This should either throw an
// exception or remedy the situation. Thus we assume it // exception or remedy the situation. Thus we assume it
@ -533,7 +541,7 @@ __default_alloc_template<threads, inst>::reallocate(void *p,
void * result; void * result;
size_t copy_sz; size_t copy_sz;
if (old_sz > __MAX_BYTES && new_sz > __MAX_BYTES) { if (old_sz > (size_t) __MAX_BYTES && new_sz > (size_t) __MAX_BYTES) {
return(realloc(p, new_sz)); return(realloc(p, new_sz));
} }
if (ROUND_UP(old_sz) == ROUND_UP(new_sz)) return(p); if (ROUND_UP(old_sz) == ROUND_UP(new_sz)) return(p);
@ -671,4 +679,6 @@ __default_alloc_template<threads, inst> ::free_list[
#pragma reset woff 1174 #pragma reset woff 1174
#endif #endif
#endif /* __NODE_ALLOC_H */ #undef __PRIVATE
#endif /* __ALLOC_H */

View File

@ -82,7 +82,8 @@ public:
friend class bit_vector; friend class bit_vector;
friend class const_iterator; friend class const_iterator;
public: public:
typedef bit_reference reference; typedef bit_reference reference;
typedef bit_reference* pointer;
protected: protected:
unsigned int* p; unsigned int* p;
unsigned int offset; unsigned int offset;
@ -163,6 +164,7 @@ public:
friend class bit_vector; friend class bit_vector;
public: public:
typedef bit_const_reference reference; typedef bit_const_reference reference;
typedef const bool* pointer;
protected: protected:
unsigned int* p; unsigned int* p;
unsigned int offset; unsigned int offset;
@ -243,10 +245,15 @@ public:
} }
}; };
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
typedef reverse_iterator<const_iterator, value_type, const_reference, typedef reverse_iterator<const_iterator, value_type, const_reference,
difference_type> const_reverse_iterator; difference_type> const_reverse_iterator;
typedef reverse_iterator<iterator, value_type, reference, difference_type> typedef reverse_iterator<iterator, value_type, reference, difference_type>
reverse_iterator; reverse_iterator;
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
protected: protected:
typedef simple_alloc<unsigned int, alloc> data_allocator; typedef simple_alloc<unsigned int, alloc> data_allocator;
@ -303,20 +310,6 @@ protected:
copy(first, last, start); copy(first, last, start);
} }
template <class BidirectionalIterator>
void initialize_range(BidirectionalIterator first,
BidirectionalIterator last,
bidirectional_iterator_tag) {
initialize_range(first, last, forward_iterator_tag());
}
template <class RandomAccessIterator>
void initialize_range(RandomAccessIterator first,
RandomAccessIterator last,
random_access_iterator_tag) {
initialize_range(first, last, forward_iterator_tag());
}
template <class InputIterator> template <class InputIterator>
void insert_range(iterator pos, void insert_range(iterator pos,
InputIterator first, InputIterator last, InputIterator first, InputIterator last,
@ -352,20 +345,6 @@ protected:
} }
} }
template <class BidirectionalIterator>
void insert_range(iterator pos,
BidirectionalIterator first, BidirectionalIterator last,
bidirectional_iterator_tag) {
insert_range(pos, first, last, forward_iterator_tag());
}
template <class RandomAccessIterator>
void insert_range(iterator pos,
RandomAccessIterator first, RandomAccessIterator last,
random_access_iterator_tag) {
insert_range(pos, first, last, forward_iterator_tag());
}
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
typedef bit_vector self; typedef bit_vector self;

View File

@ -87,42 +87,44 @@ inline size_t __deque_buf_size(size_t n, size_t sz)
} }
#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG #ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
template <class T, class Ref, size_t BufSiz> template <class T, class Ref, class Ptr, size_t BufSiz>
struct __deque_iterator { struct __deque_iterator {
typedef __deque_iterator<T, T&, BufSiz> iterator; typedef __deque_iterator<T, T&, T*, BufSiz> iterator;
typedef __deque_iterator<T, const T&, BufSiz> const_iterator; typedef __deque_iterator<T, const T&, const T*, BufSiz> const_iterator;
static size_t buffer_size() {return __deque_buf_size(BufSiz, sizeof(T)); } static size_t buffer_size() {return __deque_buf_size(BufSiz, sizeof(T)); }
#else /* __STL_NON_TYPE_TMPL_PARAM_BUG */ #else /* __STL_NON_TYPE_TMPL_PARAM_BUG */
template <class T, class Ref> template <class T, class Ref, class Ptr>
struct __deque_iterator { struct __deque_iterator {
typedef __deque_iterator<T, T&> iterator; typedef __deque_iterator<T, T&, T*> iterator;
typedef __deque_iterator<T, const T&> const_iterator; typedef __deque_iterator<T, const T&, const T*> const_iterator;
static size_t buffer_size() {return __deque_buf_size(0, sizeof(T)); } static size_t buffer_size() {return __deque_buf_size(0, sizeof(T)); }
#endif #endif
typedef random_access_iterator_tag iterator_category; typedef random_access_iterator_tag iterator_category;
typedef T value_type; typedef T value_type;
typedef value_type* pointer; typedef Ptr pointer;
typedef value_type& reference; typedef Ref reference;
typedef const value_type& const_reference;
typedef size_t size_type; typedef size_t size_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef pointer* map_pointer; typedef T** map_pointer;
typedef __deque_iterator self; typedef __deque_iterator self;
pointer cur; T* cur;
pointer first; T* first;
pointer last; T* last;
map_pointer node; map_pointer node;
__deque_iterator(pointer x, map_pointer y) __deque_iterator(T* x, map_pointer y)
: cur(x), first(*y), last(*y + buffer_size()), node(y) {} : cur(x), first(*y), last(*y + buffer_size()), node(y) {}
__deque_iterator() : cur(0), first(0), last(0), node(0) {} __deque_iterator() : cur(0), first(0), last(0), node(0) {}
__deque_iterator(const iterator& x) __deque_iterator(const iterator& x)
: cur(x.cur), first(x.first), last(x.last), node(x.node) {} : cur(x.cur), first(x.first), last(x.last), node(x.node) {}
Ref operator*() const { return *cur; } reference operator*() const { return *cur; }
#ifndef __SGI_STL_NO_ARROW_OPERATOR
pointer operator->() const { return &(operator*()); }
#endif /* __SGI_STL_NO_ARROW_OPERATOR */
difference_type operator-(const self& x) const { difference_type operator-(const self& x) const {
return buffer_size() * (node - x.node - 1) + return buffer_size() * (node - x.node - 1) +
@ -183,7 +185,7 @@ struct __deque_iterator {
return tmp -= n; return tmp -= n;
} }
Ref operator[](difference_type n) const { return *(*this + n); } reference operator[](difference_type n) const { return *(*this + n); }
bool operator==(const self& x) const { return cur == x.cur; } bool operator==(const self& x) const { return cur == x.cur; }
bool operator!=(const self& x) const { return !(*this == x); } bool operator!=(const self& x) const { return !(*this == x); }
@ -198,40 +200,45 @@ struct __deque_iterator {
} }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG #ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
template <class T, class Ref, size_t BufSiz> template <class T, class Ref, class Ptr, size_t BufSiz>
inline random_access_iterator_tag inline random_access_iterator_tag
iterator_category(const __deque_iterator<T, Ref, BufSiz>&) { iterator_category(const __deque_iterator<T, Ref, Ptr, BufSiz>&) {
return random_access_iterator_tag(); return random_access_iterator_tag();
} }
template <class T, class Ref, size_t BufSiz> template <class T, class Ref, class Ptr, size_t BufSiz>
inline T* value_type(const __deque_iterator<T, Ref, BufSiz>&) { return 0; } inline T* value_type(const __deque_iterator<T, Ref, Ptr, BufSiz>&) {
return 0;
}
template <class T, class Ref, size_t BufSiz> template <class T, class Ref, class Ptr, size_t BufSiz>
inline ptrdiff_t* distance_type(const __deque_iterator<T, Ref, BufSiz>&) { inline ptrdiff_t* distance_type(const __deque_iterator<T, Ref, Ptr, BufSiz>&) {
return 0; return 0;
} }
#else /* __STL_NON_TYPE_TMPL_PARAM_BUG */ #else /* __STL_NON_TYPE_TMPL_PARAM_BUG */
template <class T, class Ref> template <class T, class Ref, class Ptr>
inline random_access_iterator_tag inline random_access_iterator_tag
iterator_category(const __deque_iterator<T, Ref>&) { iterator_category(const __deque_iterator<T, Ref, Ptr>&) {
return random_access_iterator_tag(); return random_access_iterator_tag();
} }
template <class T, class Ref> template <class T, class Ref, class Ptr>
inline T* value_type(const __deque_iterator<T, Ref>&) { return 0; } inline T* value_type(const __deque_iterator<T, Ref, Ptr>&) { return 0; }
template <class T, class Ref> template <class T, class Ref, class Ptr>
inline ptrdiff_t* distance_type(const __deque_iterator<T, Ref>&) { inline ptrdiff_t* distance_type(const __deque_iterator<T, Ref, Ptr>&) {
return 0; return 0;
} }
#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */ #endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
// See __deque_buf_size(). The only reason that the default value is 0 // See __deque_buf_size(). The only reason that the default value is 0
// is as a workaround for bugs in the way that some compilers handle // is as a workaround for bugs in the way that some compilers handle
@ -248,17 +255,23 @@ public: // Basic types
public: // Iterators public: // Iterators
#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG #ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
typedef __deque_iterator<value_type, reference, BufSiz> iterator; typedef __deque_iterator<T, T&, T*, BufSiz> iterator;
typedef __deque_iterator<value_type, const_reference, BufSiz> const_iterator; typedef __deque_iterator<T, const T&, const T&, BufSiz> const_iterator;
#else /* __STL_NON_TYPE_TMPL_PARAM_BUG */ #else /* __STL_NON_TYPE_TMPL_PARAM_BUG */
typedef __deque_iterator<value_type, reference> iterator; typedef __deque_iterator<T, T&, T*> iterator;
typedef __deque_iterator<value_type, const_reference> const_iterator; typedef __deque_iterator<T, const T&, const T*> const_iterator;
#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */ #endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
typedef reverse_iterator<const_iterator, value_type, const_reference, typedef reverse_iterator<const_iterator, value_type, const_reference,
difference_type> difference_type>
const_reverse_iterator; const_reverse_iterator;
typedef reverse_iterator<iterator, value_type, reference, difference_type> typedef reverse_iterator<iterator, value_type, reference, difference_type>
reverse_iterator; reverse_iterator;
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
protected: // Internal typedefs protected: // Internal typedefs
typedef pointer* map_pointer; typedef pointer* map_pointer;
@ -553,19 +566,6 @@ protected: // Internal construction/destruction
void range_initialize(ForwardIterator first, ForwardIterator last, void range_initialize(ForwardIterator first, ForwardIterator last,
forward_iterator_tag); forward_iterator_tag);
template <class BidirectionalIterator>
void range_initialize(BidirectionalIterator first,
BidirectionalIterator last,
bidirectional_iterator_tag) {
range_initialize(first, last, forward_iterator_tag());
}
template <class RandomAccessIterator>
void range_initialize(RandomAccessIterator first, RandomAccessIterator last,
random_access_iterator_tag) {
range_initialize(first, last, forward_iterator_tag());
}
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
protected: // Internal push_* and pop_* protected: // Internal push_* and pop_*
@ -587,19 +587,6 @@ protected: // Internal insert functions
void insert(iterator pos, ForwardIterator first, ForwardIterator last, void insert(iterator pos, ForwardIterator first, ForwardIterator last,
forward_iterator_tag); forward_iterator_tag);
template <class BidirectionalIterator>
void insert(iterator pos,
BidirectionalIterator first, BidirectionalIterator last,
bidirectional_iterator_tag) {
insert(pos, first, last, forward_iterator_tag());
}
template <class RandomAccessIterator>
void insert(iterator pos,
RandomAccessIterator first, RandomAccessIterator last,
random_access_iterator_tag) {
insert(pos, first, last, forward_iterator_tag());
}
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
iterator insert_aux(iterator pos, const value_type& x); iterator insert_aux(iterator pos, const value_type& x);
@ -881,7 +868,7 @@ void deque<T, Alloc, BufSize>::fill_initialize(size_type n,
} }
catch(...) { catch(...) {
for (map_pointer n = start.node; n < cur; ++n) for (map_pointer n = start.node; n < cur; ++n)
destroy(*cur, *cur + buffer_size()); destroy(*n, *n + buffer_size());
destroy_map_and_nodes(); destroy_map_and_nodes();
throw; throw;
} }

View File

@ -123,7 +123,6 @@ struct __hashtable_iterator {
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef size_t size_type; typedef size_t size_type;
typedef Value& reference; typedef Value& reference;
typedef const Value& const_reference;
typedef Value* pointer; typedef Value* pointer;
node* cur; node* cur;
@ -132,6 +131,9 @@ struct __hashtable_iterator {
__hashtable_iterator(node* n, hashtable* tab) : cur(n), ht(tab) {} __hashtable_iterator(node* n, hashtable* tab) : cur(n), ht(tab) {}
__hashtable_iterator() {} __hashtable_iterator() {}
reference operator*() const { return cur->val; } reference operator*() const { return cur->val; }
#ifndef __SGI_STL_NO_ARROW_OPERATOR
pointer operator->() const { return &(operator*()); }
#endif /* __SGI_STL_NO_ARROW_OPERATOR */
iterator& operator++(); iterator& operator++();
iterator operator++(int); iterator operator++(int);
bool operator==(const iterator& it) const { return cur == it.cur; } bool operator==(const iterator& it) const { return cur == it.cur; }
@ -156,9 +158,8 @@ struct __hashtable_const_iterator {
typedef Value value_type; typedef Value value_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef size_t size_type; typedef size_t size_type;
typedef Value& reference; typedef const Value& reference;
typedef const Value& const_reference; typedef const Value* pointer;
typedef Value* pointer;
const node* cur; const node* cur;
const hashtable* ht; const hashtable* ht;
@ -167,7 +168,10 @@ struct __hashtable_const_iterator {
: cur(n), ht(tab) {} : cur(n), ht(tab) {}
__hashtable_const_iterator() {} __hashtable_const_iterator() {}
__hashtable_const_iterator(const iterator& it) : cur(it.cur), ht(it.ht) {} __hashtable_const_iterator(const iterator& it) : cur(it.cur), ht(it.ht) {}
const_reference operator*() const { return cur->val; } reference operator*() const { return cur->val; }
#ifndef __SGI_STL_NO_ARROW_OPERATOR
pointer operator->() const { return &(operator*()); }
#endif /* __SGI_STL_NO_ARROW_OPERATOR */
const_iterator& operator++(); const_iterator& operator++();
const_iterator operator++(int); const_iterator operator++(int);
bool operator==(const const_iterator& it) const { return cur == it.cur; } bool operator==(const const_iterator& it) const { return cur == it.cur; }
@ -399,34 +403,6 @@ public:
insert_equal_noresize(*f); insert_equal_noresize(*f);
} }
template <class BidirectionalIterator>
void insert_unique(BidirectionalIterator f, BidirectionalIterator l,
bidirectional_iterator_tag)
{
insert_unique(f, l, forward_iterator_tag());
}
template <class BidirectionalIterator>
void insert_equal(BidirectionalIterator f, BidirectionalIterator l,
bidirectional_iterator_tag)
{
insert_equal(f, l, forward_iterator_tag());
}
template <class RandomAccessIterator>
void insert_unique(RandomAccessIterator f, RandomAccessIterator l,
random_access_iterator_tag)
{
insert_unique(f, l, forward_iterator_tag());
}
template <class RandomAccessIterator>
void insert_equal(RandomAccessIterator f, RandomAccessIterator l,
random_access_iterator_tag)
{
insert_equal(f, l, forward_iterator_tag());
}
#else /* __STL_MEMBER_TEMPLATES */ #else /* __STL_MEMBER_TEMPLATES */
void insert_unique(const value_type* f, const value_type* l) void insert_unique(const value_type* f, const value_type* l)
{ {
@ -619,6 +595,7 @@ __hashtable_const_iterator<V, K, HF, ExK, EqK, A>::operator++(int)
return tmp; return tmp;
} }
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class V, class K, class HF, class ExK, class EqK, class All> template <class V, class K, class HF, class ExK, class EqK, class All>
inline forward_iterator_tag inline forward_iterator_tag
@ -661,6 +638,8 @@ distance_type(const __hashtable_const_iterator<V, K, HF, ExK, EqK, All>&)
return (hashtable<V, K, HF, ExK, EqK, All>::difference_type*) 0; return (hashtable<V, K, HF, ExK, EqK, All>::difference_type*) 0;
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class V, class K, class HF, class Ex, class Eq, class A> template <class V, class K, class HF, class Ex, class Eq, class A>
bool operator==(const hashtable<V, K, HF, Ex, Eq, A>& ht1, bool operator==(const hashtable<V, K, HF, Ex, Eq, A>& ht1,
const hashtable<V, K, HF, Ex, Eq, A>& ht2) const hashtable<V, K, HF, Ex, Eq, A>& ht2)

View File

@ -33,9 +33,9 @@
struct input_iterator_tag {}; struct input_iterator_tag {};
struct output_iterator_tag {}; struct output_iterator_tag {};
struct forward_iterator_tag {}; struct forward_iterator_tag : public input_iterator_tag {};
struct bidirectional_iterator_tag {}; struct bidirectional_iterator_tag : public forward_iterator_tag {};
struct random_access_iterator_tag {}; struct random_access_iterator_tag : public bidirectional_iterator_tag {};
template <class T, class Distance> struct input_iterator { template <class T, class Distance> struct input_iterator {
typedef input_iterator_tag iterator_category; typedef input_iterator_tag iterator_category;
@ -47,6 +47,10 @@ template <class T, class Distance> struct input_iterator {
struct output_iterator { struct output_iterator {
typedef output_iterator_tag iterator_category; typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
}; };
template <class T, class Distance> struct forward_iterator { template <class T, class Distance> struct forward_iterator {
@ -106,7 +110,34 @@ struct iterator_traits<T*> {
typedef T& reference; typedef T& reference;
}; };
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */ template <class T>
struct iterator_traits<const T*> {
typedef random_access_iterator_tag iterator_category;
typedef T value_type;
typedef ptrdiff_t difference_type;
typedef const T* pointer;
typedef const T& reference;
};
template <class Iterator>
inline iterator_traits<Iterator>::iterator_category
iterator_category(const Iterator&) {
return iterator_traits<Iterator>::iterator_category();
}
template <class Iterator>
inline iterator_traits<Iterator>::difference_type*
distance_type(const Iterator&) {
return static_cast<iterator_traits<Iterator>::difference_type*>(0);
}
template <class Iterator>
inline iterator_traits<Iterator>::value_type*
value_type(const Iterator&) {
return static_cast<iterator_traits<Iterator>::value_type*>(0);
}
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class T, class Distance> template <class T, class Distance>
inline input_iterator_tag inline input_iterator_tag
@ -189,12 +220,18 @@ distance_type(const random_access_iterator<T, Distance>&) {
template <class T> template <class T>
inline ptrdiff_t* distance_type(const T*) { return (ptrdiff_t*)(0); } inline ptrdiff_t* distance_type(const T*) { return (ptrdiff_t*)(0); }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class Container> template <class Container>
class back_insert_iterator { class back_insert_iterator {
protected: protected:
Container* container; Container* container;
public: public:
typedef output_iterator_tag iterator_category; typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
explicit back_insert_iterator(Container& x) : container(&x) {} explicit back_insert_iterator(Container& x) : container(&x) {}
back_insert_iterator<Container>& back_insert_iterator<Container>&
@ -207,6 +244,8 @@ public:
back_insert_iterator<Container>& operator++(int) { return *this; } back_insert_iterator<Container>& operator++(int) { return *this; }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class Container> template <class Container>
inline output_iterator_tag inline output_iterator_tag
iterator_category(const back_insert_iterator<Container>&) iterator_category(const back_insert_iterator<Container>&)
@ -214,6 +253,8 @@ iterator_category(const back_insert_iterator<Container>&)
return output_iterator_tag(); return output_iterator_tag();
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class Container> template <class Container>
inline back_insert_iterator<Container> back_inserter(Container& x) { inline back_insert_iterator<Container> back_inserter(Container& x) {
return back_insert_iterator<Container>(x); return back_insert_iterator<Container>(x);
@ -225,6 +266,10 @@ protected:
Container* container; Container* container;
public: public:
typedef output_iterator_tag iterator_category; typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
explicit front_insert_iterator(Container& x) : container(&x) {} explicit front_insert_iterator(Container& x) : container(&x) {}
front_insert_iterator<Container>& front_insert_iterator<Container>&
@ -237,6 +282,8 @@ public:
front_insert_iterator<Container>& operator++(int) { return *this; } front_insert_iterator<Container>& operator++(int) { return *this; }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class Container> template <class Container>
inline output_iterator_tag inline output_iterator_tag
iterator_category(const front_insert_iterator<Container>&) iterator_category(const front_insert_iterator<Container>&)
@ -244,6 +291,8 @@ iterator_category(const front_insert_iterator<Container>&)
return output_iterator_tag(); return output_iterator_tag();
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class Container> template <class Container>
inline front_insert_iterator<Container> front_inserter(Container& x) { inline front_insert_iterator<Container> front_inserter(Container& x) {
return front_insert_iterator<Container>(x); return front_insert_iterator<Container>(x);
@ -256,6 +305,10 @@ protected:
typename Container::iterator iter; typename Container::iterator iter;
public: public:
typedef output_iterator_tag iterator_category; typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
insert_iterator(Container& x, typename Container::iterator i) insert_iterator(Container& x, typename Container::iterator i)
: container(&x), iter(i) {} : container(&x), iter(i) {}
@ -270,6 +323,8 @@ public:
insert_iterator<Container>& operator++(int) { return *this; } insert_iterator<Container>& operator++(int) { return *this; }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class Container> template <class Container>
inline output_iterator_tag inline output_iterator_tag
iterator_category(const insert_iterator<Container>&) iterator_category(const insert_iterator<Container>&)
@ -277,6 +332,8 @@ iterator_category(const insert_iterator<Container>&)
return output_iterator_tag(); return output_iterator_tag();
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class Container, class Iterator> template <class Container, class Iterator>
inline insert_iterator<Container> inserter(Container& x, Iterator i) { inline insert_iterator<Container> inserter(Container& x, Iterator i) {
typedef typename Container::iterator iter; typedef typename Container::iterator iter;
@ -311,6 +368,9 @@ public:
BidirectionalIterator tmp = current; BidirectionalIterator tmp = current;
return *--tmp; return *--tmp;
} }
#ifndef __SGI_STL_NO_ARROW_OPERATOR
pointer operator->() const { return &(operator*()); }
#endif /* __SGI_STL_NO_ARROW_OPERATOR */
self& operator++() { self& operator++() {
--current; --current;
return *this; return *this;
@ -331,6 +391,7 @@ public:
} }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class BidirectionalIterator, class T, class Reference, template <class BidirectionalIterator, class T, class Reference,
class Distance> class Distance>
@ -357,6 +418,8 @@ distance_type(const reverse_bidirectional_iterator<BidirectionalIterator, T,
return (Distance*) 0; return (Distance*) 0;
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class BidirectionalIterator, class T, class Reference, template <class BidirectionalIterator, class T, class Reference,
class Distance> class Distance>
inline bool operator==( inline bool operator==(
@ -367,6 +430,109 @@ inline bool operator==(
return x.current == y.current; return x.current == y.current;
} }
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
// This is the new version of reverse_iterator, as defined in the
// draft C++ standard. It relies on the iterator_traits template,
// which in turn relies on partial specialization. The class
// reverse_bidirectional_iterator is no longer part of the draft
// standard, but it is retained for backward compatibility.
template <class Iterator>
class reverse_iterator : public iterator_traits<Iterator>
{
protected:
Iterator current;
public:
typedef Iterator iterator_type;
typedef reverse_iterator<Iterator> self;
public:
reverse_iterator() {}
explicit reverse_iterator(iterator_type x) : current(x) {}
reverse_iterator(const self& x) : current(x.current) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class Iter>
reverse_iterator(const reverse_iterator<Iter>& x) : current(x.current) {}
#endif /* __STL_MEMBER_TEMPLATES */
iterator_type base() const { return current; }
reference operator*() const {
Iterator tmp = current;
return *--tmp;
}
#ifndef __SGI_STL_NO_ARROW_OPERATOR
pointer operator->() const { return &(operator*()); }
#endif /* __SGI_STL_NO_ARROW_OPERATOR */
self& operator++() {
--current;
return *this;
}
self operator++(int) {
self tmp = *this;
--current;
return tmp;
}
self& operator--() {
++current;
return *this;
}
self operator--(int) {
self tmp = *this;
++current;
return tmp;
}
self operator+(difference_type n) const {
return self(current - n);
}
self& operator+=(difference_type n) {
current -= n;
return *this;
}
self operator-(difference_type n) const {
return self(current + n);
}
self& operator-=(difference_type n) {
current += n;
return *this;
}
reference operator[](difference_type n) { return *(*this + n); }
};
template <class Iterator>
inline bool operator==(const reverse_iterator<Iterator>& x,
const reverse_iterator<Iterator>& y) {
return x.base() == y.base();
}
template <class Iterator>
inline bool operator<(const reverse_iterator<Iterator>& x,
const reverse_iterator<Iterator>& y) {
return y.base() < x.base();
}
template <class Iterator>
inline reverse_iterator<Iterator>::difference_type
operator-(const reverse_iterator<Iterator>& x,
const reverse_iterator<Iterator>& y) {
return y.base() - x.base();
}
template <class Iterator>
inline reverse_iterator<Iterator>
operator+(reverse_iterator<Iterator>::difference_type n,
const reverse_iterator<Iterator>& x) {
return reverse_iterator<Iterator>(x.base() - n);
}
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
// This is the old version of reverse_iterator, as found in the original
// HP STL. It does not use partial specialization.
#ifndef __STL_LIMITED_DEFAULT_TEMPLATES #ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class RandomAccessIterator, class T, class Reference = T&, template <class RandomAccessIterator, class T, class Reference = T&,
class Distance = ptrdiff_t> class Distance = ptrdiff_t>
@ -394,6 +560,9 @@ public:
explicit reverse_iterator(RandomAccessIterator x) : current(x) {} explicit reverse_iterator(RandomAccessIterator x) : current(x) {}
RandomAccessIterator base() { return current; } RandomAccessIterator base() { return current; }
Reference operator*() const { return *(current - 1); } Reference operator*() const { return *(current - 1); }
#ifndef __SGI_STL_NO_ARROW_OPERATOR
pointer operator->() const { return &(operator*()); }
#endif /* __SGI_STL_NO_ARROW_OPERATOR */
self& operator++() { self& operator++() {
--current; --current;
return *this; return *this;
@ -482,6 +651,7 @@ operator+(Distance n,
(x.current - n); (x.current - n);
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class ForwardIterator, class T> template <class ForwardIterator, class T>
class raw_storage_iterator { class raw_storage_iterator {
@ -489,6 +659,10 @@ protected:
ForwardIterator iter; ForwardIterator iter;
public: public:
typedef output_iterator_tag iterator_category; typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
explicit raw_storage_iterator(ForwardIterator x) : iter(x) {} explicit raw_storage_iterator(ForwardIterator x) : iter(x) {}
raw_storage_iterator<ForwardIterator, T>& operator*() { return *this; } raw_storage_iterator<ForwardIterator, T>& operator*() { return *this; }
@ -507,6 +681,8 @@ public:
} }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class ForwardIterator, class T> template <class ForwardIterator, class T>
inline output_iterator_tag inline output_iterator_tag
iterator_category(const raw_storage_iterator<ForwardIterator, T>&) iterator_category(const raw_storage_iterator<ForwardIterator, T>&)
@ -514,6 +690,8 @@ iterator_category(const raw_storage_iterator<ForwardIterator, T>&)
return output_iterator_tag(); return output_iterator_tag();
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class T, class Distance = ptrdiff_t> template <class T, class Distance = ptrdiff_t>
class istream_iterator { class istream_iterator {
friend bool operator==(const istream_iterator<T, Distance>& x, friend bool operator==(const istream_iterator<T, Distance>& x,
@ -531,12 +709,15 @@ public:
typedef input_iterator_tag iterator_category; typedef input_iterator_tag iterator_category;
typedef T value_type; typedef T value_type;
typedef Distance difference_type; typedef Distance difference_type;
typedef T* pointer; typedef const T* pointer;
typedef T& reference; typedef const T& reference;
istream_iterator() : stream(&cin), end_marker(false) {} istream_iterator() : stream(&cin), end_marker(false) {}
istream_iterator(istream& s) : stream(&s) { read(); } istream_iterator(istream& s) : stream(&s) { read(); }
const T& operator*() const { return value; } reference operator*() const { return value; }
#ifndef __SGI_STL_NO_ARROW_OPERATOR
pointer operator->() const { return &(operator*()); }
#endif /* __SGI_STL_NO_ARROW_OPERATOR */
istream_iterator<T, Distance>& operator++() { istream_iterator<T, Distance>& operator++() {
read(); read();
return *this; return *this;
@ -548,6 +729,8 @@ public:
} }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class T, class Distance> template <class T, class Distance>
inline input_iterator_tag inline input_iterator_tag
iterator_category(const istream_iterator<T, Distance>&) { iterator_category(const istream_iterator<T, Distance>&) {
@ -562,6 +745,8 @@ inline Distance* distance_type(const istream_iterator<T, Distance>&) {
return (Distance*) 0; return (Distance*) 0;
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class T, class Distance> template <class T, class Distance>
bool operator==(const istream_iterator<T, Distance>& x, bool operator==(const istream_iterator<T, Distance>& x,
const istream_iterator<T, Distance>& y) { const istream_iterator<T, Distance>& y) {
@ -576,6 +761,10 @@ protected:
const char* string; const char* string;
public: public:
typedef output_iterator_tag iterator_category; typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
ostream_iterator(ostream& s) : stream(&s), string(0) {} ostream_iterator(ostream& s) : stream(&s), string(0) {}
ostream_iterator(ostream& s, const char* c) : stream(&s), string(c) {} ostream_iterator(ostream& s, const char* c) : stream(&s), string(c) {}
@ -589,10 +778,14 @@ public:
ostream_iterator<T>& operator++(int) { return *this; } ostream_iterator<T>& operator++(int) { return *this; }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class T> template <class T>
inline output_iterator_tag inline output_iterator_tag
iterator_category(const ostream_iterator<T>&) { iterator_category(const ostream_iterator<T>&) {
return output_iterator_tag(); return output_iterator_tag();
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
#endif /* __SGI_STL_ITERATOR_H */ #endif /* __SGI_STL_ITERATOR_H */

View File

@ -40,17 +40,16 @@ struct __list_node {
T data; T data;
}; };
template<class T, class Ref> template<class T, class Ref, class Ptr>
struct __list_iterator { struct __list_iterator {
typedef __list_iterator<T, T&> iterator; typedef __list_iterator<T, T&, T*> iterator;
typedef __list_iterator<T, const T&> const_iterator; typedef __list_iterator<T, const T&, const T*> const_iterator;
typedef __list_iterator<T, Ref> self; typedef __list_iterator<T, Ref, Ptr> self;
typedef bidirectional_iterator_tag iterator_category; typedef bidirectional_iterator_tag iterator_category;
typedef T value_type; typedef T value_type;
typedef value_type* pointer; typedef Ptr pointer;
typedef value_type& reference; typedef Ref reference;
typedef const value_type& const_reference;
typedef __list_node<T>* link_type; typedef __list_node<T>* link_type;
typedef size_t size_type; typedef size_t size_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
@ -63,7 +62,11 @@ struct __list_iterator {
bool operator==(const self& x) const { return node == x.node; } bool operator==(const self& x) const { return node == x.node; }
bool operator!=(const self& x) const { return node != x.node; } bool operator!=(const self& x) const { return node != x.node; }
Ref operator*() const { return (*node).data; } reference operator*() const { return (*node).data; }
#ifndef __SGI_STL_NO_ARROW_OPERATOR
pointer operator->() const { return &(operator*()); }
#endif /* __SGI_STL_NO_ARROW_OPERATOR */
self& operator++() { self& operator++() {
node = (link_type)((*node).next); node = (link_type)((*node).next);
@ -85,25 +88,27 @@ struct __list_iterator {
} }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class T, class Ref> template <class T, class Ref, class Ptr>
inline bidirectional_iterator_tag inline bidirectional_iterator_tag
iterator_category(const __list_iterator<T, Ref>&) { iterator_category(const __list_iterator<T, Ref, Ptr>&) {
return bidirectional_iterator_tag(); return bidirectional_iterator_tag();
} }
template <class T, class Ref> template <class T, class Ref, class Ptr>
inline T* inline T*
value_type(const __list_iterator<T, Ref>&) { value_type(const __list_iterator<T, Ref, Ptr>&) {
return 0; return 0;
} }
template <class T, class Ref> template <class T, class Ref, class Ptr>
inline ptrdiff_t* inline ptrdiff_t*
distance_type(const __list_iterator<T, Ref>&) { distance_type(const __list_iterator<T, Ref, Ptr>&) {
return 0; return 0;
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class T, class Alloc = alloc> template <class T, class Alloc = alloc>
class list { class list {
@ -121,15 +126,20 @@ public:
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
public: public:
typedef __list_iterator<T, T&> iterator; typedef __list_iterator<T, T&, T*> iterator;
typedef __list_iterator<T, const T&> const_iterator; typedef __list_iterator<T, const T&, const T*> const_iterator;
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
typedef reverse_bidirectional_iterator<const_iterator, value_type, typedef reverse_bidirectional_iterator<const_iterator, value_type,
const_reference, difference_type> const_reference, difference_type>
const_reverse_iterator; const_reverse_iterator;
typedef reverse_bidirectional_iterator<iterator, value_type, reference, typedef reverse_bidirectional_iterator<iterator, value_type, reference,
difference_type> difference_type>
reverse_iterator; reverse_iterator;
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
protected: protected:
link_type get_node() { return list_node_allocator::allocate(); } link_type get_node() { return list_node_allocator::allocate(); }

View File

@ -38,18 +38,18 @@ inline charT __eos(charT*) { return charT(); }
// Test for basic character types. // Test for basic character types.
// For basic character types leaves having a trailing eos. // For basic character types leaves having a trailing eos.
template <class charT> template <class charT>
inline bool __is_basic_char_type(charT* c) { return false; } inline bool __is_basic_char_type(charT *) { return false; }
template <class charT> template <class charT>
inline bool __is_one_byte_char_type(charT* c) { return false; } inline bool __is_one_byte_char_type(charT *) { return false; }
inline bool __is_basic_char_type(char* c) { return true; } inline bool __is_basic_char_type(char *) { return true; }
inline bool __is_one_byte_char_type(char* c) { return true; } inline bool __is_one_byte_char_type(char *) { return true; }
inline bool __is_basic_char_type(wchar_t* c) { return true; } inline bool __is_basic_char_type(wchar_t *) { return true; }
// Store an eos iff charT is a basic character type. // Store an eos iff charT is a basic character type.
// Do not reference __eos if it isn't. // Do not reference __eos if it isn't.
template <class charT> template <class charT>
inline void __cond_store_eos(charT& c) {} inline void __cond_store_eos(charT&) {}
inline void __cond_store_eos(char& c) { c = 0; } inline void __cond_store_eos(char& c) { c = 0; }
inline void __cond_store_eos(wchar_t& c) { c = 0; } inline void __cond_store_eos(wchar_t& c) { c = 0; }
@ -235,6 +235,7 @@ template<class CharT, class Alloc> class __rope_charT_ptr_proxy;
template<class charT, class Alloc> template<class charT, class Alloc>
struct __rope_RopeBase { struct __rope_RopeBase {
typedef rope<charT,Alloc> my_rope; typedef rope<charT,Alloc> my_rope;
typedef simple_alloc<charT, Alloc> DataAlloc;
typedef simple_alloc<__rope_RopeConcatenation<charT,Alloc>, Alloc> CAlloc; typedef simple_alloc<__rope_RopeConcatenation<charT,Alloc>, Alloc> CAlloc;
typedef simple_alloc<__rope_RopeLeaf<charT,Alloc>, Alloc> LAlloc; typedef simple_alloc<__rope_RopeLeaf<charT,Alloc>, Alloc> LAlloc;
typedef simple_alloc<__rope_RopeFunction<charT,Alloc>, Alloc> FAlloc; typedef simple_alloc<__rope_RopeFunction<charT,Alloc>, Alloc> FAlloc;
@ -368,12 +369,17 @@ struct __rope_RopeBase {
{ {
if (0 != t) t -> incr_refcount(); if (0 != t) t -> incr_refcount();
} }
static void free_if_unref(__rope_RopeBase* t)
{
if (0 != t && 0 == t -> refcount) t -> free_tree();
}
# else /* __GC */ # else /* __GC */
void unref_nonnil() {} void unref_nonnil() {}
void ref_nonnil() {} void ref_nonnil() {}
static void unref(__rope_RopeBase* t) {} static void unref(__rope_RopeBase* t) {}
static void ref(__rope_RopeBase* t) {} static void ref(__rope_RopeBase* t) {}
static void fn_finalization_proc(void * tree, void *); static void fn_finalization_proc(void * tree, void *);
static void free_if_unref(__rope_RopeBase* t) {}
# endif # endif
// The data fields of leaves are allocated with some // The data fields of leaves are allocated with some
@ -384,9 +390,9 @@ struct __rope_RopeBase {
size_t size_with_eos; size_t size_with_eos;
if (__is_basic_char_type((charT *)0)) { if (__is_basic_char_type((charT *)0)) {
size_with_eos = (n + 1) * sizeof(charT); size_with_eos = n + 1;
} else { } else {
size_with_eos = n * sizeof(charT); size_with_eos = n;
} }
# ifdef __GC # ifdef __GC
return size_with_eos; return size_with_eos;
@ -684,6 +690,11 @@ class __rope_const_iterator : public __rope_iterator_base<charT,Alloc> {
const_cast<RopeBase *>(root), pos) const_cast<RopeBase *>(root), pos)
// Only nonconst iterators modify root ref count // Only nonconst iterators modify root ref count
{} {}
public:
typedef charT reference; // Really a value. Returning a reference
// Would be a mess, since it would have
// to be included in refcount.
typedef const charT* pointer;
public: public:
__rope_const_iterator() {}; __rope_const_iterator() {};
@ -702,7 +713,7 @@ class __rope_const_iterator : public __rope_iterator_base<charT,Alloc> {
} }
return(*this); return(*this);
} }
const charT& operator*() { reference operator*() {
if (0 == buf_ptr) setcache(*this); if (0 == buf_ptr) setcache(*this);
return *buf_ptr; return *buf_ptr;
} }
@ -758,7 +769,7 @@ class __rope_const_iterator : public __rope_iterator_base<charT,Alloc> {
friend __rope_const_iterator<charT,Alloc> operator+ friend __rope_const_iterator<charT,Alloc> operator+
(ptrdiff_t n, (ptrdiff_t n,
const __rope_const_iterator<charT,Alloc> & x); const __rope_const_iterator<charT,Alloc> & x);
charT operator[](size_t n) { reference operator[](size_t n) {
return rope<charT,Alloc>::fetch(root, current_pos + n); return rope<charT,Alloc>::fetch(root, current_pos + n);
} }
friend bool operator== friend bool operator==
@ -790,6 +801,10 @@ class __rope_iterator : public __rope_iterator_base<charT,Alloc> {
RopeBase::ref(root); RopeBase::ref(root);
} }
void check(); void check();
public:
typedef __rope_charT_ref_proxy<charT,Alloc> reference;
typedef __rope_charT_ref_proxy<charT,Alloc>* pointer;
public: public:
rope<charT,Alloc>& container() { return *root_rope; } rope<charT,Alloc>& container() { return *root_rope; }
__rope_iterator() { __rope_iterator() {
@ -819,7 +834,7 @@ class __rope_iterator : public __rope_iterator_base<charT,Alloc> {
RopeBase::unref(old); RopeBase::unref(old);
return(*this); return(*this);
} }
__rope_charT_ref_proxy<charT,Alloc> operator*() { reference operator*() {
check(); check();
if (0 == buf_ptr) { if (0 == buf_ptr) {
return __rope_charT_ref_proxy<charT,Alloc>(root_rope, current_pos); return __rope_charT_ref_proxy<charT,Alloc>(root_rope, current_pos);
@ -862,7 +877,7 @@ class __rope_iterator : public __rope_iterator_base<charT,Alloc> {
decr(1); decr(1);
return __rope_iterator<charT,Alloc>(root_rope, old_pos); return __rope_iterator<charT,Alloc>(root_rope, old_pos);
} }
__rope_charT_ref_proxy<charT,Alloc> operator[](ptrdiff_t n) { reference operator[](ptrdiff_t n) {
return __rope_charT_ref_proxy<charT,Alloc>(root_rope, current_pos + n); return __rope_charT_ref_proxy<charT,Alloc>(root_rope, current_pos + n);
} }
friend bool operator== friend bool operator==
@ -892,7 +907,7 @@ class rope {
typedef charT value_type; typedef charT value_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef size_t size_type; typedef size_t size_type;
typedef const charT& const_reference; typedef charT const_reference;
typedef const charT* const_pointer; typedef const charT* const_pointer;
typedef __rope_iterator<charT,Alloc> iterator; typedef __rope_iterator<charT,Alloc> iterator;
typedef __rope_const_iterator<charT,Alloc> const_iterator; typedef __rope_const_iterator<charT,Alloc> const_iterator;
@ -945,6 +960,7 @@ class rope {
static charT empty_c_str[1]; static charT empty_c_str[1];
typedef simple_alloc<charT, Alloc> DataAlloc;
typedef simple_alloc<__rope_RopeConcatenation<charT,Alloc>, Alloc> CAlloc; typedef simple_alloc<__rope_RopeConcatenation<charT,Alloc>, Alloc> CAlloc;
typedef simple_alloc<__rope_RopeLeaf<charT,Alloc>, Alloc> LAlloc; typedef simple_alloc<__rope_RopeLeaf<charT,Alloc>, Alloc> LAlloc;
typedef simple_alloc<__rope_RopeFunction<charT,Alloc>, Alloc> FAlloc; typedef simple_alloc<__rope_RopeFunction<charT,Alloc>, Alloc> FAlloc;
@ -1054,8 +1070,7 @@ class rope {
// Adds a trailing NULL for basic char types. // Adds a trailing NULL for basic char types.
static charT * alloc_copy(const charT *s, size_t size) static charT * alloc_copy(const charT *s, size_t size)
{ {
charT * result = (charT *) charT * result = DataAlloc::allocate(rounded_up_size(size));
Alloc::allocate(rounded_up_size(size));
uninitialized_copy_n(s, size, result); uninitialized_copy_n(s, size, result);
__cond_store_eos(result[size]); __cond_store_eos(result[size]);
@ -1073,6 +1088,15 @@ class rope {
// In the nonGC case, it was allocated from Alloc with // In the nonGC case, it was allocated from Alloc with
// rounded_up_size(size). // rounded_up_size(size).
static RopeLeaf * RopeLeaf_from_unowned_char_ptr(const charT *s,
size_t size) {
charT * buf = alloc_copy(s, size);
__STL_TRY
return RopeLeaf_from_char_ptr(buf, size);
__STL_UNWIND(RopeBase::free_string(buf, size))
}
// Concatenation of nonempty strings. // Concatenation of nonempty strings.
// Always builds a concatenation node. // Always builds a concatenation node.
// Rebalances if the result is too deep. // Rebalances if the result is too deep.
@ -1107,24 +1131,14 @@ class rope {
friend struct rope<charT,Alloc>::concat_fn; friend struct rope<charT,Alloc>::concat_fn;
struct concat_fn struct concat_fn
: binary_function<RopeBase *, RopeBase *, RopeBase *> { : binary_function<rope<charT,Alloc>, rope<charT,Alloc>,
RopeBase * operator() (RopeBase * x, RopeBase *y) { rope<charT,Alloc> > {
RopeBase * result; rope operator() (const rope& x, const rope& y) {
x -> ref_nonnil(); return x + y;
y -> ref_nonnil();
__STL_TRY
result = tree_concat(x, y);
# ifndef __GC
result -> refcount = 0;
# endif
__STL_UNWIND(unref(x); unref(y));
return result;
// In the nonGC case, x and y must remain accessible through
// the result. Use of concat could result on a memory leak.
} }
}; };
friend RopeBase* identity_element(concat_fn) { return 0; } friend rope identity_element(concat_fn) { return rope<charT,Alloc>(); }
static size_t char_ptr_len(const charT * s); static size_t char_ptr_len(const charT * s);
// slightly generalized strlen // slightly generalized strlen
@ -1202,7 +1216,7 @@ class rope {
if (0 == len) { if (0 == len) {
tree_ptr = 0; tree_ptr = 0;
} else { } else {
tree_ptr = RopeLeaf_from_char_ptr(alloc_copy(s, len), len); tree_ptr = RopeLeaf_from_unowned_char_ptr(s, len);
# ifndef __GC # ifndef __GC
__stl_assert(1 == tree_ptr -> refcount); __stl_assert(1 == tree_ptr -> refcount);
# endif # endif
@ -1214,7 +1228,7 @@ class rope {
if (0 == len) { if (0 == len) {
tree_ptr = 0; tree_ptr = 0;
} else { } else {
tree_ptr = RopeLeaf_from_char_ptr(alloc_copy(s, len), len); tree_ptr = RopeLeaf_from_unowned_char_ptr(s, len);
} }
} }
@ -1225,7 +1239,7 @@ class rope {
if (0 == len) { if (0 == len) {
tree_ptr = 0; tree_ptr = 0;
} else { } else {
tree_ptr = RopeLeaf_from_char_ptr(alloc_copy(s, len), len); tree_ptr = RopeLeaf_from_unowned_char_ptr(s, len);
} }
} }
@ -1241,10 +1255,12 @@ class rope {
rope(charT c) rope(charT c)
{ {
charT * buf = (charT *)Alloc::allocate(rounded_up_size(1)); charT * buf = DataAlloc::allocate(rounded_up_size(1));
construct(buf, c); construct(buf, c);
tree_ptr = RopeLeaf_from_char_ptr(buf, 1); __STL_TRY
tree_ptr = RopeLeaf_from_char_ptr(buf, 1);
__STL_UNWIND(RopeBase::free_string(buf, 1))
} }
rope(size_t n, charT c); rope(size_t n, charT c);
@ -1258,7 +1274,7 @@ class rope {
tree_ptr = 0; tree_ptr = 0;
} else { } else {
size_t len = j - i; size_t len = j - i;
tree_ptr = RopeLeaf_from_char_ptr(alloc_copy(i, len), len); tree_ptr = RopeLeaf_from_unowned_char_ptr(i, len);
} }
} }
@ -1312,15 +1328,12 @@ class rope {
return fetch(tree_ptr, tree_ptr -> size - 1); return fetch(tree_ptr, tree_ptr -> size - 1);
} }
void push_front(const charT& x) void push_front(charT x)
{ {
RopeBase *old = tree_ptr; RopeBase *old = tree_ptr;
charT *buf = alloc_copy(&x, 1);
RopeBase *left; RopeBase *left;
__STL_TRY left = RopeLeaf_from_unowned_char_ptr(&x, 1);
left = RopeLeaf_from_char_ptr(buf, 1);
__STL_UNWIND(RopeBase::free_string(buf, 1))
__STL_TRY __STL_TRY
tree_ptr = concat(left, tree_ptr); tree_ptr = concat(left, tree_ptr);
unref(old); unref(old);
@ -1436,9 +1449,13 @@ class rope {
// but it's harder to make guarantees. // but it's harder to make guarantees.
} }
# ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
typedef reverse_iterator<const_iterator> const_reverse_iterator;
# else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
typedef reverse_iterator<const_iterator, value_type, const_reference, typedef reverse_iterator<const_iterator, value_type, const_reference,
difference_type> const_reverse_iterator; difference_type> const_reverse_iterator;
# endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
const_reverse_iterator rbegin() const { const_reverse_iterator rbegin() const {
return const_reverse_iterator(end()); return const_reverse_iterator(end());
} }
@ -1794,8 +1811,12 @@ class rope {
return(iterator(this, size())); return(iterator(this, size()));
} }
# ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
typedef reverse_iterator<iterator> reverse_iterator;
# else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
typedef reverse_iterator<iterator, value_type, reference, typedef reverse_iterator<iterator, value_type, reference,
difference_type> reverse_iterator; difference_type> reverse_iterator;
# endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
reverse_iterator mutable_rbegin() { reverse_iterator mutable_rbegin() {
return reverse_iterator(mutable_end()); return reverse_iterator(mutable_end());

View File

@ -11,11 +11,8 @@
* purpose. It is provided "as is" without express or implied warranty. * purpose. It is provided "as is" without express or implied warranty.
*/ */
#if defined(_MSC_VER) # include <stdio.h>
# include <ostream> # include <iostream.h>
#else
# include <iostream.h>
#endif
// Set buf_start, buf_end, and buf_ptr appropriately, filling tmp_buf // Set buf_start, buf_end, and buf_ptr appropriately, filling tmp_buf
// if necessary. Assumes path_end[leaf_index] and leaf_pos are correct. // if necessary. Assumes path_end[leaf_index] and leaf_pos are correct.
@ -330,7 +327,7 @@ inline void __rope_RopeBase<charT,Alloc>::free_c_string()
if (0 != cstr) { if (0 != cstr) {
size_t sz = size + 1; size_t sz = size + 1;
destroy(cstr, cstr + sz); destroy(cstr, cstr + sz);
Alloc::deallocate(cstr, sz); DataAlloc::deallocate(cstr, sz);
} }
} }
@ -340,7 +337,7 @@ inline void __rope_RopeBase<charT,Alloc>::free_string(charT* s, size_t n)
if (!__is_basic_char_type((charT *)0)) { if (!__is_basic_char_type((charT *)0)) {
destroy(s, s + n); destroy(s, s + n);
} }
Alloc::deallocate(s, rounded_up_size(n)); DataAlloc::deallocate(s, rounded_up_size(n));
} }
template <class charT, class Alloc> template <class charT, class Alloc>
@ -413,7 +410,7 @@ rope<charT,Alloc>::leaf_concat_char_iter
{ {
size_t old_len = r -> size; size_t old_len = r -> size;
charT * new_data = (charT *) charT * new_data = (charT *)
Alloc::allocate(rounded_up_size(old_len + len)); DataAlloc::allocate(rounded_up_size(old_len + len));
RopeLeaf * result; RopeLeaf * result;
uninitialized_copy_n(r -> data, old_len, new_data); uninitialized_copy_n(r -> data, old_len, new_data);
@ -459,6 +456,7 @@ rope<charT,Alloc>::destr_leaf_concat_char_iter
#endif #endif
// Assumes left and right are not 0. // Assumes left and right are not 0.
// Does not increment (nor decrement on exception) child reference counts.
// Result has ref count 1. // Result has ref count 1.
template <class charT, class Alloc> template <class charT, class Alloc>
rope<charT,Alloc>::RopeBase * rope<charT,Alloc>::RopeBase *
@ -473,7 +471,7 @@ rope<charT,Alloc>::tree_concat (RopeBase * left, RopeBase * right)
result -> is_balanced = false; result -> is_balanced = false;
result -> size = rsize = left -> size + right -> size; result -> size = rsize = left -> size + right -> size;
if (right -> depth > child_depth) child_depth = right -> depth; if (right -> depth > child_depth) child_depth = right -> depth;
unsigned char depth = child_depth + 1; unsigned char depth = (unsigned char)(child_depth + 1);
result -> depth = depth; result -> depth = depth;
result -> left = left; result -> left = left;
result -> right = right; result -> right = right;
@ -492,7 +490,12 @@ rope<charT,Alloc>::tree_concat (RopeBase * left, RopeBase * right)
&& 1 == balanced -> refcount); && 1 == balanced -> refcount);
} }
# endif # endif
__STL_ALWAYS(result -> unref_nonnil()); result -> unref_nonnil();
__STL_UNWIND(CAlloc::deallocate(result));
// In case of exception, we need to deallocate
// otherwise dangling result node. But caller
// still owns its children. Thus unref is
// inappropriate.
return balanced; return balanced;
} else { } else {
return result; return result;
@ -508,7 +511,7 @@ rope<charT,Alloc>::RopeBase * rope<charT,Alloc>::concat_char_iter
ref(r); ref(r);
return r; return r;
} }
if (0 == r) return RopeLeaf_from_char_ptr(alloc_copy(s, slen), slen); if (0 == r) return RopeLeaf_from_unowned_char_ptr(s, slen);
if (RopeBase::leaf == r -> tag && r -> size + slen <= copy_max) { if (RopeBase::leaf == r -> tag && r -> size + slen <= copy_max) {
result = leaf_concat_char_iter((RopeLeaf *)r, s, slen); result = leaf_concat_char_iter((RopeLeaf *)r, s, slen);
# ifndef __GC # ifndef __GC
@ -521,23 +524,22 @@ rope<charT,Alloc>::RopeBase * rope<charT,Alloc>::concat_char_iter
RopeLeaf *right = (RopeLeaf *)(((RopeConcatenation *)r) -> right); RopeLeaf *right = (RopeLeaf *)(((RopeConcatenation *)r) -> right);
if (right -> size + slen <= copy_max) { if (right -> size + slen <= copy_max) {
RopeBase * left = ((RopeConcatenation *)r) -> left; RopeBase * left = ((RopeConcatenation *)r) -> left;
RopeBase * nright = leaf_concat_char_iter((RopeLeaf *)right, s, slen);
left -> ref_nonnil(); left -> ref_nonnil();
__STL_TRY __STL_TRY
result = tree_concat(left, result = tree_concat(left, nright);
leaf_concat_char_iter((RopeLeaf *)right, __STL_UNWIND(unref(left); unref(nright));
s, slen));
__STL_UNWIND(unref(left));
# ifndef __GC # ifndef __GC
__stl_assert(1 == result -> refcount); __stl_assert(1 == result -> refcount);
# endif # endif
return result; return result;
} }
} }
RopeBase * nright = RopeLeaf_from_unowned_char_ptr(s, slen);
__STL_TRY __STL_TRY
r -> ref_nonnil(); r -> ref_nonnil();
result = tree_concat(r, RopeLeaf_from_char_ptr(alloc_copy(s, slen), result = tree_concat(r, nright);
slen)); __STL_UNWIND(unref(r); unref(nright));
__STL_UNWIND(unref(r));
# ifndef __GC # ifndef __GC
__stl_assert(1 == result -> refcount); __stl_assert(1 == result -> refcount);
# endif # endif
@ -551,7 +553,7 @@ rope<charT,Alloc>::RopeBase * rope<charT,Alloc>
(RopeBase * r, const charT *s, size_t slen) (RopeBase * r, const charT *s, size_t slen)
{ {
RopeBase *result; RopeBase *result;
if (0 == r) return RopeLeaf_from_char_ptr(alloc_copy(s, slen), slen); if (0 == r) return RopeLeaf_from_unowned_char_ptr(s, slen);
size_t count = r -> refcount; size_t count = r -> refcount;
size_t orig_size = r -> size; size_t orig_size = r -> size;
__stl_assert(count >= 1); __stl_assert(count >= 1);
@ -587,11 +589,11 @@ rope<charT,Alloc>::RopeBase * rope<charT,Alloc>
return r; return r;
} }
} }
charT * cpy = alloc_copy(s, slen); RopeBase *right = RopeLeaf_from_unowned_char_ptr(s, slen);
r -> ref_nonnil(); r -> ref_nonnil();
__STL_TRY __STL_TRY
result = tree_concat(r, RopeLeaf_from_char_ptr(cpy, slen)); result = tree_concat(r, right);
__STL_UNWIND(unref(r); RopeBase::free_string(cpy,slen)) __STL_UNWIND(unref(r); unref(right))
__stl_assert(1 == result -> refcount); __stl_assert(1 == result -> refcount);
return result; return result;
} }
@ -629,13 +631,15 @@ rope<charT,Alloc>::concat(RopeBase * left, RopeBase * right)
leftleft -> ref_nonnil(); leftleft -> ref_nonnil();
__STL_TRY __STL_TRY
return(tree_concat(leftleft, rest)); return(tree_concat(leftleft, rest));
__STL_UNWIND(unref(left); unref(rest)) __STL_UNWIND(unref(leftleft); unref(rest))
} }
} }
} }
left -> ref_nonnil(); left -> ref_nonnil();
right -> ref_nonnil(); right -> ref_nonnil();
return(tree_concat(left, right)); __STL_TRY
return(tree_concat(left, right));
__STL_UNWIND(unref(left); unref(right));
} }
template <class charT, class Alloc> template <class charT, class Alloc>
@ -686,21 +690,18 @@ rope<charT,Alloc>::substring(RopeBase * base, size_t start, size_t endp1)
{ {
RopeLeaf * l = (RopeLeaf *)base; RopeLeaf * l = (RopeLeaf *)base;
RopeLeaf * result; RopeLeaf * result;
__GC_CONST charT *section;
size_t result_len; size_t result_len;
if (start >= adj_endp1) return 0; if (start >= adj_endp1) return 0;
result_len = adj_endp1 - start; result_len = adj_endp1 - start;
if (result_len > lazy_threshold) goto lazy; if (result_len > lazy_threshold) goto lazy;
# ifdef __GC # ifdef __GC
section = l -> data + start; const charT *section = l -> data + start;
result = RopeLeaf_from_char_ptr(section, result_len); result = RopeLeaf_from_char_ptr(section, result_len);
result -> c_string = 0; // Not eos terminated. result -> c_string = 0; // Not eos terminated.
# else # else
section = alloc_copy(l -> data + start, result_len);
// We should sometimes create substring node instead. // We should sometimes create substring node instead.
__STL_TRY result = RopeLeaf_from_unowned_char_ptr(
result = RopeLeaf_from_char_ptr(section, result_len); l -> data + start, result_len);
__STL_UNWIND(RopeBase::free_string(section, result_len))
# endif # endif
return result; return result;
} }
@ -730,7 +731,7 @@ rope<charT,Alloc>::substring(RopeBase * base, size_t start, size_t endp1)
if (result_len > lazy_threshold) goto lazy; if (result_len > lazy_threshold) goto lazy;
section = (charT *) section = (charT *)
Alloc::allocate(rounded_up_size(result_len)); DataAlloc::allocate(rounded_up_size(result_len));
__STL_TRY __STL_TRY
(*(f -> fn))(start, result_len, section); (*(f -> fn))(start, result_len, section);
__STL_UNWIND(RopeBase::free_string(section, result_len)); __STL_UNWIND(RopeBase::free_string(section, result_len));
@ -870,12 +871,11 @@ bool rope<charT, Alloc>::apply_to_pieces(
RopeFunction * f = (RopeFunction *)r; RopeFunction * f = (RopeFunction *)r;
size_t len = end - begin; size_t len = end - begin;
bool result; bool result;
charT * buffer = (charT *) charT * buffer = DataAlloc::allocate(len);
Alloc::allocate(len * sizeof(charT));
__STL_TRY __STL_TRY
(*(f -> fn))(begin, end, buffer); (*(f -> fn))(begin, end, buffer);
result = c(buffer, len); result = c(buffer, len);
__STL_ALWAYS(Alloc::deallocate(buffer, len * sizeof(charT))) __STL_ALWAYS(DataAlloc::deallocate(buffer, len))
return result; return result;
} }
default: default:
@ -887,23 +887,23 @@ bool rope<charT, Alloc>::apply_to_pieces(
inline void __rope_fill(ostream& o, size_t n) inline void __rope_fill(ostream& o, size_t n)
{ {
char f = cout.fill(); char f = o.fill();
size_t i; size_t i;
for (i = 0; i < n; i++) o.put(f); for (i = 0; i < n; i++) o.put(f);
} }
template <class charT> inline bool __rope_is_simple(charT *c) { return false; } template <class charT> inline bool __rope_is_simple(charT *) { return false; }
inline bool __rope_is_simple(char * c) { return true; } inline bool __rope_is_simple(char *) { return true; }
inline bool __rope_is_simple(wchar_t * c) { return true; } inline bool __rope_is_simple(wchar_t *) { return true; }
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)
{ {
size_t w = o.width(); size_t w = o.width();
bool left = o.flags() & ios::left; bool left = bool(o.flags() & ios::left);
size_t pad_len; size_t pad_len;
size_t rope_len = r.size(); size_t rope_len = r.size();
__rope_insert_char_consumer<charT> c(o); __rope_insert_char_consumer<charT> c(o);
@ -1084,6 +1084,9 @@ rope<charT,Alloc>::balance(RopeBase *r)
# endif # endif
result = concat(forest[i], result); result = concat(forest[i], result);
forest[i] -> unref_nonnil(); forest[i] -> unref_nonnil();
# if !defined(__GC) && defined(__STL_USE_EXCEPTIONS)
forest[i] = 0;
# endif
} }
__STL_UNWIND(for(i = 0; i <= RopeBase::max_rope_depth; i++) __STL_UNWIND(for(i = 0; i <= RopeBase::max_rope_depth; i++)
unref(forest[i])) unref(forest[i]))
@ -1114,12 +1117,11 @@ template <class charT, class Alloc>
void void
rope<charT,Alloc>::add_leaf_to_forest(RopeBase *r, RopeBase **forest) rope<charT,Alloc>::add_leaf_to_forest(RopeBase *r, RopeBase **forest)
{ {
self_destruct_ptr insertee(r); // included in refcount RopeBase * insertee; // included in refcount
self_destruct_ptr too_tiny(0); // included in refcount RopeBase * too_tiny = 0; // included in refcount
int i; // forest[0..i-1] is empty int i; // forest[0..i-1] is empty
size_t s = insertee -> size; size_t s = r -> size;
ref(r);
for (i = 0; s >= min_len[i+1]/* not this bucket */; ++i) { for (i = 0; s >= min_len[i+1]/* not this bucket */; ++i) {
if (0 != forest[i]) { if (0 != forest[i]) {
# ifndef __GC # ifndef __GC
@ -1132,12 +1134,12 @@ rope<charT,Alloc>::add_leaf_to_forest(RopeBase *r, RopeBase **forest)
} }
{ {
# ifndef __GC # ifndef __GC
self_destruct_ptr old(insertee); self_destruct_ptr old(too_tiny);
# endif # endif
insertee = concat_and_set_balanced(too_tiny, insertee); insertee = concat_and_set_balanced(too_tiny, r);
} }
unref(too_tiny); // too_tiny is dead. // Too_tiny dead, and no longer included in refcount.
too_tiny = 0; // Needed for exception safety. // Insertee is live and included.
__stl_assert(is_almost_balanced(insertee)); __stl_assert(is_almost_balanced(insertee));
__stl_assert(insertee -> depth <= r -> depth + 1); __stl_assert(insertee -> depth <= r -> depth + 1);
for (;; ++i) { for (;; ++i) {
@ -1155,7 +1157,6 @@ rope<charT,Alloc>::add_leaf_to_forest(RopeBase *r, RopeBase **forest)
if (i == RopeBase::max_rope_depth if (i == RopeBase::max_rope_depth
|| insertee -> size < min_len[i+1]) { || insertee -> size < min_len[i+1]) {
forest[i] = insertee; forest[i] = insertee;
insertee = 0;
// refcount is OK since insertee is now dead. // refcount is OK since insertee is now dead.
return; return;
} }
@ -1348,12 +1349,13 @@ __rope_charT_ref_proxy<charT, Alloc>::operator& () const {
template <class charT, class Alloc> template <class charT, class Alloc>
rope<charT, Alloc>::rope(size_t n, charT c) rope<charT, Alloc>::rope(size_t n, charT c)
{ {
RopeBase * result; rope result;
const size_t exponentiate_threshold = 32; const size_t exponentiate_threshold = 32;
size_t exponent; size_t exponent;
size_t rest; size_t rest;
charT *rest_buffer; charT *rest_buffer;
RopeBase * remainder; RopeBase * remainder;
rope remainder_rope;
if (0 == n) { tree_ptr = 0; return; } if (0 == n) { tree_ptr = 0; return; }
exponent = n / exponentiate_threshold; exponent = n / exponentiate_threshold;
@ -1361,53 +1363,42 @@ rope<charT, Alloc>::rope(size_t n, charT c)
if (0 == rest) { if (0 == rest) {
remainder = 0; remainder = 0;
} else { } else {
rest_buffer = (charT *)Alloc::allocate(rounded_up_size(rest)); rest_buffer = DataAlloc::allocate(rounded_up_size(rest));
uninitialized_fill_n(rest_buffer, rest, c); uninitialized_fill_n(rest_buffer, rest, c);
__cond_store_eos(rest_buffer[rest]); __cond_store_eos(rest_buffer[rest]);
__STL_TRY __STL_TRY
remainder = RopeLeaf_from_char_ptr(rest_buffer, rest); remainder = RopeLeaf_from_char_ptr(rest_buffer, rest);
__STL_UNWIND(RopeBase::free_string(rest_buffer, rest)) __STL_UNWIND(RopeBase::free_string(rest_buffer, rest))
} }
__STL_TRY remainder_rope.tree_ptr = remainder;
if (exponent != 0) { if (exponent != 0) {
charT * base_buffer = charT * base_buffer =
(charT *)Alloc::allocate( DataAlloc::allocate(rounded_up_size(exponentiate_threshold));
rounded_up_size(exponentiate_threshold)); RopeLeaf * base_leaf;
self_destruct_ptr base_leaf; rope base_rope;
uninitialized_fill_n(base_buffer, exponentiate_threshold, c); uninitialized_fill_n(base_buffer, exponentiate_threshold, c);
__cond_store_eos(base_buffer[exponentiate_threshold]); __cond_store_eos(base_buffer[exponentiate_threshold]);
__STL_TRY __STL_TRY
base_leaf = RopeLeaf_from_char_ptr(base_buffer, base_leaf = RopeLeaf_from_char_ptr(base_buffer,
exponentiate_threshold); exponentiate_threshold);
__STL_UNWIND(RopeBase::free_string(base_buffer, exponentiate_threshold)) __STL_UNWIND(RopeBase::free_string(base_buffer, exponentiate_threshold))
base_rope.tree_ptr = base_leaf;
if (1 == exponent) { if (1 == exponent) {
result = base_leaf; result = base_rope;
# ifndef __GC # ifndef __GC
__stl_assert(1 == result -> refcount); __stl_assert(1 == result -> tree_ptr -> refcount);
result -> refcount = 2; // will be decremented when base_leaf disappears # endif
# endif
} else { } else {
result = power((RopeBase *)base_leaf, exponent, concat_fn()); result = power(base_rope, exponent, concat_fn());
# ifndef __GC
__stl_assert(0 == result -> refcount);
result -> refcount = 1;
# endif
} }
if (0 != remainder) { if (0 != remainder) {
# ifndef __GC result += remainder_rope;
__stl_assert(1 == remainder -> refcount);
# endif
result = tree_concat(result, remainder);
} }
// All partial results computed by power must be used. } else {
} else { result = remainder_rope;
result = remainder; }
} tree_ptr = result.tree_ptr;
__STL_UNWIND(unref(remainder)); tree_ptr -> ref_nonnil();
# ifndef __GC
__stl_assert(0 == result || 1 == result -> refcount);
# endif
tree_ptr = result;
} }
template<class charT, class Alloc> charT rope<charT,Alloc>::empty_c_str[1]; template<class charT, class Alloc> charT rope<charT,Alloc>::empty_c_str[1];
@ -1427,7 +1418,7 @@ const charT * rope<charT,Alloc>::c_str() const {
__GC_CONST charT * old_c_string = tree_ptr -> c_string; __GC_CONST charT * old_c_string = tree_ptr -> c_string;
if (0 != old_c_string) return(old_c_string); if (0 != old_c_string) return(old_c_string);
size_t s = size(); size_t s = size();
charT * result = (charT *)Alloc::allocate((s + 1)*sizeof(charT)); charT * result = DataAlloc::allocate(s + 1);
flatten(tree_ptr, result); flatten(tree_ptr, result);
result[s] = __eos((charT *)0); result[s] = __eos((charT *)0);
# ifdef __GC # ifdef __GC
@ -1438,7 +1429,7 @@ const charT * rope<charT,Alloc>::c_str() const {
// separately allocated. Deallocate the old copy, since we just // separately allocated. Deallocate the old copy, since we just
// replaced it. // replaced it.
destroy(old_c_string, old_c_string + s + 1); destroy(old_c_string, old_c_string + s + 1);
Alloc::deallocate(old_c_string, s + 1); DataAlloc::deallocate(old_c_string, s + 1);
} }
# endif # endif
return(result); return(result);
@ -1455,7 +1446,7 @@ const charT * rope<charT,Alloc>::replace_with_c_str() {
return(old_c_string); return(old_c_string);
} }
size_t s = size(); size_t s = size();
charT * result = (charT *)Alloc::allocate(rounded_up_size(s)); charT * result = DataAlloc::allocate(rounded_up_size(s));
flatten(tree_ptr, result); flatten(tree_ptr, result);
result[s] = __eos((charT *)0); result[s] = __eos((charT *)0);
tree_ptr -> unref_nonnil(); tree_ptr -> unref_nonnil();

View File

@ -99,24 +99,27 @@ struct __slist_iterator_base
} }
}; };
template <class T, class Ref> template <class T, class Ref, class Ptr>
struct __slist_iterator : public __slist_iterator_base struct __slist_iterator : public __slist_iterator_base
{ {
typedef __slist_iterator<T, T&> iterator; typedef __slist_iterator<T, T&, T*> iterator;
typedef __slist_iterator<T, const T&> const_iterator; typedef __slist_iterator<T, const T&, const T*> const_iterator;
typedef __slist_iterator<T, Ref> self; typedef __slist_iterator<T, Ref, Ptr> self;
typedef T value_type; typedef T value_type;
typedef value_type* pointer; typedef Ptr pointer;
typedef value_type& reference; typedef Ref reference;
typedef const value_type& const_reference;
typedef __slist_node<T> list_node; typedef __slist_node<T> list_node;
__slist_iterator(list_node* x) : __slist_iterator_base(x) {} __slist_iterator(list_node* x) : __slist_iterator_base(x) {}
__slist_iterator() : __slist_iterator_base(0) {} __slist_iterator() : __slist_iterator_base(0) {}
__slist_iterator(const iterator& x) : __slist_iterator_base(x.node) {} __slist_iterator(const iterator& x) : __slist_iterator_base(x.node) {}
Ref operator*() const { return ((list_node*) node)->data; } reference operator*() const { return ((list_node*) node)->data; }
#ifndef __SGI_STL_NO_ARROW_OPERATOR
pointer operator->() const { return &(operator*()); }
#endif /* __SGI_STL_NO_ARROW_OPERATOR */
self& operator++() self& operator++()
{ {
incr(); incr();
@ -130,6 +133,8 @@ struct __slist_iterator : public __slist_iterator_base
} }
}; };
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
inline ptrdiff_t* inline ptrdiff_t*
distance_type(const __slist_iterator_base&) distance_type(const __slist_iterator_base&)
{ {
@ -142,12 +147,14 @@ iterator_category(const __slist_iterator_base&)
return forward_iterator_tag(); return forward_iterator_tag();
} }
template <class T, class Ref> template <class T, class Ref, class Ptr>
inline T* inline T*
value_type(const __slist_iterator<T, Ref>&) { value_type(const __slist_iterator<T, Ref, Ptr>&) {
return 0; return 0;
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
inline size_t __slist_size(__slist_node_base* node) inline size_t __slist_size(__slist_node_base* node)
{ {
size_t result = 0; size_t result = 0;
@ -167,8 +174,8 @@ public:
typedef size_t size_type; typedef size_t size_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef __slist_iterator<T, reference> iterator; typedef __slist_iterator<T, T&, T*> iterator;
typedef __slist_iterator<T, const_reference> const_iterator; typedef __slist_iterator<T, const T&, const T*> const_iterator;
private: private:
typedef __slist_node<T> list_node; typedef __slist_node<T> list_node;

View File

@ -47,14 +47,16 @@
// (9) Defines __STL_NON_TYPE_TMPL_PARAM_BUG if the compiler has // (9) Defines __STL_NON_TYPE_TMPL_PARAM_BUG if the compiler has
// trouble performing function template argument deduction for // trouble performing function template argument deduction for
// non-type template parameters. // non-type template parameters.
// (10) Defines __STL_USE_EXCEPTIONS if the compiler (in the current // (10) Defines __SGI_STL_NO_ARROW_OPERATOR if the compiler is unable
// compilation mode) supports exceptions. // to support the -> operator for iterators.
// (11) Defines __STL_SGI_THREADS if this is being compiled on an SGI // (11) Defines __STL_USE_EXCEPTIONS if the compiler (in the current
// compiler, and if the user hasn't selected pthreads or no threads // compilation mode) supports exceptions.
// instead. // (12) Defines __STL_SGI_THREADS if this is being compiled on an SGI
// (12) Defines __STL_WIN32THREADS if this is being compiled on a // compiler, and if the user hasn't selected pthreads or no threads
// instead.
// (13) Defines __STL_WIN32THREADS if this is being compiled on a
// WIN32 compiler in multithreaded mode. // WIN32 compiler in multithreaded mode.
// (13) Defines __stl_assert either as a test or as a null macro, // (14) Defines __stl_assert either as a test or as a null macro,
// depending on whether or not __STL_ASSERTIONS is defined. // depending on whether or not __STL_ASSERTIONS is defined.
# if defined(__sgi) && !defined(__GNUC__) # if defined(__sgi) && !defined(__GNUC__)
@ -120,6 +122,7 @@
# define __STL_NEED_EXPLICIT # define __STL_NEED_EXPLICIT
# endif # endif
# define __STL_NON_TYPE_TMPL_PARAM_BUG # define __STL_NON_TYPE_TMPL_PARAM_BUG
# define __SGI_STL_NO_ARROW_OPERATOR
# ifdef _CPPUNWIND # ifdef _CPPUNWIND
# define __STL_USE_EXCEPTIONS # define __STL_USE_EXCEPTIONS
# endif # endif
@ -132,6 +135,7 @@
# define __STL_NO_DRAND48 # define __STL_NO_DRAND48
# define __STL_NEED_TYPENAME # define __STL_NEED_TYPENAME
# define __STL_LIMITED_DEFAULT_TEMPLATES # define __STL_LIMITED_DEFAULT_TEMPLATES
# define __SGI_STL_NO_ARROW_OPERATOR
# define __STL_NON_TYPE_TMPL_PARAM_BUG # define __STL_NON_TYPE_TMPL_PARAM_BUG
# ifdef _CPPUNWIND # ifdef _CPPUNWIND
# define __STL_USE_EXCEPTIONS # define __STL_USE_EXCEPTIONS

View File

@ -137,23 +137,25 @@ struct __rb_tree_base_iterator
} }
}; };
template <class Value, class Ref> template <class Value, class Ref, class Ptr>
struct __rb_tree_iterator : public __rb_tree_base_iterator struct __rb_tree_iterator : public __rb_tree_base_iterator
{ {
typedef Value value_type; typedef Value value_type;
typedef Value& reference; typedef Value& reference;
typedef const Value& const_reference;
typedef Value* pointer; typedef Value* pointer;
typedef __rb_tree_iterator<Value, reference> iterator; typedef __rb_tree_iterator<Value, Value&, Value*> iterator;
typedef __rb_tree_iterator<Value, const_reference> const_iterator; typedef __rb_tree_iterator<Value, const Value&, const Value*> const_iterator;
typedef __rb_tree_iterator<Value, Ref> self; typedef __rb_tree_iterator<Value, Ref, Ptr> self;
typedef __rb_tree_node<Value>* link_type; typedef __rb_tree_node<Value>* link_type;
__rb_tree_iterator() {} __rb_tree_iterator() {}
__rb_tree_iterator(link_type x) { node = x; } __rb_tree_iterator(link_type x) { node = x; }
__rb_tree_iterator(const iterator& it) { node = it.node; } __rb_tree_iterator(const iterator& it) { node = it.node; }
Ref operator*() const { return link_type(node)->value_field; } reference operator*() const { return link_type(node)->value_field; }
#ifndef __SGI_STL_NO_ARROW_OPERATOR
pointer operator->() const { return &(operator*()); }
#endif /* __SGI_STL_NO_ARROW_OPERATOR */
self& operator++() { increment(); return *this; } self& operator++() { increment(); return *this; }
self operator++(int) { self operator++(int) {
@ -180,6 +182,8 @@ inline bool operator!=(const __rb_tree_base_iterator& x,
return x.node != y.node; return x.node != y.node;
} }
#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
inline bidirectional_iterator_tag inline bidirectional_iterator_tag
iterator_category(const __rb_tree_base_iterator&) { iterator_category(const __rb_tree_base_iterator&) {
return bidirectional_iterator_tag(); return bidirectional_iterator_tag();
@ -190,11 +194,13 @@ distance_type(const __rb_tree_base_iterator&) {
return (__rb_tree_base_iterator::difference_type*) 0; return (__rb_tree_base_iterator::difference_type*) 0;
} }
template <class Value, class Ref> template <class Value, class Ref, class Ptr>
inline Value* value_type(const __rb_tree_iterator<Value, Ref>&) { inline Value* value_type(const __rb_tree_iterator<Value, Ref, Ptr>&) {
return (Value*) 0; return (Value*) 0;
} }
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
inline void inline void
__rb_tree_rotate_left(__rb_tree_node_base* x, __rb_tree_node_base*& root) __rb_tree_rotate_left(__rb_tree_node_base* x, __rb_tree_node_base*& root)
{ {
@ -487,15 +493,21 @@ protected:
} }
public: public:
typedef __rb_tree_iterator<value_type, reference> iterator; typedef __rb_tree_iterator<value_type, reference, pointer> iterator;
typedef __rb_tree_iterator<value_type, const_reference> const_iterator; typedef __rb_tree_iterator<value_type, const_reference, const_pointer>
const_iterator;
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
typedef reverse_bidirectional_iterator<iterator, value_type, reference, typedef reverse_bidirectional_iterator<iterator, value_type, reference,
difference_type> difference_type>
reverse_iterator; reverse_iterator;
typedef reverse_bidirectional_iterator<const_iterator, value_type, typedef reverse_bidirectional_iterator<const_iterator, value_type,
const_reference, difference_type> const_reference, difference_type>
const_reverse_iterator; const_reverse_iterator;
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
private: private:
iterator __insert(base_ptr x, base_ptr y, const value_type& v); iterator __insert(base_ptr x, base_ptr y, const value_type& v);
link_type __copy(link_type x, link_type p); link_type __copy(link_type x, link_type p);

View File

@ -42,10 +42,16 @@ public:
typedef const value_type& const_reference; typedef const value_type& const_reference;
typedef size_t size_type; typedef size_t size_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
typedef reverse_iterator<const_iterator, value_type, const_reference, typedef reverse_iterator<const_iterator, value_type, const_reference,
difference_type> const_reverse_iterator; difference_type> const_reverse_iterator;
typedef reverse_iterator<iterator, value_type, reference, difference_type> typedef reverse_iterator<iterator, value_type, reference, difference_type>
reverse_iterator; reverse_iterator;
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
protected: protected:
typedef simple_alloc<value_type, Alloc> data_allocator; typedef simple_alloc<value_type, Alloc> data_allocator;
iterator start; iterator start;
@ -256,20 +262,6 @@ protected:
end_of_storage = finish; end_of_storage = finish;
} }
template <class BidirectionalIterator>
void range_initialize(BidirectionalIterator first,
BidirectionalIterator last,
bidirectional_iterator_tag) {
range_initialize(first, last, forward_iterator_tag());
}
template <class RandomAccessIterator>
void range_initialize(RandomAccessIterator first,
RandomAccessIterator last,
random_access_iterator_tag) {
range_initialize(first, last, forward_iterator_tag());
}
template <class InputIterator> template <class InputIterator>
void range_insert(iterator pos, void range_insert(iterator pos,
InputIterator first, InputIterator last, InputIterator first, InputIterator last,
@ -280,19 +272,6 @@ protected:
ForwardIterator first, ForwardIterator last, ForwardIterator first, ForwardIterator last,
forward_iterator_tag); forward_iterator_tag);
template <class BidirectionalIterator>
void range_insert(iterator pos,
BidirectionalIterator first, BidirectionalIterator last,
bidirectional_iterator_tag) {
range_insert(pos, first, last, forward_iterator_tag());
}
template <class RandomAccessIterator>
void range_insert(iterator pos,
RandomAccessIterator first, RandomAccessIterator last,
random_access_iterator_tag) {
range_insert(pos, first, last, forward_iterator_tag());
}
#endif /* __STL_MEMBER_TEMPLATES */ #endif /* __STL_MEMBER_TEMPLATES */
}; };