BCB VECTOR source code (reference learning)

xiaoxiao2021-03-06  61

This is a header file ~~~~~~~~~~~~~~~~~

#ifndef __vector_h # define __vector_h # Pragma Option Push -b -A8 -PC -VX- -VE - -A- -W-INL-W-AUS -W-SIG / / - * - C - * - / *** *********************************************************** ********************** * * Vector - Declarations for the standard library vector class * **************** *********************************************************** ********* * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. It is provided " AS IS

WITHOUT Express or Implied Warranty. * * *********************************************************** ******************************** * * Copyright (C) 1994-1999 Rogue Wave Software, Inc. All Rights Reserved. * * This computer software is owned by Rogue Wave Software, Inc. and is * protected by US copyright laws and other laws and by international * treaties. This computer software is furnished by Rogue Wave Software, * Inc. pursuant to a written license agreement and may be used, copied, * transmitted, and stored only in accordance with the terms of such * license and with the inclusion of the above copyright notice. This * computer software or any other copies thereof may not be provided or * otherwise made available to any other person. * * US Government Restricted Rights. This computer software is provided * with Restricted Rights. Use, duplication, or disclosure by the * Government is subject to restrictions as set forth in subparagraph (c) * (1) (ii) of the rights in Technical Data and C omputer Software clause * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the * Commercial Computer Software? Restricted Rights at 48 CFR 52.227-19, * as applicable. Manufacturer is Rogue Wave Software, Inc., 5500 * flatiron Parkway, Boulder, Colorado 80301 USA. * ************************************************* ********************************************** / # ifndef __STD_Vector __ # define __std_vector__

#include #include #include

#include #include #include #include

#ifndef Vector # define Vector Vector # Endif

#ifndef _RWSTD_NO_NAMESPACENAMESPACE STD {#ENDIF

//// Note That _RWSTD_COMPLEX_DEFAULT (X) // WILL Expand to: '= x', or nothing, // depending on your compiler's capabilities and / or // flag settings (see stdcomp.h) .// Template )> class vector {private: #if defined (_RWSTD_ALLOCATOR) && defined (_HPACC_) typedef _TYPENAME Allocator :: template rebind :: other __value_alloc_type; #else typedef allocator_interface __Value_alloc_type; #ENDIF

Public: // // Types. // Typedef T value_type; typef allocator allocator_type;

#ifndef _RWSTD_NO_COMPLICATED_TYPEDEF typedef _TYPENAME _RWSTD_ALLOC_SIZE_TYPE size_type; typedef _TYPENAME _RWSTD_ALLOC_DIFF_TYPE difference_type; typedef _TYPENAME __value_alloc_type :: pointer iterator; typedef _TYPENAME __value_alloc_type :: const_pointer const_iterator; typedef _TYPENAME __value_alloc_type :: reference reference; typedef _TYPENAME __value_alloc_type :: const_reference const_reference; typedef _TYPENAME __value_alloc_type :: pointer pointer; typedef _TYPENAME __value_alloc_type :: const_pointer const_pointer; #else typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T * iterator; typedef const T * const_iterator; typedef T & reference; typedef const T & const_reference; typedef T * pointer; typedef const T * const_pointer; #endif // _ rwstd_no_complicated_typedef

#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC typedef _RW_STD :: reverse_iterator const_reverse_iterator; typedef _RW_STD :: reverse_iterator reverse_iterator; #else typedef _RW_STD :: reverse_iterator const_reverse_iterator; typedef _RW_STD :: reverse_iterator Reverse_iterator; #ENDIFPROTECTED:

Size_type __buffer_size; itrator __start; itrator __finish; __rwstd :: __ rw_basis __end_of_storage;

void __insert_aux (iterator position, const T & x); void __insert_aux (iterator position, size_type n, const T & x); # ifndef _RWSTD_NO_MEMBER_TEMPLATES template void __insert_aux (iterator position, InputIterator first, InputIterator last, _RW_is_not_integer) {__insert_aux2 ( position, first, last);} template void __insert_aux (iterator position, InputIterator first, InputIterator last, _RW_is_integer) {__insert_aux (position, (size_type) first, last);} template void __insert_aux2 (iterator Position, inputiterator first, input); # else void __insert_aux2 (item position, const_iterator first, const_iterator last); # itif

Void __destroy (iterator start, iterator finish {while (start! = finish) __value_alloc_type (__ end_of_storage) .destroy (Start );}

// // Allocate buffers and fill with n values ​​// void __initn (size_type n, const T & value) {__init (); __start = __value_alloc_type (__ end_of_storage) .allocate (n, 0); # ifndef _RWSTD_NO_EXCEPTIONS try {uninitialized_fill_n (__ start , n, value);} catch (...) {__value_alloc_type (__ end_of_storage) .deallocate (__ start, n); throw;} #else uninitialized_fill_n (__ start, n, value); # endif // _RWSTD_NO_EXCEPTIONS __finish = __start n ; __end_of_storage = __finish;} void __init () {__buffer_size = max ((size_type) 1, __ RWSTD :: __ rw_allocation_size ((value_type *) 0, (size_type) 0, (size_type) 0));} public: // // Construct / COPY / DESTROY / / / _EXPLICIT VECTOR (const allocator& alloc _rwstd_default_arg (allocator ())): __start (0), __finish (0), __end_of_storage (0, alloc) {__init ();}

#ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS Vector: __start (0), __finish (0), __end_of_storage (0, allocator ()) {;

Vector (size_type n, const t & value): __start (0), __finish (0), __end_of_storage (0, allocator ()) {__initn (n, value);} #ENDIF

_EXPLICIT VECTOR (size_type n): __start (0), __Finish (0), __end_of_storage (0, allocator ()) {t value = t (); __initn (n, value);}

#ifndef _RWSTD_NO_MEMBER_TEMPLATES

template void __init_aux (InputIterator first, InputIterator last, _RW_is_not_integer) {if (__is_input_iterator (__ iterator_category (first))) {copy (first, last, back_inserter (* this));} else {size_type n; __init () ; __initialize (n, size_type (0)); distance (first, last, n); __start = __value_alloc_type (__ end_of_storage) .allocate (n, 0); # ifndef _RWSTD_NO_EXCEPTIONS try {__finish = uninitialized_copy (first, last, __start); } catch (...) {__value_alloc_type (__ end_of_storage) .deallocate (__ start, n); throw;} #else __finish = uninitialized_copy (first, last, __start); # endif // _RWSTD_NO_EXCEPTIONS __end_of_storage = __finish;}} template void __init_aux (InputIterator first, InputIterator last, _RW_is_integer) {__initn ((size_type) first, last);} template vector (InputIterator first, InputIterator last, const Allocator & alloc _RWSTD_DEFAULT_ARG (Allocator ())): __start (0) , __Finish (0), __end_of_storage (0, alloc) {typedef _TYPENAME _RWdispatch :: _ RWtype _RWtype; __init_aux (first, last, _RWtype ());} vector (size_type n, const T & value, const Allocator & alloc _RWSTD_DEFAULT_ARG ( ALLOCATOR ()): __start (0), __finish (0), __end_of_storage (0, alloc) {__INITN ((size_type) n, value);} #else // / b v} #} #} #} #} to copy of value // vector (size_type n, const T & value, const Allocator & alloc _RWSTD_DEFAULT_ARG (Allocator ())):. __start (0), __finish (0), __end_of_storage (0, alloc) {__initn (n, value) }

vector (const_iterator first, const_iterator last, const Allocator & alloc _RWSTD_DEFAULT_ARG (Allocator ())): __start (0), __finish (0), __end_of_storage (0, alloc) {size_type n; __init (); __initialize (n, size_type (0 )); distance (first, last, n); __start = __value_alloc_type (__ end_of_storage) .allocate (n, 0); # ifndef _RWSTD_NO_EXCEPTIONS try {__finish = uninitialized_copy (first, last, __start);} catch (...) { __value_alloc_type (__ end_of_storage) .deallocate (__ start, n); throw;} #else __finish = uninitialized_copy (first, last, __start); # endif // _RWSTD_NO_EXCEPTIONS __end_of_storage = __finish;} #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS vector (const_iterator first, const_iterator last): __start (0), __Finish (0), __end_of_storage (0, allocator ()) {size_type n; __init (); __initialize (n, size_type (0)); Distance (first, last, n); __start = __Value_alloc_type (__ end_of_s torage) .allocate (n, 0); # ifndef _RWSTD_NO_EXCEPTIONS try {__finish = uninitialized_copy (first, last, __start);} catch (...) {__value_alloc_type (__ end_of_storage) .deallocate (__ start, n); throw;} # else __finish = uninitialized_copy (first, last, __start); # endif // _RWSTD_NO_EXCEPTIONS __end_of_storage = __finish;} #endif // _RWSTD_NO_DEFAULT_TEMPLATE_ARGS # endif // _RWSTD_NO_MEMBER_TEMPLATES

Vector (Const Vector & X): __start (0), __Finish (0), __end_of_storage (0, x.get_allocator ()) {__init (); __start = __Value_alloc_type (__ end_of_storage). alocate (x.end () - x.begin (), 0); __finish = uninitialized_copy (x.begin (), x.end (), __start); __end_of_staRage = __Finish;} ~ Vector () {__DESTROY (__ start, __finish); __Value_alloc_type __END_OF_Storage) .deallocate (__ start, __ end_of_storage.data () -__ start);}

Vector & operator = (const vector & x);

#ifndef _RWSTD_NO_MEMBER_TEMPLATES template void assign (InputIterator first, InputIterator last) {erase (begin (), end ()); typedef _TYPENAME _RWdispatch :: _ RWtype _RWtype; __insert_aux (begin (), first, last, _RWTYPE ());} Void Assign (SIZE_TYPE N, Const T & T) {ERAS (begin (), end ()); INSERT (Begin (), N, T);} #else void Assign (const_iterator first, const_iterator Last ) {ERAS (Begin (), INSERT (Begin (), first, last);} /// Assign N copies of t to this vector. // void assign (size_type n, const t & t) {ERASE (Begin (), INSERT (Begin (), N, T);} #ENDIF / / _RWSTD_NO_MEMBER_TEMPLATES

Allocator_type get_allocator () const {return (allocator_type) __ end_of_storage;}

// // ipurin () {return __start;} const_iterator begin () const {return __start;} iterator end () {return__finish;} const_iterator end () const {return__finish;}

reverse_iterator rbegin () {reverse_iterator tmp (end ()); return tmp;} const_reverse_iterator rbegin () const {const_reverse_iterator tmp (end ()); return tmp;} reverse_iterator rend () {reverse_iterator tmp (begin ()); return tmp ;} const_reverse_iterator rend () const {const_reverse_iterator tmp (begin ()); return tmp;} // // Capacity // size_type size () const {return size_type (end () - begin ());.} size_type max_size ( Const {RETURN __VALUE_ALLOC_TYPE (__ End_Of_Storage) .max_size ();} void resize; void resize (size_type new_size, t value);

size_type capacity () const {return size_type (__ end_of_storage.data () - begin ());} bool empty () const {return begin () == end ();} void reserve (size_type n) {_RWSTD_THROW (n> max_size (), length_error, __rwstd :: eXcept_msg_string (__ rwstd :: __ rwse_invalidsizeparam, "Vector :: RESERVE (SIZE_T)", N, Max_Size ()). msgstr ());

if (capacity () = size (), out_of_range, __RWSTD :: except_msg_string (__ RWSTD :: rwse_OutOfRange, "vector: : operator [] (size_t) ", n, size ()). msgstr ()); # endif return * Begin () n);

} Const_reference operator [] (size_type n) const {#ifdef _RWSTD_BOUNDS_CHECKING _RWSTD_THROW (n> = size (), out_of_range, __RWSTD :: except_msg_string (__ RWSTD :: rwse_OutOfRange, "vector :: operator [] (size_t) const", n, . size ()) msgstr ()); # endif return * (begin () n);} reference at (size_type n) {_RWSTD_THROW (n> = size (), out_of_range, __RWSTD :: except_msg_string (__ RWSTD :: rwse_OutOfRange "Vector :: at (size_t)", n, size ()); msgstr ()); return * (begin () n);} const_reference at (size_type n) const {_rwstd_throw (n> = size () , out_of_range, __rwstd :: eXcept_msg_string (__ rwstd :: rwse_outofrange, "vector :: at (size_t) const", n, size ()). msgstr ()); returnity * (begin () n);} Reference Front ) {RETURN * begin ();} const_reference front () const {return * begin ();} refrence back () { RETURN * (end () - 1);} const_reference back () const {return * (end () - 1);} ///Modifiers. // void push_back (const t & x) {ix (__finish! = __END_OF_Storage .data ()) {__value_alloc_type (__ end_of_storage) .construct (__ finish, x); __finish ;} else __insert_aux (end (), x);} void pop_back () {--__ finish; __value_alloc_type (__ end_of_storage) .destroy (__ finish) }

// // Itert x at position. // iposition, const t & x) {size_type n = position - begin (); if (__finish! = __END_OF_STORAGE.DATA () && position == end ()) { __value_alloc_type (__ end_of_storage) .construct (__ finish, x); __finish ;} else __insert_aux (position, x); return begin () n;} #ifndef _RWSTD_NO_MEMBER_TEMPLATES template void insert (iterator position, InputIterator first, InputIterator last ) {typedef _TYPENAME _RWdispatch :: _ RWtype _RWtype; __insert_aux (position, first, last, _RWtype ());} void insert (iterator position, size_type n, const T & value) {__insert_aux (position, n, value); } #else void insert (iterator position, size_type n, const T & x) {__insert_aux (position, n, x);} void insert (iterator position, const_iterator first, const_iterator last) {__insert_aux2 (position, first, last);} #endif // _RW STD_NO_MEMBER_TEMPLATES

Iterator erase {if (position 1! = end ()) COPY (Position 1, end (), position; --__ finish; __value_alloc_type (__ end_storage) .destroy (__ finish); return position;} itemator ERASE (Iterator First, Iterator Last) {Iterator I = Copy (Last, End (), First); Iterator TMP = __finish; __finish = __finish - (Last - First); __DESTROY (I, TMP); Return First;}

void swap (vector & x) {if ((allocator_type) __ end_of_storage == (allocator_type) x .__ end_of_storage) {#ifndef _RWSTD_NO_NAMESPACE std :: swap (__ start, x .__ start); std :: swap (__ finish , X.__ Finish; std :: swap (_); x .__ end_of_storage); # else :: swap (__ start, x .__ start); :: swap (__ finish, x .__ finish); :: swap (__ end_of_storage, x. __END_OF_STORAGE); # ENDIF / / _RWSTD_NO_NAMESPACE} else {Vector _x = * this; * this = x; x = _x;}} void clear () {ERASE (begin (), end ());}

#ifndef _RWSTD_STRICT_ANSI // Non-standard function for setting buffer allocation size size_type allocation_size () {return __buffer_size;} size_type allocation_size (size_type new_size) {size_type tmp = __buffer_size; __buffer_size = max ((size_type) 1, new_size); return tmp; } #ENDIF / / _RWSTD_STRICT_ANSI};

Template Inline Bool Operator == (Const Vector & x, Const Vector & Y) {Return X.Size () == Y.Size () && equal (x.egin (), x.end (), y.begin ());

Template Inline Bool Operator <(Const Vector & x, Const Vector & Y) {Return Lexicographical_Compare (x.begin (), x.end (), y .begin (), y.end ());

#if! defined (_RWSTD_NO_NAMESPACE) ||! defined (_RWSTD_NO_PART_SPEC_OVERLOAD) template inline bool operator! = (const vector & x, const vector & y) {return ! (x == y);

Template Inline Bool Operator> (Const Vector & x, Const Vector & Y) {Return Y Inline Bool Operator> = (const vector & x, const vector> & y) {return! (x

Template Inline Bool Operator <= (Const Vector & X, Const Vector & Y) {Return! (Y

Template Inline Void Swap (Vector & A, Vector & b) {a.swap (b);} #ENDIF / /! Defined (_RWSTD_NO_NAMESPACE || ! defined (_RWSTD_NO_PART_SPEC_OVERLOAD) #if Defined (_RWSTD_NO_TEMPLATE_REPOSTORY) && Defined (__borlandc__) && (__turboc__ <0x540) #ifndef _rwstd_no_namespace} #ENDIF

#include

#ifndef _RWSTD_NO_NAMESPACENAMESPACE STD {#ENDIF

#ENDIF / / (_RWSTD_NO_TEMPLATE_REPOSTORY) && Defined (__borlandc__)

//// if Bool Is a Builtin Type, We provide a vector Specialization.// We do not this specialization.//#ifNDEF _RWSTD_NO_BOOL

#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC

Template Class _RWSTDEXPORT Vector {

#ELSE

// Use a macro to mutate allocator into allocator #define allocator allocator

_RWSTD_TEMPLATE _RWSTDEXPORT Vector > {

#ENDIF / / _RWSTD_NO_CLASS_PARTIAL_SPEC

public: // // types // typedef Allocator allocator_type; typedef bool value_type; private:! #if defined (_RWSTD_ALLOCATOR) && defined (_HPACC _) # ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC typedef _TYPENAME allocator_type :: template rebind :: other __value_alloc_type; #else typedef allocator_type :: template rebind :: other __value_alloc_type; # endif # else typedef allocator_interface __value_alloc_type; #endif

public: #ifdef _RWSTD_NO_EMBEDDED_TYPEDEF typedef allocator :: size_type size_type; typedef allocator :: difference_type difference_type; # else # ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC typedef allocator_type :: size_type size_type; typedef allocator_type :: difference_type difference_type; #else typedef _TYPENAME allocator_type: : size_type size_type; typedef _typename allocator_type :: Difference_type Difference_type; # Endif # ENDIF

protected: #ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC typedef __value_alloc_type :: pointer pointer; typedef __value_alloc_type :: const_pointer const_pointer; #else typedef _TYPENAME __value_alloc_type :: pointer pointer; typedef _TYPENAME __value_alloc_type :: const_pointer const_pointer; #endif

PUBLIC:

///////. '

// // bit reference // class reference {friend class iterator; friend class const_iterator; protected: unsigned int * p; unsigned int mask; reference (unsigned int * x, unsigned int y): p (x), mask (y ) {} Public: Reference (): p (0), Mask (0) {} Operator Bool () const {return! (! (* P & mask));} Reference & Operator = (BOOL X) {IF (x * P | = mask; else * p & = ~ mask; return * this;} Reference & operator = (const reference) {RETURN * this = BOOL (x);} #ifndef _rwstd_strict_ansi bool operator == (Const Reference & X ) const {return bool (* this) == BOOL (X);} Bool Operator <(const reference & x) const {#if! defined (_msc_ver) || defined (__ borlandc__) Return Bool (* this) (cons) T Reference & X) const {return x <* this;} Bool Operator> = (const reference & x) const {return! (* this x);} #ENDIF / / _RWSTD_STRICT_ANSI

void flip () {* p ^ = mask;}}; typedef bool const_reference; // // Definition of our iterator // class iterator:. public _RW_STD :: iterator {# IF! defined (_rwstd_no_class_partial_spec) Friend Class Vector ; # Else Friend Class Vector >; # Endif Friend Class Const_ITerator; protected:

Unsigned int * p; unsigned int offset

Void __bump_up () {if (Offset == _RWSTD_WORD_BIT - 1) {OFFSET = 0; P;}} void __bump_down ()} void __bump_down () {= _rwstd_word_bit - 1; --P; }

PUBLIC: Iterator (): p (0), Offset (0) {} Iterator (unsigned int * x, unsigned int y): p (x), offset (y) {}

Reference Operator * () const {return reference (p, 1u << Offset); {__Bump_UP (); return * this;} {Iterator TMP = * this; __bump_up (); RETURN tmp;} iterator & operator-- () {__bump_down (); return * this;} iterator operator-- (int) {iterator tmp = * this; __bump_down (); return tmp;} iterator & operator = (difference_type i) {difference_type n = i offset; p = n / _rwstd_word_bit; n = n% _RWSTD_WORD_bit; if (n <0) {offset = n _rwstd_word_bit; --p;} else offset = n; return * this;} iterator & operator = (difference_type i) {* this = -i; return * this;} iterator operator (difference_type i) const {iterator tmp = * this; return tmp = i;} iterator operator- (difference_type i) const {iterator t MP = * this; return tmp - = i;} Difference_Type Operator- (item x) const {return _RWSTD_WORD_BIT * (P - XP) Offset - x.offset;} Reference Operator [] (Difference_Type i) {Return * (* THIS I);} Bool Operator == (Const Iterator & X) Const {Return P == XP && Offset == x.offset;} BOOL Operator <(const itrator & x) const {return P

x) const {return! (* this == x);} Bool Operator> (const itrator & x) const {return x <* this;} Bool Operator> = (const itrator & x) const {return! (* this x);}}; // // definition of out_iterator: public _rw_std :: itemage {#if defined (_RWSTD_NO_CLASS_PARTIAL_SPEC) friend class vector ; # else friend class vector >; # endifprotected!:

Unsigned int * p; unsigned int offset; void __bump_up () {if (Offset == _RWSTD_WORD_BIT - 1) {OFFSET = 0; P;}} void __bump_down ()} void __bump_down ()}} VOID __BUMP_DOWN ()} VOID __Bump_Down ()} = _RWSTD_WORD_BIT - 1; --P;}}

Public: const_iterator (): p (0), offset (0) {} const_iterator (unsigned int * x, unsigned int y): p (x), offset (y) {} #if! defined (_msc_ver) || defined (__BORLANDC __) # ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC const_iterator (const vector :: iterator & x): p (xp), offset (x.offset) {} #else const_iterator (const _TYPENAME vector :: iterator & x : p (xp), offset (x.offset) {} # Endif # Else const_iterator (const itrator & x): p (xp), offset (x.offset) {} #ENDIF const_reference Operator * () const {return vector :: reference (p, 1U << offset);} const_iterator & operator () {__bump_up (); return * this;} const_iterator operator (int) {const_iterator tmp = * this; __bump_up (); return tmp Const_iterator & operator - () {__bump_down (); return * this;} const_iterator operator - (int) {const_iterator tmp = * this; __bump_down (); return t mp;} const_iterator & operator = (difference_type i) {difference_type n = i offset; p = n / _RWSTD_WORD_BIT; n = n% _RWSTD_WORD_BIT; if (n <0) {offset = n _RWSTD_WORD_BIT; --p;} else offset = n; return * this;} const_iterator & operator- = (difference_type i) {* this = -i; return * this;} const_iterator operator (difference_type i) const {const_iterator tmp = * this; return tmp = i ;

} Const_iterator operator- (difference_type i) const {const_iterator tmp = * this; return tmp - = i;} difference_type operator- (const_iterator x) const {return _RWSTD_WORD_BIT * (p - xp) offset - x.offset;} const_reference operator [] (DIFEERENCE_TYPE I) {RETURN * (* this i);} Bool Operator == (const const_iterator & x) const {return p == xp && offset == x.offset;} BOOL Operator <(const const_iterator & x) Const {RETURN P (Const Const_Iterator & x) const {return x <* this;} Bool Operator> = (const const_iterator & x) const {return! (* this x) Const {Return! (* this> x );}}; // // Types // # IFN def _RWSTD_NO_CLASS_PARTIAL_SPEC typedef _RW_STD :: reverse_iterator const_reverse_iterator; typedef _RW_STD :: reverse_iterator reverse_iterator; #else typedef _RW_STD :: reverse_iterator const_reverse_iterator; typedef _RW_STD :: reverse_iterator < Iterator, random_access_iterator_tag, value_type, reference, pointer, Difference_Type> Reverse_Iuterator; #ENDIF

private: // // These private functions are replicas of generic algorithms // We provide them here to avoid putting instantiations of // the generic algorithms into an archive or shared library // This gives you full flexibilty in deciding where you want.. . // to put particular instantiations of the generic // algorithms // void __fill (iterator first, iterator last, const bool & value) {while (first = last!) * first = value;} void __fill_n (iterator first, size_type n , const bool & value) {while (n--> 0) * first = value;}! #ifndef _RWSTD_NO_MEMBER_TEMPLATES template iterator __copy (Iterator first, Iterator last, iterator result) {while (first = last) * result = * first ; returnrate;} template iTerator __copy_backward (iterator first, iterator last, iterator result) {Whil e (first! = last) * - result = * - last; returnrate;} #else itrator __copy (const_iterator first, const_iterator last, iterator result) {while (first! = last) * Result = * first ; Return result;} iterator __copy (const bool * first, const bool * last, iterator result) {while (! first = last) * result = * first ; return result;} iterator __copy_backward (const_iterator first, const_iterator last, iterator result) { WHILT = * - Last; RETURN RESULT;

} Iterator __copy_backward (const bool * limited, iterator result) {while (first! = Last) * - result = * - last; returnrate;} #ENDIFPROTECTED:

Iterator __start; itrator __finish; __rwstd :: __ rw_basis __end_of_storage;

unsigned int * __bit_alloc (size_type n) {return __value_alloc_type (__ end_of_storage) .allocate ((n _RWSTD_WORD_BIT - 1) / _ RWSTD_WORD_BIT, __ start.p);} void __init (size_type n) {unsigned int * q = __bit_alloc (n); __END_OF_STORAGE = Q (N _RWSTD_WORD_BIT - 1) / _ rwstd_word_bit; __start = Iterator (q, 0); __finish = __Start N;} void __insert_aux (item position, bool x);

PUBLIC:

// // construct / copy / destroy // vector (const Allocator & alloc _RWSTD_DEFAULT_ARG (Allocator ())): __start (iterator ()), __finish (iterator ()), __end_of_storage (0, alloc) { ;} _EXPLICIT vector (size_type n, bool value = bool (), const Allocator & alloc _RWSTD_DEFAULT_ARG (Allocator ())): __end_of_storage (0, alloc) {__init (n); unsigned int * first = __start. P; size_type m = (n _rwstd_word_bit - 1) / _ rwstd_word_bit; while (m-> 0) * first = value? ~ 0: 0;}

Vector (const vector> & x): __end_of_storage (0, x.get_allocator ()) {__init (x.size ()); __copy (x.begin (), x.end ), __start);

#ifndef _RWSTD_NO_MEMBER_TEMPLATES template vector (InputIterator first, InputIterator last): __end_of_storage (0, Allocator ()) {size_type n; __initialize (n, size_type (0)); distance (first, last, n); __init (n); __copy (first, last, __start);} #} #} #}> (const_iterator first): __END_OF_STORAGE (0, allocator ()) {size_type n; __initialize (n, SIZE_TYPE (0)); Distance (first, last, n); __init (n); __Copy (first, last, __start);} Vector (const bool * first, const box): __end_of_storage ( 0, allocator ()) {size_type n; __initialize (n, size_type (0)); Distance (first, last, n); __init (n); __copy (first, last, __start);} #ENDIF ~ Vector () {__Value_alloc_type (__ end_of_storage) .deallocate (__ start.p, __end_of_storage.data () -__ start.p);} Vector & operator = (const vector & x) {if (& x == this) return * this; if (x.size ()> Capacity () {__Value_alloc_type (__ end_of_storage) .deallocate (__ start. p, __END_OF_SORAGE.DATA () -__ start.p); __init (x.size ());} __copy (x.begin (), x.end (), begin ()); __finish = begin () x. size (); return * this;} #ifndef _RWSTD_NO_MEMBER_TEMPLATES template void assign (InputIterator first, InputIterator last) {erase (begin (), end ()); insert (begin (), first, last);} #ELSE VOID ASSIGN (const_iterator first) {ERASE (Begin (), End ());

INSERT (Begin (), first, last);} #ENDIFVOID ASSIGN (SIZE_TYPE N, Const Bool & T = BOOL ()) {ERAS (Begin (), End ()); INSERT (Begin (), N, T); }

Allocator_type get_allocator () const {return (allocator_type) __ end_of_storage;}

//// {RETURN __START;} const_iterator begin () const {return const_iterator (__ start.p, __ start.offset);} iterator end () {return__finish;} const_iterator end () const { Return const_iterator (__ finish.p, __ finish.offset);

reverse_iterator rbegin () {return reverse_iterator (end ());} const_reverse_iterator rbegin () const {return const_reverse_iterator (end ());} reverse_iterator rend () {return reverse_iterator (begin ());} const_reverse_iterator rend () const {return Const_reverse_iterator (begin ());

// // capacity // size_type size () const {return size_type (end () - begin ());} size_type max_size () const {return __value_alloc_type (__ end_of_storage) .max_size ();} void resize (size_type new_size, bool C = false); size_type capacity () const {return size_type (const_iterator (_) (), 0) - begin ());} BOOL EMPTY () const {return begin () == end ();} void Reserve (size_type n) {_RWSTD_THROW (n> max_size (), length_error, __RWSTD :: except_msg_string (__ RWSTD :: __ rwse_InvalidSizeParam, "vector :: reserve (size_t)", n, max_size ()) msgstr ().); IF (Capacity ()

// // element access // reference operator [] (size_type n) {#ifdef _RWSTD_BOUNDS_CHECKING _RWSTD_THROW (n> = size (), out_of_range, __RWSTD :: except_msg_string (__ RWSTD :: rwse_OutOfRange, "vector :: [] (SIZE_T) ", N, Size ()). Msgstr ()); # endif rett * (begin () n);} const_reference Operator [] (size_type n) const {#ifdef _rwstd_bounds_checking _rwstd_throw (n> = size ), OUT_OF_RANGE, __RWSTD :: EXCEPT_MSG_STRING (__ rwstd :: rwse_outofrange, "Vector :: [] (size_t)", n, size ()). msgstr ()); # endif return * (begin () n );} Reference at (size_type n) {_rwstd_throw (n> = size (), out_of_range, __rwstd :: except_msg_string (__ rwstd :: rwse_outofrange, "vector :: at (size_t)", n, size ()) . msgstr ()); return () n);} const_reference at (size_type n) const {_rwstd_throw (n> = size (), out_of_range, __rwstd :: except_msg_string (__rwstd :: r WSE_OUTOFRANGE, "Vector :: at (size_t) const", n, size ()). msgstr ()); returnity * (begin () n);} Reference Front () {Return * Begin (); } Const_reference front () const {return * begin ();} reference back () {return * (end () - 1);} const_reference back () const {return * (end () - 1);} // / / modifiers // void push_back (const bool) {if (__finish.p! = __end_of_storage.data ()) * __ finish = x; else __insert_aux (end (), x);} void pop_back () {--__finish; }

Iterator Insert (Iterator Position, Const Bool & X = Bool ()) {size_type n = position - begin (); if (__finish.p! = __END_OF_Storage.Data () && position == end () * __ finish = x; Else __insert_aux (position, x); return begin () n;} void insert (iterator position, size_type n, const bool & x); # ifndef _RWSTD_NO_MEMBER_TEMPLATES template void insert (iterator position, InputIterator first, InputIterator last); #ELSE VOID INSERT (Iterator Position, const_iterator first, const_iterator last); # ENDIF

Iterator Erase {IF (! (position 1 == end ())) __copy (position 1, end (), position; --__ finish; return position;} {Iterator First, Iterator Last ) {__finish = __copy (last, end (), first); return first;} void swap (vector & x) {if ((allocator_type) __ end_of_storage == (allocator_type) x .__ end_of_storage) {#ifndef _RWSTD_NO_NAMESPACE std :: swap (__ start, x .__ start); std :: swap (__ finish, x .__ finish); std :: swap (__ end_of_storage, x .__ end_of_storage); # else :: swap (__ start, x .__ start); :: swap (__finish, x .__ finish); :: swap (__ end_of_storage, x .__ end_of_storage); # endif // _rwstd_no_namespace} else {Vector _x = * this; * this = x; x = _x; }} Static void swap (reference x, reference y); void flip (); void clear () {ERASE (begin (), end ());} }

#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC template #endif inline bool operator == (const vector & x, const vector & y) {if (x.size () == y.size ( )) {#ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC vector :: const_iterator first1 = x.begin (), #else _TYPENAME vector :: const_iterator first1 = x.begin (), #endif last1 = x.end (), first2 = y.begin (); while (first1 = last1 && * first1 == * first2!) { first1; first2;} return first1 == last1;} return false;} #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC template #endif inline bool operator <(const vector & x, const vector & y) {#ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC vector :: const_iterator first1 = x.begin ( ), #else_typename vector :: const_iterator first1 = x.begin (), #ENDIF Last1 = x.end (), first2 = y.begin (), last2 = y.end ();

While (first1! = last1 &&first2! = last2) {if ((int) * first1 <(int) * first2) Return True; if ((int) * first2 <(int) * first1 ) Return False;} Return First1 == Last1 &&first2! = last2;}

#if! defined (_RWSTD_NO_NAMESPACE) ||! defined (_RWSTD_NO_PART_SPEC_OVERLOAD) #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC template #endif inline bool operator! = (const vector & x, const vector & y) {return (x == y);!} #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC template #endif inline bool operator> (const vector & x, const vector & y) {return y < X;

#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC Template #ENDIF INLINE BOOL OPERATOR> = (Const Vector & x, Const Vector & Y) {Return! (x

#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC Template #ENDIF INLINE BOOL Operator <= (Const Vector & x, Const Vector & Y) {Return! (Y

#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC Template #ENDIF inline void swap (Vector & A, Vector & b) {a.swap (b);}

#ENDIF

#ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC # undef allocator #ENDIF

#ENDIF / * _ RWSTD_NO_BOOL * /

#ifndef _RWSTD_NO_NAMESPACE} #ENDIF

#if Defined (_RWSTD_NO_TEMPLATE_REPOSTORY) && (! defined (__turboc__) || (__turboc__> 0x530)) # include #ENDIF

#undef vector

#ENDIF / * __SD_Vector__ * /

#pragma option pop # endif / * __vector_h * /

转载请注明原文地址:https://www.9cbs.com/read-112045.html

New Post(0)