/*** * ==++== * * Copyright (c) Microsoft Corporation. All rights reserved. * Microsoft would like to acknowledge that this concurrency data structure implementation * is based on the Intel implementation of its Threading Building Blocks ("Intel Material"). * * ==--== * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ * * concurrent_vector.h * * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ****/ /* Intel Material Copyright 2005-2008 Intel Corporation. All Rights Reserved. */ #pragma once #include #include #include #include #include #include #include #include #define _PPL_CONTAINER #if !(defined (_M_X64) || defined (_M_IX86) || defined (_M_ARM)) #error ERROR: Concurrency Runtime is supported only on X64, X86 and ARM architectures. #endif /* !(defined (_M_X64) || defined (_M_IX86) || defined (_M_ARM)) */ #if defined (_M_CEE) #error ERROR: Concurrency Runtime is not supported when compiling /clr. #endif /* defined (_M_CEE) */ #pragma pack(push,_CRT_PACKING) #pragma warning (push) #pragma warning (disable: 4510 4512 4610) // disable warnings for compiler unable to generate constructor /// /// The Concurrency namespace provides classes and functions that give you access to the Concurrency Runtime, /// a concurrent programming framework for C++. For more information, see . /// /**/ namespace Concurrency { template > class concurrent_vector; namespace details { // Bad allocation marker. #define _BAD_ALLOC_MARKER reinterpret_cast(63) // Base class of concurrent vector implementation. class _Concurrent_vector_base_v4 { protected: // Basic types declarations. typedef size_t _Segment_index_t; typedef size_t _Size_type; // Size constants static const _Segment_index_t _Default_initial_segments = 1; // 2 initial items // Number of slots for segment's pointers inside the class static const _Segment_index_t _Pointers_per_short_table = 3; // to fit into 8 words of entire structure static const _Segment_index_t _Pointers_per_long_table = sizeof(_Segment_index_t) * 8; // one segment per bit // Segment pointer. Can be zero-initialized. struct _Segment_t { void* _My_array; }; // Data fields // allocator function pointer void* (__cdecl *_My_vector_allocator_ptr)(_Concurrent_vector_base_v4 &, size_t); // embedded storage of segment pointers _Segment_t _My_storage[_Pointers_per_short_table]; // Methods _Concurrent_vector_base_v4() { _My_early_size = 0; _My_first_block = 0; // here is not _Default_initial_segments for( _Segment_index_t _I = 0; _I < _Pointers_per_short_table; _I++) _My_storage[_I]._My_array = NULL; _My_segment = _My_storage; } _CRTIMP2 ~_Concurrent_vector_base_v4(); _CRTIMP2 static _Segment_index_t __cdecl _Segment_index_of( _Size_type _Index ); static _Segment_index_t _Segment_base( _Segment_index_t _K ) { return (_Segment_index_t(1)<<_K & ~_Segment_index_t(1)); } static _Segment_index_t _Segment_base_index_of( _Segment_index_t &_Index ) { _Segment_index_t _K = _Segment_index_of( _Index ); _Index -= _Segment_base(_K); return _K; } static _Size_type _Segment_size( _Segment_index_t _K ) { return _Segment_index_t(1)<<_K; // fake value for _K==0 } // An operation on an n-element array starting at begin. typedef void (__cdecl *_My_internal_array_op1)(void* _Begin, _Size_type _N ); // An operation on n-element destination array and n-element source array. typedef void (__cdecl *_My_internal_array_op2)(void* _Dst, const void* _Src, _Size_type _N ); // Internal structure for shrink_to_fit(). struct _Internal_segments_table { _Segment_index_t _First_block; void* _Table[_Pointers_per_long_table]; }; _CRTIMP2 void _Internal_reserve( _Size_type _N, _Size_type _Element_size, _Size_type _Max_size ); _CRTIMP2 _Size_type _Internal_capacity() const; void _Internal_grow( _Size_type _Start, _Size_type _Finish, _Size_type _Element_size, _My_internal_array_op2 _Init, const void *_Src ); _Size_type _Internal_grow_segment( const _Size_type _Start, _Size_type _Finish, _Size_type _Element_size, _Segment_t** _PPSegment, _Size_type* _PSegStart, _Size_type* _PSegFinish ); _CRTIMP2 _Size_type _Internal_grow_by( _Size_type _Delta, _Size_type _Element_size, _My_internal_array_op2 _Init, const void *_Src ); _CRTIMP2 void* _Internal_push_back( _Size_type _Element_size, _Size_type& _Index ); _CRTIMP2 _Segment_index_t _Internal_clear( _My_internal_array_op1 _Destroy ); void _Internal_truncate( _Size_type _Old_size, _Size_type _New_size, _Size_type _Element_size, _My_internal_array_op1 _Destroy); _CRTIMP2 void* _Internal_compact( _Size_type _Element_size, void *_Table, _My_internal_array_op1 _Destroy, _My_internal_array_op2 _Copy ); _CRTIMP2 void _Internal_copy( const _Concurrent_vector_base_v4& _Src, _Size_type _Element_size, _My_internal_array_op2 _Copy ); _CRTIMP2 void _Internal_assign( const _Concurrent_vector_base_v4& _Src, _Size_type _Element_size, _My_internal_array_op1 _Destroy, _My_internal_array_op2 _Assign, _My_internal_array_op2 _Copy ); _CRTIMP2 void _Internal_throw_exception(_Size_type) const; _CRTIMP2 void _Internal_swap(_Concurrent_vector_base_v4&); _CRTIMP2 void _Internal_resize( _Size_type _New_size, _Size_type _Element_size, _Size_type _Max_size, _My_internal_array_op1 _Destroy, _My_internal_array_op2 _Init, const void* _Src); _CRTIMP2 _Size_type _Internal_grow_to_at_least_with_result( _Size_type _New_size, _Size_type _Element_size, _My_internal_array_op2 _Init, const void *_Src ); // Count of segments in the first block. _Subatomic<_Size_type> _My_first_block; // Requested size of vector. _Subatomic<_Size_type> _My_early_size; // Pointer to the segments table. _Subatomic<_Segment_t*> _My_segment; private: // Private functionality. class _Helper; friend class _Helper; }; typedef _Concurrent_vector_base_v4 _Concurrent_vector_base; // Meets requirements of a forward iterator for STL.*/ /** _Value is either the _Ty or const _Ty type of the container. */ template class _Vector_iterator { // concurrent_vector over which we are iterating. _Container* _My_vector; // Index into the vector. size_t _My_index; // Caches _My_vector->_Internal_subscript(_My_index) /** NULL if cached value is not available */ mutable _Value* _My_item; template friend _Vector_iterator<_C,_Ty> operator+( ptrdiff_t _Offset, const _Vector_iterator<_C,_Ty>& _Vec ); template friend bool operator==( const _Vector_iterator<_C,_Ty>&, const _Vector_iterator<_C,_U>& ); template friend bool operator<( const _Vector_iterator<_C,_Ty>&, const _Vector_iterator<_C,_U>& ); template friend ptrdiff_t operator-( const _Vector_iterator<_C,_Ty>&, const _Vector_iterator<_C,_U>& ); template friend class ::Concurrency::details::_Vector_iterator; template friend class ::Concurrency::concurrent_vector; _Vector_iterator( const _Container& _Vec, size_t _Index, void* _Ptr = NULL ) : _My_vector(const_cast<_Container*>(&_Vec)), _My_index(_Index), _My_item(static_cast<_Value*>(_Ptr)) { } public: // Default constructor _Vector_iterator() : _My_vector(NULL), _My_index(~size_t(0)), _My_item(NULL) { } _Vector_iterator( const _Vector_iterator<_Container,typename _Container::value_type>& _Other ) : _My_vector(_Other._My_vector), _My_index(_Other._My_index), _My_item(_Other._My_item) { } _Vector_iterator operator+( ptrdiff_t _Offset ) const { return _Vector_iterator( *_My_vector, _My_index+_Offset ); } _Vector_iterator& operator+=( ptrdiff_t _Offset ) { _My_index+=_Offset; _My_item = NULL; return *this; } _Vector_iterator operator-( ptrdiff_t _Offset ) const { return _Vector_iterator( *_My_vector, _My_index-_Offset ); } _Vector_iterator& operator-=( ptrdiff_t _Offset ) { _My_index-=_Offset; _My_item = NULL; return *this; } _Value& operator*() const { _Value* _Item = _My_item; if( !_Item ) _Item = _My_item = &_My_vector->_Internal_subscript(_My_index); _CONCRT_ASSERT( _Item==&_My_vector->_Internal_subscript(_My_index)); // corrupt cache return *_Item; } _Value& operator[]( ptrdiff_t _K ) const { return _My_vector->_Internal_subscript(_My_index+_K); } _Value* operator->() const { return &operator*(); } // Pre increment _Vector_iterator& operator++() { size_t _K = ++_My_index; if( _My_item ) { // Following test uses 2's-complement wizardry. if( (_K& (_K-2))==0 ) { // _K is a power of two that is at least _K-2. _My_item= NULL; } else { ++_My_item; } } return *this; } // Pre decrement _Vector_iterator& operator--() { _CONCRT_ASSERT( _My_index>0 ); // operator--() applied to iterator already at beginning of concurrent_vector. size_t _K = _My_index--; if( _My_item ) { // Following test uses 2's-complement wizardry. if( (_K& (_K-2))==0 ) { // k is a power of two that is at least k-2. _My_item= NULL; } else { --_My_item; } } return *this; } // Post increment _Vector_iterator operator++(int) { _Vector_iterator _Result = *this; operator++(); return _Result; } // Post decrement _Vector_iterator operator--(int) { _Vector_iterator _Result = *this; operator--(); return _Result; } // STL support typedef ptrdiff_t difference_type; typedef _Value value_type; typedef _Value* pointer; typedef _Value& reference; typedef std::random_access_iterator_tag iterator_category; }; template struct std::_Is_checked_helper<_Vector_iterator<_Container, _Value> > : public true_type { // mark _Vector_iterator as checked. This supresses warning C4996 }; template _Vector_iterator<_Container,_Ty> operator+( ptrdiff_t _Offset, const _Vector_iterator<_Container,_Ty>& _Vec ) { return _Vector_iterator<_Container,_Ty>( *_Vec._My_vector, _Vec._My_index+_Offset ); } template bool operator==( const _Vector_iterator<_Container,_Ty>& _I, const _Vector_iterator<_Container,_U>& _J ) { return _I._My_index==_J._My_index && _I._My_vector == _J._My_vector; } template bool operator!=( const _Vector_iterator<_Container,_Ty>& _I, const _Vector_iterator<_Container,_U>& _J ) { return !(_I==_J); } template bool operator<( const _Vector_iterator<_Container,_Ty>& _I, const _Vector_iterator<_Container,_U>& _J ) { return _I._My_index<_J._My_index && _I._My_vector == _J._My_vector; } template bool operator>( const _Vector_iterator<_Container,_Ty>& _I, const _Vector_iterator<_Container,_U>& _J ) { return _J<_I; } template bool operator>=( const _Vector_iterator<_Container,_Ty>& _I, const _Vector_iterator<_Container,_U>& _J ) { return !(_I<_J); } template bool operator<=( const _Vector_iterator<_Container,_Ty>& _I, const _Vector_iterator<_Container,_U>& _J ) { return !(_J<_I); } template ptrdiff_t operator-( const _Vector_iterator<_Container,_Ty>& _I, const _Vector_iterator<_Container,_U>& _J ) { return ptrdiff_t(_I._My_index)-ptrdiff_t(_J._My_index); } template class _Allocator_base { public: typedef typename _Ax::template rebind<_Ty>::other _Allocator_type; _Allocator_type _My_allocator; _Allocator_base(const _Allocator_type &_Al = _Allocator_type() ) : _My_allocator(_Al) { } }; } // namespace details /// /// The concurrent_vector class is a sequence container class that allows random access to any element. /// It enables concurrency-safe append, element access, iterator access, and iterator traversal operations. /// /// /// The data type of the elements to be stored in the vector. /// /// /// The type that represents the stored allocator object that encapsulates details about the allocation and /// deallocation of memory for the concurrent vector. This argument is optional and the default value is /// allocator<>. /// /// /// For detailed information on the concurrent_vector class, see . /// /// /**/ template class concurrent_vector: protected details::_Allocator_base<_Ty, _Ax>, private details::_Concurrent_vector_base_v4 { private: typedef concurrent_vector<_Ty, _Ax> _Myt; template friend class details::_Vector_iterator; public: /// /// A type that counts the number of elements in a concurrent vector. /// /**/ typedef details::_Concurrent_vector_base_v4::_Size_type size_type; /// /// A type that represents the allocator class for the concurrent vector. /// /**/ typedef typename details::_Allocator_base<_Ty, _Ax>::_Allocator_type allocator_type; /// /// A type that represents the data type stored in a concurrent vector. /// /**/ typedef _Ty value_type; /// /// A type that provides the signed distance between two elements in a concurrent vector. /// /**/ typedef ptrdiff_t difference_type; /// /// A type that provides a reference to an element stored in a concurrent vector. /// /**/ typedef _Ty& reference; /// /// A type that provides a reference to a const element stored in a concurrent vector for reading and /// performing const operations. /// /**/ typedef const _Ty& const_reference; /// /// A type that provides a pointer to an element in a concurrent vector. /// /**/ typedef _Ty *pointer; /// /// A type that provides a pointer to a const element in a concurrent vector. /// /**/ typedef const _Ty *const_pointer; /// /// A type that provides a random-access iterator that can read any element in a concurrent vector. Modification of an /// element using the iterator is not concurrency-safe. /// /**/ typedef details::_Vector_iterator iterator; /// /// A type that provides a random-access iterator that can read a const element in a concurrent vector. /// /**/ typedef details::_Vector_iterator const_iterator; /// /// A type that provides a random-access iterator that can read any element in a reversed concurrent vector. Modification of an /// element using the iterator is not concurrency-safe. /// /**/ typedef std::reverse_iterator reverse_iterator; /// /// A type that provides a random-access iterator that can read any const element in the concurrent vector. /// /**/ typedef std::reverse_iterator const_reverse_iterator; /// /// Constructs a concurrent vector. /// /// /// The allocator class to use with this object. /// /// /// All constructors store an allocator object and initialize the vector. /// The first constructor specify an empty initial vector and explicitly specifies the allocator type. /// to be used. /// The second and third constructors specify a copy of the concurrent vector . /// The fourth constructor specifies a move of the concurrent vector . /// The fifth constructor specifies a repetition of a specified number () of elements of the default /// value for class . /// The sixth constructor specifies a repetition of () elements of value . /// The last constructor specifies values supplied by the iterator range [, ). /// /**/ explicit concurrent_vector(const allocator_type &_Al = allocator_type()) : details::_Allocator_base<_Ty, _Ax>(_Al) { _My_vector_allocator_ptr = &_Internal_allocator; } /// /// Constructs a concurrent vector. /// /// /// The source concurrent_vector object to copy or move elements from. /// /// /// All constructors store an allocator object and initialize the vector. /// The first constructor specify an empty initial vector and explicitly specifies the allocator type. /// to be used. /// The second and third constructors specify a copy of the concurrent vector . /// The fourth constructor specifies a move of the concurrent vector . /// The fifth constructor specifies a repetition of a specified number () of elements of the default /// value for class . /// The sixth constructor specifies a repetition of () elements of value . /// The last constructor specifies values supplied by the iterator range [, ). /// /**/ concurrent_vector( const concurrent_vector& _Vector) : details::_Allocator_base<_Ty, _Ax>(_Vector.get_allocator()) { _My_vector_allocator_ptr = &_Internal_allocator; _Internal_copy(_Vector, sizeof(_Ty), &_Copy_array); } /// /// Constructs a concurrent vector. /// /// /// The allocator type of the source vector. /// /// /// The source concurrent_vector object to copy or move elements from. /// /// /// The allocator class to use with this object. /// /// /// All constructors store an allocator object and initialize the vector. /// The first constructor specify an empty initial vector and explicitly specifies the allocator type. /// to be used. /// The second and third constructors specify a copy of the concurrent vector . /// The fourth constructor specifies a move of the concurrent vector . /// The fifth constructor specifies a repetition of a specified number () of elements of the default /// value for class . /// The sixth constructor specifies a repetition of () elements of value . /// The last constructor specifies values supplied by the iterator range [, ). /// /**/ template concurrent_vector( const concurrent_vector<_Ty, M>& _Vector, const allocator_type& _Al = allocator_type() ) : details::_Allocator_base<_Ty, _Ax>(_Al) { _My_vector_allocator_ptr = &_Internal_allocator; _Internal_copy(_Vector._Internal_vector_base(), sizeof(_Ty), &_Copy_array); } /// /// Constructs a concurrent vector. /// /// /// The source concurrent_vector object to copy or move elements from. /// /// /// All constructors store an allocator object and initialize the vector. /// The first constructor specify an empty initial vector and explicitly specifies the allocator type. /// to be used. /// The second and third constructors specify a copy of the concurrent vector . /// The fourth constructor specifies a move of the concurrent vector . /// The fifth constructor specifies a repetition of a specified number () of elements of the default /// value for class . /// The sixth constructor specifies a repetition of () elements of value . /// The last constructor specifies values supplied by the iterator range [, ). /// /**/ concurrent_vector( concurrent_vector && _Vector) : details::_Allocator_base<_Ty, _Ax>(_Vector.get_allocator()) { _My_vector_allocator_ptr = &_Internal_allocator; _Concurrent_vector_base_v4::_Internal_swap(_Vector._Internal_vector_base()); } /// /// Constructs a concurrent vector. /// /// /// The initial size of the concurrent_vector object. /// /// /// All constructors store an allocator object and initialize the vector. /// The first constructor specify an empty initial vector and explicitly specifies the allocator type. /// to be used. /// The second and third constructors specify a copy of the concurrent vector . /// The fourth constructor specifies a move of the concurrent vector . /// The fifth constructor specifies a repetition of a specified number () of elements of the default /// value for class . /// The sixth constructor specifies a repetition of () elements of value . /// The last constructor specifies values supplied by the iterator range [, ). /// /**/ explicit concurrent_vector(size_type _N) { _My_vector_allocator_ptr = &_Internal_allocator; if ( !_N ) return; _Internal_reserve(_N, sizeof(_Ty), max_size()); _My_early_size = _N; _CONCRT_ASSERT( _My_first_block == _Segment_index_of(_N-1)+1 ); _Initialize_array(static_cast<_Ty*>(_My_segment[0]._My_array), NULL, _N); } /// /// Constructs a concurrent vector. /// /// /// The initial capacity of the concurrent_vector object. /// /// /// The value of elements in the constructed object. /// /// /// The allocator class to use with this object. /// /// /// All constructors store an allocator object and initialize the vector. /// The first constructor specify an empty initial vector and explicitly specifies the allocator type. /// to be used. /// The second and third constructors specify a copy of the concurrent vector . /// The fourth constructor specifies a move of the concurrent vector . /// The fifth constructor specifies a repetition of a specified number () of elements of the default /// value for class . /// The sixth constructor specifies a repetition of () elements of value . /// The last constructor specifies values supplied by the iterator range [, ). /// /**/ concurrent_vector(size_type _N, const_reference _Item, const allocator_type& _Al = allocator_type()) : details::_Allocator_base<_Ty, _Ax>(_Al) { _My_vector_allocator_ptr = &_Internal_allocator; _Internal_assign( _N, _Item ); } /// /// Constructs a concurrent vector. /// /// /// The type of the input iterator. /// /// /// Position of the first element in the range of elements to be copied. /// /// /// Position of the first element beyond the range of elements to be copied. /// /// /// The allocator class to use with this object. /// /// /// All constructors store an allocator object and initialize the vector. /// The first constructor specify an empty initial vector and explicitly specifies the allocator type. /// to be used. /// The second and third constructors specify a copy of the concurrent vector . /// The fourth constructor specifies a move of the concurrent vector . /// The fifth constructor specifies a repetition of a specified number () of elements of the default /// value for class . /// The sixth constructor specifies a repetition of () elements of value . /// The last constructor specifies values supplied by the iterator range [, ). /// /**/ template concurrent_vector(_InputIterator _Begin, _InputIterator _End, const allocator_type &_Al = allocator_type()) : details::_Allocator_base<_Ty, _Ax>(_Al) { _My_vector_allocator_ptr = &_Internal_allocator; _Internal_assign(_Begin, _End, static_cast<_Is_integer_tag::is_integer> *>(0) ); } /// /// Assigns the contents of another concurrent_vector object to this one. This method is not concurrency-safe. /// /// /// The source concurrent_vector object. /// /// /// A reference to this concurrent_vector object. /// /**/ concurrent_vector& operator=( const concurrent_vector& _Vector ) { if( this != &_Vector ) _Concurrent_vector_base_v4::_Internal_assign(_Vector, sizeof(_Ty), &_Destroy_array, &_Assign_array, &_Copy_array); return *this; } /// /// Assigns the contents of another concurrent_vector object to this one. This method is not concurrency-safe. /// /// /// The allocator type of the source vector. /// /// /// The source concurrent_vector object. /// /// /// A reference to this concurrent_vector object. /// /**/ template concurrent_vector& operator=( const concurrent_vector<_Ty, M>& _Vector ) { if( static_cast( this ) != static_cast( &_Vector ) ) { _Concurrent_vector_base_v4::_Internal_assign(_Vector._Internal_vector_base(), sizeof(_Ty), &_Destroy_array, &_Assign_array, &_Copy_array); } return *this; } /// /// Assigns the contents of another concurrent_vector object to this one. This method is not concurrency-safe. /// /// /// The source concurrent_vector object. /// /// /// A reference to this concurrent_vector object. /// /**/ concurrent_vector& operator=( concurrent_vector && _Vector ) { if( static_cast( this ) != static_cast( &_Vector ) ) { _Concurrent_vector_base_v4::_Internal_swap(_Vector._Internal_vector_base()); _Vector.clear(); } return *this; } /// /// Grows this concurrent vector by elements. This method is concurrency-safe. /// /// /// The number of elements to append to the object. /// /// /// An iterator to first item appended. /// /// /// If is not specified, the new elements are default constructed. /// /**/ iterator grow_by( size_type _Delta ) { return iterator(*this, _Delta ? _Internal_grow_by( _Delta, sizeof(_Ty), &_Initialize_array, NULL ) : _My_early_size); } /// /// Grows this concurrent vector by elements. This method is concurrency-safe. /// /// /// The number of elements to append to the object. /// /// /// The value to initialize the new elements with. /// /// /// An iterator to first item appended. /// /// /// If is not specified, the new elements are default constructed. /// /**/ iterator grow_by( size_type _Delta, const_reference _Item ) { return iterator(*this, _Delta ? _Internal_grow_by( _Delta, sizeof(_Ty), &_Initialize_array_by, static_cast(&_Item) ) : _My_early_size); } /// /// Grows this concurrent vector until it has at least elements. This method is concurrency-safe. /// /// /// The new minimum size for the concurrent_vector object. /// /// /// An iterator that points to beginning of appended sequence, or to the element at index if no /// elements were appended. /// /**/ iterator grow_to_at_least( size_type _N ) { size_type _M = 0; if( _N ) { _M = _Internal_grow_to_at_least_with_result( _N, sizeof(_Ty), &_Initialize_array, NULL ); if( _M > _N ) _M = _N; } return iterator(*this, _M); }; /// /// Appends the given item to the end of the concurrent vector. This method is concurrency-safe. /// /// /// The value to be appended. /// /// /// An iterator to item appended. /// /**/ iterator push_back( const_reference _Item ) { size_type _K; void *_Ptr = _Internal_push_back(sizeof(_Ty), _K); _Internal_loop_guide _Loop(1, _Ptr); _Loop._Init(&_Item); return iterator(*this, _K, _Ptr); } /// /// Appends the given item to the end of the concurrent vector. This method is concurrency-safe. /// /// /// The value to be appended. /// /// /// An iterator to item appended. /// /**/ iterator push_back( _Ty &&_Item ) { size_type _K; void *_Ptr = _Internal_push_back(sizeof(_Ty), _K); new (_Ptr) _Ty( std::move(_Item)); return iterator(*this, _K, _Ptr); } /// /// Provides access to the element at the given index in the concurrent vector. This method is concurrency-safe for read operations, /// and also while growing the vector, as long as the you have ensured that the value is less than /// the size of the concurrent vector. /// /// /// The index of the element to be retrieved. /// /// /// A reference to the item at the given index. /// /// /// The version of operator [] that returns a non-const reference cannot be used to concurrently write to the element /// from different threads. A different synchronization object should be used to synchronize concurrent read and write operations /// to the same data element. /// No bounds checking is performed to ensure that is a valid index into the concurrent vector. /// /**/ reference operator[]( size_type _Index ) { return _Internal_subscript(_Index); } /// /// Provides read access to element at the given index in the concurrent vector. This method is concurrency-safe for read operations, /// and also while growing the vector, as long as the you have ensured that the value is less than /// the size of the concurrent vector. /// /// /// The index of the element to be retrieved. /// /// /// A const reference to the item at the given index. /// /// /// The version of operator [] that returns a non-const reference cannot be used to concurrently write to the element /// from different threads. A different synchronization object should be used to synchronize concurrent read and write operations /// to the same data element. /// No bounds checking is performed to ensure that is a valid index into the concurrent vector. /// /**/ const_reference operator[]( size_type _Index ) const { return _Internal_subscript(_Index); } /// /// Provides access to the element at the given index in the concurrent vector. This method is concurrency-safe for read operations, /// and also while growing the vector, as long as you have ensured that the value is less than /// the size of the concurrent vector. /// /// /// The index of the element to be retrieved. /// /// /// A reference to the item at the given index. /// /// /// The version of the function at that returns a non-const reference cannot be used to concurrently write to the element /// from different threads. A different synchronization object should be used to synchronize concurrent read and write operations /// to the same data element. /// The method throws out_of_range if is greater than or equal to the size of the concurrent vector, /// and range_error if the index is for a broken portion of the vector. For details on how a vector can become broken, /// see . /// /**/ reference at( size_type _Index ) { return _Internal_subscript_with_exceptions(_Index); } /// /// Provides access to the element at the given index in the concurrent vector. This method is concurrency-safe for read operations, /// and also while growing the vector, as long as you have ensured that the value is less than /// the size of the concurrent vector. /// /// /// The index of the element to be retrieved. /// /// /// A const reference to the item at the given index. /// /// /// The version of the function at that returns a non-const reference cannot be used to concurrently write to the element /// from different threads. A different synchronization object should be used to synchronize concurrent read and write operations /// to the same data element. /// The method throws out_of_range if is greater than or equal to the size of the concurrent vector, /// and range_error if the index is for a broken portion of the vector. For details on how a vector can become broken, /// see . /// /**/ const_reference at( size_type _Index ) const { return _Internal_subscript_with_exceptions(_Index); } /// /// Returns the number of elements in the concurrent vector. This method is concurrency-safe. /// /// /// The number of elements in this concurrent_vector object. /// /// /// The returned size is guaranteed to include all elements appended by calls to the function push_back, /// or grow operations that have completed prior to invoking this method. However, it may also include elements /// that are allocated but still under construction by concurrent calls to any of the growth methods. /// /**/ size_type size() const { size_type _Sz = _My_early_size; size_type _Cp = _Internal_capacity(); return _Cp < _Sz ? _Cp : _Sz; } /// /// Tests if the concurrent vector is empty at the time this method is called. This method is concurrency-safe. /// /// /// true if the vector was empty at the moment the function was called, false otherwise. /// /**/ bool empty() const { return !_My_early_size; } /// /// Returns the maximum size to which the concurrent vector can grow without having to allocate more memory. /// This method is concurrency-safe. /// /// /// The maximum size to which the concurrent vector can grow without having to allocate more memory. /// /// /// Unlike an STL vector, a concurrent_vector object does not move existing elements if it allocates more memory. /// /**/ size_type capacity() const { return _Internal_capacity(); } /// /// Allocates enough space to grow the concurrent vector to size without having to allocate more memory later. /// This method is not concurrency-safe. /// /// /// The number of elements to reserve space for. /// /// /// reserve is not concurrency-safe. You must ensure that no other threads are invoking methods /// on the concurrent vector when you call this method. The capacity of the concurrent vector after the method returns /// may be bigger than the requested reservation. /// /**/ void reserve( size_type _N ) { if( _N ) _Internal_reserve(_N, sizeof(_Ty), max_size()); } /// /// Compacts the internal representation of the concurrent vector to reduce fragmentation and optimize memory usage. /// This method is not concurrency-safe. /// /// /// This method will internally re-allocate memory move elements around, invalidating all the iterators. /// shrink_to_fit is not concurrency-safe. You must ensure that no other threads are invoking methods /// on the concurrent vector when you call this function. /// /**/ void shrink_to_fit(); /// /// Changes the size of the concurrent vector to the requested size, deleting or adding elements as /// necessary. This method is not concurrency-safe. /// /// /// The new size of the concurrent vector. /// /// /// If the size of the container is less than the requested size, elements are added to the vector until it reaches the /// requested size. If the size of the container is larger than the requested size, the elements closest to the end of the container /// are deleted until the container reaches the size . If the present size of the container is the same as the requested /// size, no action is taken. /// resize is not concurrency safe. You must ensure that no other threads are invoking methods /// on the concurrent vector when you call this method. /// /**/ void resize(size_type _N) { _Internal_resize( _N, sizeof(_Ty), max_size(), _Destroy_array, _Initialize_array, NULL); } /// /// Changes the size of the concurrent vector to the requested size, deleting or adding elements as /// necessary. This method is not concurrency-safe. /// /// /// The new size of the concurrent_vector. /// /// /// The value of new elements added to the vector if the new size is larger than the original size. If the value is omitted, /// the new objects are assigned the default value for their type. /// /// /// If the size of the container is less than the requested size, elements are added to the vector until it reaches the /// requested size. If the size of the container is larger than the requested size, the elements closest to the end of the container /// are deleted until the container reaches the size . If the present size of the container is the same as the requested /// size, no action is taken. /// resize is not concurrency safe. You must ensure that no other threads are invoking methods /// on the concurrent vector when you call this method. /// /**/ void resize(size_type _N, const _Ty& _Val) { _Internal_resize( _N, sizeof(_Ty), max_size(), _Destroy_array, _Initialize_array_by, static_cast(&_Val) ); } /// /// Returns the maximum number of elements the concurrent vector can hold. This method is concurrency-safe. /// /// /// The maximum number of elements the concurrent_vector object can hold. /// /**/ size_type max_size() const { return (~size_type(0))/sizeof(_Ty); } /// /// Returns an iterator of type or to the beginning of /// the concurrent vector. This method is concurrency-safe. /// /// /// An iterator of type or to the beginning of /// the concurrent vector. /// /**/ iterator begin() { return iterator(*this,0); } /// /// Returns an iterator of type or to the end of /// the concurrent vector. This method is concurrency-safe. /// /// /// An iterator of type or to the end of /// the concurrent vector. /// /**/ iterator end() { return iterator(*this,size()); } /// /// Returns an iterator of type or to the beginning of /// the concurrent vector. This method is concurrency-safe. /// /// /// An iterator of type or to the beginning of /// the concurrent vector. /// /**/ const_iterator begin() const { return const_iterator(*this,0); } /// /// Returns an iterator of type or to the end of /// the concurrent vector. This method is concurrency-safe. /// /// /// An iterator of type or to the end of /// the concurrent vector. /// /**/ const_iterator end() const { return const_iterator(*this,size()); } /// /// Returns an iterator of type or to the beginning of /// the concurrent vector. This method is concurrency-safe. /// /// /// An iterator of type or to the beginning of /// the concurrent vector. /// /**/ reverse_iterator rbegin() { return reverse_iterator(end()); } /// /// Returns an iterator of type or to the end of /// the concurrent vector. This method is concurrency-safe. /// /// /// An iterator of type or to the end of /// the concurrent vector. /// /**/ reverse_iterator rend() { return reverse_iterator(begin()); } /// /// Returns an iterator of type or to the beginning /// the concurrent vector. This method is concurrency-safe. /// /// /// An iterator of type or to the beginning of /// the concurrent vector. /// /**/ const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } /// /// Returns an iterator of type or to the end of /// the concurrent vector. This method is concurrency-safe. /// /// /// An iterator of type or to the end of /// the concurrent vector. /// /**/ const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } /// /// Returns an iterator of type to the beginning of the concurrent vector. /// This method is concurrency-safe. /// /// /// An iterator of type to the beginning of the concurrent vector. /// /**/ const_iterator cbegin() const { return (((const _Myt *)this)->begin()); } /// /// Returns an iterator of type to the end of the concurrent vector. /// This method is concurrency-safe. /// /// /// An iterator of type to the end of the concurrent vector. /// /**/ const_iterator cend() const { return (((const _Myt *)this)->end()); } /// /// Returns an iterator of type to the beginning of the concurrent vector. /// This method is concurrency-safe. /// /// /// An iterator of type to the beginning of the concurrent vector. /// /**/ const_reverse_iterator crbegin() const { return (((const _Myt *)this)->rbegin()); } /// /// Returns an iterator of type to the end of the concurrent vector. /// This method is concurrency-safe. /// /// /// An iterator of type to the end of the concurrent vector. /// /**/ const_reverse_iterator crend() const { return (((const _Myt *)this)->rend()); } /// /// Returns a reference or a const reference to the first element in the concurrent vector. If the /// concurrent vector is empty, the return value is undefined. This method is concurrency-safe. /// /// /// A reference or a const reference to the first element in the concurrent vector. /// /**/ reference front() { _CONCRT_ASSERT( size()>0 ); return static_cast<_Ty*>(_My_segment[0]._My_array)[0]; } /// /// Returns a reference or a const reference to the first element in the concurrent vector. If the /// concurrent vector is empty, the return value is undefined. This method is concurrency-safe. /// /// /// A reference or a const reference to the first element in the concurrent_vector object. /// /**/ const_reference front() const { _CONCRT_ASSERT( size()>0 ); return static_cast<_Ty*>(_My_segment[0]._My_array)[0]; } /// /// Returns a reference or a const reference to the last element in the concurrent vector. If the /// concurrent vector is empty, the return value is undefined. This method is concurrency-safe. /// /// /// A reference or a const reference to the last element in the concurrent vector. /// /**/ reference back() { _Size_type sz = size(); _CONCRT_ASSERT( sz > 0 ); return _Internal_subscript( sz-1 ); } /// /// Returns a reference or a const reference to the last element in the concurrent_vector. If the /// concurrent vector is empty, the return value is undefined. This method is concurrency-safe. /// /// /// A reference or a const reference to the last element in the concurrent vector. /// /**/ const_reference back() const { _Size_type sz = size(); _CONCRT_ASSERT( sz > 0 ); return _Internal_subscript( sz-1 ); } /// /// Returns a copy of the allocator used to construct the concurrent vector. This method is concurrency-safe. /// /// /// A copy of the allocator used to construct the concurrent_vector object. /// /**/ allocator_type get_allocator() const { return this->_My_allocator; } /// /// Erases the elements of the concurrent vector and assigns to it either copies of /// , or values specified by the iterator range [, ). /// This method is not concurrency-safe. /// /// /// The number of items to copy into the concurrent vector. /// /// /// Reference to a value used to fill the concurrent vector. /// /// /// assign is not concurrency-safe. You must ensure that no other threads are invoking methods /// on the concurrent vector when you call this method. /// /**/ void assign(size_type _N, const_reference _Item) { clear(); _Internal_assign( _N, _Item ); } /// /// Erases the elements of the concurrent vector and assigns to it either copies of , /// or values specified by the iterator range [, ). /// This method is not concurrency-safe. /// /// /// The type of the specified iterator. /// /// /// An iterator to the first element of the source range. /// /// /// An iterator to one past the last element of the source range. /// /// /// assign is not concurrency-safe. You must ensure that no other threads are invoking methods /// on the concurrent vector when you call this method. /// /**/ template void assign(_InputIterator _Begin, _InputIterator _End) { clear(); _Internal_assign( _Begin, _End, static_cast<_Is_integer_tag::is_integer> *>(0) ); } /// /// Swaps the contents of two concurrent vectors. This method is not concurrency-safe. /// /// /// The concurrent_vector object to swap contents with. /// /**/ void swap(concurrent_vector &_Vector) { if( this != &_Vector ) { _Concurrent_vector_base_v4::_Internal_swap(static_cast<_Concurrent_vector_base_v4&>(_Vector)); std::swap(this->_My_allocator, _Vector._My_allocator); } } /// /// Erases all elements in the concurrent vector. This method is not concurrency-safe. /// /// /// clear is not concurrency-safe. You must ensure that no other threads are invoking methods /// on the concurrent vector when you call this method. clear does not free internal arrays. To free internal arrays, /// call the function shrink_to_fit after clear. /// /**/ void clear() { _Internal_clear(&_Destroy_array); } /// /// Erases all elements and destroys this concurrent vector. /// /**/ ~concurrent_vector() { _Segment_t *_Table = _My_segment; _Internal_free_segments( reinterpret_cast(_Table), _Internal_clear(&_Destroy_array), _My_first_block ); // base class destructor call } const ::Concurrency::details::_Concurrent_vector_base_v4 &_Internal_vector_base() const { return *this; } ::Concurrency::details::_Concurrent_vector_base_v4 &_Internal_vector_base() { return *this; } private: // Allocate _K items static void * __cdecl _Internal_allocator(::Concurrency::details::_Concurrent_vector_base_v4 &_Vb, size_t _K) { return static_cast&>(_Vb)._My_allocator.allocate(_K); } // Free _K segments from table void _Internal_free_segments(void *_Table[], _Segment_index_t _K, _Segment_index_t _First_block); // Get reference to element at given _Index. _Ty& _Internal_subscript( size_type _Index ) const; // Get reference to element at given _Index with errors checks _Ty& _Internal_subscript_with_exceptions( size_type _Index ) const; // assign _N items by copying _Item void _Internal_assign(size_type _N, const_reference _Item); // helper class template class _Is_integer_tag; // assign integer items by copying when arguments are treated as iterators. See C++ Standard 2003 23.1.1 p9 template void _Internal_assign(_I _First, _I _Last, _Is_integer_tag *) { _Internal_assign(static_cast(_First), static_cast<_Ty>(_Last)); } // inline proxy assign by iterators template void _Internal_assign(_I _First, _I _Last, _Is_integer_tag *) { internal_assign_iterators(_First, _Last); } // assign by iterators template void internal_assign_iterators(_I _First, _I _Last); // Construct _N instances of _Ty, starting at "begin". static void __cdecl _Initialize_array( void* _Begin, const void*, size_type _N ); // Construct _N instances of _Ty, starting at "begin". static void __cdecl _Initialize_array_by( void* _Begin, const void* _Src, size_type _N ); // Construct _N instances of _Ty, starting at "begin". static void __cdecl _Copy_array( void* _Dst, const void* _Src, size_type _N ); // Assign _N instances of _Ty, starting at "begin". static void __cdecl _Assign_array( void* _Dst, const void* _Src, size_type _N ); // Destroy _N instances of _Ty, starting at "begin". static void __cdecl _Destroy_array( void* _Begin, size_type _N ); // Exception-aware helper class for filling a segment by exception-danger operators of user class class _Internal_loop_guide { public: const pointer _My_array; const size_type _N; size_type _I; _Internal_loop_guide(size_type _NTrials, void *_Ptr) : _My_array(static_cast(_Ptr)), _N(_NTrials), _I(0) { } void _Init() { for(; _I < _N; ++_I) new( &_My_array[_I] ) _Ty(); } void _Init(const void *_Src) { for(; _I < _N; ++_I) new( &_My_array[_I] ) _Ty(*static_cast(_Src)); } void _Copy(const void *_Src) { for(; _I < _N; ++_I) new( &_My_array[_I] ) _Ty(static_cast(_Src)[_I]); } void _Assign(const void *_Src) { for(; _I < _N; ++_I) _My_array[_I] = static_cast(_Src)[_I]; } template void _Iterate(_It &_Src) { for(; _I < _N; ++_I, ++_Src) new( &_My_array[_I] ) _Ty( *_Src ); } ~_Internal_loop_guide() { if(_I < _N) // if exception raised, do zeroing on the rest of items std::memset(_My_array+_I, 0, (_N-_I)*sizeof(value_type)); } private: void operator=(const _Internal_loop_guide&); // prevent warning: assign operator can't be generated }; }; /// /// Compacts the internal representation of the concurrent vector to reduce fragmentation and optimize memory usage. /// /// /// This method will internally re-allocate memory move elements around, invalidating all the iterators. /// shrink_to_fit is not concurrency-safe. You must ensure that no other threads are invoking methods /// on the concurrent vector when you call this function. /// /**/ template void concurrent_vector<_Ty, _Ax>::shrink_to_fit() { _Internal_segments_table _Old = { 0, nullptr }; try { if( _Internal_compact( sizeof(_Ty), &_Old, &_Destroy_array, &_Copy_array ) ) _Internal_free_segments( _Old._Table, _Pointers_per_long_table, _Old._First_block ); // Free joined and unnecessary segments } catch(...) { if( _Old._First_block ) // Free segment allocated for compacting. Only for support of exceptions in ctor of user _Ty[pe] _Internal_free_segments( _Old._Table, 1, _Old._First_block ); throw; } } template void concurrent_vector<_Ty, _Ax>::_Internal_free_segments(void *_Table[], _Segment_index_t _K, _Segment_index_t _First_block) { // Free the arrays while( _K > _First_block ) { --_K; _Ty* _Array = static_cast<_Ty*>(_Table[_K]); _Table[_K] = NULL; if( _Array > _BAD_ALLOC_MARKER ) // check for correct segment pointer this->_My_allocator.deallocate( _Array, _Segment_size(_K) ); } _Ty* _Array = static_cast<_Ty*>(_Table[0]); if( _Array > _BAD_ALLOC_MARKER ) { _CONCRT_ASSERT( _First_block > 0 ); while(_K > 0) _Table[--_K] = NULL; this->_My_allocator.deallocate( _Array, _Segment_size(_First_block) ); } } template _Ty& concurrent_vector<_Ty, _Ax>::_Internal_subscript( size_type _Index ) const { _CONCRT_ASSERT( _Index<_My_early_size ); // index out of bounds size_type _J = _Index; _Segment_index_t _K = _Segment_base_index_of( _J ); _CONCRT_ASSERT( _My_segment != (_Segment_t*)_My_storage || _K < _Pointers_per_short_table ); // index is under construction // no need in load_with_acquire because the thread works in its own space or gets _Ty* _Array = static_cast<_Ty*>(_My_segment[_K]._My_array); _CONCRT_ASSERT( _Array != _BAD_ALLOC_MARKER ); // instance may be broken by bad allocation; use at() instead _CONCRT_ASSERT( _Array != NULL ); // index is being allocated return _Array[_J]; } template _Ty& concurrent_vector<_Ty, _Ax>::_Internal_subscript_with_exceptions( size_type _Index ) const { if( _Index >= _My_early_size ) _Internal_throw_exception(0); // throw std::out_of_range size_type _J = _Index; _Segment_index_t _K = _Segment_base_index_of( _J ); if( _My_segment == (_Segment_t*)_My_storage && _K >= _Pointers_per_short_table ) _Internal_throw_exception(1); // throw std::out_of_range void *_Array = _My_segment[_K]._My_array; // no need in load_with_acquire if( _Array <= _BAD_ALLOC_MARKER ) // check for correct segment pointer _Internal_throw_exception(2); // throw std::range_error return static_cast<_Ty*>(_Array)[_J]; } template void concurrent_vector<_Ty, _Ax>::_Internal_assign(size_type _N, const_reference _Item) { _CONCRT_ASSERT( _My_early_size == 0 ); if( !_N ) return; _Internal_reserve(_N, sizeof(_Ty), max_size()); _My_early_size = _N; _Segment_index_t _K = 0; _Size_type _Sz = _Segment_size( _My_first_block ); while (_Sz < _N) { _Initialize_array_by(static_cast<_Ty*>(_My_segment[_K]._My_array), static_cast(&_Item), _Sz); _N -= _Sz; if (!_K) { _K = _My_first_block; } else { ++_K; _Sz <<= 1; } } _Initialize_array_by(static_cast<_Ty*>(_My_segment[_K]._My_array), static_cast(&_Item), _N); } template template void concurrent_vector<_Ty, _Ax>::internal_assign_iterators(_I _First, _I _Last) { _CONCRT_ASSERT(_My_early_size == 0); size_type _N = std::distance(_First, _Last); if( !_N ) return; _Internal_reserve(_N, sizeof(_Ty), max_size()); _My_early_size = _N; _Segment_index_t _K = 0; _Size_type _Sz = _Segment_size( _My_first_block ); while (_Sz < _N) { _Internal_loop_guide _Loop(_Sz, _My_segment[_K]._My_array); _Loop._Iterate(_First); _N -= _Sz; if (!_K) { _K = _My_first_block; } else { ++_K; _Sz <<= 1; } } _Internal_loop_guide _Loop(_N, _My_segment[_K]._My_array); _Loop._Iterate(_First); } template void __cdecl concurrent_vector<_Ty, _Ax>::_Initialize_array( void* _Begin, const void *, size_type _N ) { _Internal_loop_guide _Loop(_N, _Begin); _Loop._Init(); } template void __cdecl concurrent_vector<_Ty, _Ax>::_Initialize_array_by( void* _Begin, const void *_Src, size_type _N ) { _Internal_loop_guide _Loop(_N, _Begin); _Loop._Init(_Src); } template void __cdecl concurrent_vector<_Ty, _Ax>::_Copy_array( void* _Dst, const void* _Src, size_type _N ) { _Internal_loop_guide _Loop(_N, _Dst); _Loop._Copy(_Src); } template void __cdecl concurrent_vector<_Ty, _Ax>::_Assign_array( void* _Dst, const void* _Src, size_type _N ) { _Internal_loop_guide _Loop(_N, _Dst); _Loop._Assign(_Src); } #pragma warning(push) #pragma warning(disable: 4189) /* local variable _Array is initialized but not used - the compiler optimizes away calls to the destructor */ template void __cdecl concurrent_vector<_Ty, _Ax>::_Destroy_array( void* _Begin, size_type _N ) { _Ty* _Array = static_cast<_Ty*>(_Begin); for( size_type _J=_N; _J>0; --_J ) _Array[_J-1].~_Ty(); // destructors are supposed to not throw any exceptions } #pragma warning(pop) /// /// Tests if the concurrent_vector object on the left side of the operator is equal to the concurrent_vector /// object on the right side. /// /// /// The data type of the elements stored in the concurrent vectors. /// /// /// The allocator type of the first concurrent_vector object. /// /// /// The allocator type of the second concurrent_vector object. /// /// /// An object of type concurrent_vector. /// /// /// An object of type concurrent_vector. /// /// /// true if the concurrent vector on the left side of the operator is equal to the concurrent vector on the right side /// of the operator; otherwise false. /// /// /// Two concurrent vectors are equal if they have the same number of elements and their respective elements have the same values. /// Otherwise, they are unequal. /// This method is not concurrency-safe with respect to other methods that could modify either of the concurrent vectors /// or . /// /// /// /**/ template inline bool operator==(const concurrent_vector<_Ty, A1> &_A, const concurrent_vector<_Ty, A2> &_B) { // Simply: return _A.size() == _B.size() && std::equal(_A.begin(), _A.end(), _B.begin()); if(_A.size() != _B.size()) return false; typename concurrent_vector<_Ty, A1>::const_iterator _I(_A.begin()); typename concurrent_vector<_Ty, A2>::const_iterator _J(_B.begin()); for(; _I != _A.end(); ++_I, ++_J) { if( !(*_I == *_J) ) return false; } return true; } /// /// Tests if the concurrent_vector object on the left side of the operator is not equal to the concurrent_vector /// object on the right side. /// /// /// The data type of the elements stored in the concurrent vectors. /// /// /// The allocator type of the first concurrent_vector object. /// /// /// The allocator type of the second concurrent_vector object. /// /// /// An object of type concurrent_vector. /// /// /// An object of type concurrent_vector. /// /// /// true if the concurrent vectors are not equal; false if the concurrent vectors are equal. /// /// /// Two concurrent vectors are equal if they have the same number of elements and their respective elements have the same /// values. Otherwise, they are unequal. /// This method is not concurrency-safe with respect to other methods that could modify either of the concurrent vectors /// or . /// /// /// /**/ template inline bool operator!=(const concurrent_vector<_Ty, A1> &_A, const concurrent_vector<_Ty, A2> &_B) { return !(_A == _B); } /// /// Tests if the concurrent_vector object on the left side of the operator is less than the concurrent_vector /// object on the right side. /// /// /// The data type of the elements stored in the concurrent vectors. /// /// /// The allocator type of the first concurrent_vector object. /// /// /// The allocator type of the second concurrent_vector object. /// /// /// An object of type concurrent_vector. /// /// /// An object of type concurrent_vector. /// /// /// true if the concurrent vector on the left side of the operator is less than the concurrent vector /// on the right side of the operator; otherwise false. /// /// /// The behavior of this operator is identical to the equivalent operator for the vector class in the std /// namespace. /// This method is not concurrency-safe with respect to other methods that could modify either of the concurrent vectors /// or . /// /// /// /**/ template inline bool operator<(const concurrent_vector<_Ty, A1> &_A, const concurrent_vector<_Ty, A2> &_B) { return (std::lexicographical_compare(_A.begin(), _A.end(), _B.begin(), _B.end())); } /// /// Tests if the concurrent_vector object on the left side of the operator is greater than the concurrent_vector /// object on the right side. /// /// /// The data type of the elements stored in the concurrent vectors. /// /// /// The allocator type of the first concurrent_vector object. /// /// /// The allocator type of the second concurrent_vector object. /// /// /// An object of type concurrent_vector. /// /// /// An object of type concurrent_vector. /// /// /// true if the concurrent vector on the left side of the operator is greater than the concurrent vector /// on the right side of the operator; otherwise false. /// /// /// The behavior of this operator is identical to the equivalent operator for the vector class in the std /// namespace. /// This method is not concurrency-safe with respect to other methods that could modify either of the concurrent vectors /// or . /// /// /// /**/ template inline bool operator>(const concurrent_vector<_Ty, A1> &_A, const concurrent_vector<_Ty, A2> &_B) { return _B < _A; } /// /// Tests if the concurrent_vector object on the left side of the operator is less than or equal to the concurrent_vector /// object on the right side. /// /// /// The data type of the elements stored in the concurrent vectors. /// /// /// The allocator type of the first concurrent_vector object. /// /// /// The allocator type of the second concurrent_vector object. /// /// /// An object of type concurrent_vector. /// /// /// An object of type concurrent_vector. /// /// /// true if the concurrent vector on the left side of the operator is less than or equal to the concurrent vector /// on the right side of the operator; otherwise false. /// /// /// The behavior of this operator is identical to the equivalent operator for the vector class in the std /// namespace. /// This method is not concurrency-safe with respect to other methods that could modify either of the concurrent vectors /// or . /// /// /// /**/ template inline bool operator<=(const concurrent_vector<_Ty, A1> &_A, const concurrent_vector<_Ty, A2> &_B) { return !(_B < _A); } /// /// Tests if the concurrent_vector object on the left side of the operator is greater than or equal to the concurrent_vector /// object on the right side. /// /// /// The data type of the elements stored in the concurrent vectors. /// /// /// The allocator type of the first concurrent_vector object. /// /// /// The allocator type of the second concurrent_vector object. /// /// /// An object of type concurrent_vector. /// /// /// An object of type concurrent_vector. /// /// /// true if the concurrent vector on the left side of the operator is greater than or equal to the concurrent vector /// on the right side of the operator; otherwise false. /// /// /// The behavior of this operator is identical to the equivalent operator for the vector class in the std /// namespace. /// This method is not concurrency-safe with respect to other methods that could modify either of the concurrent vectors /// or . /// /// /// /**/ template inline bool operator>=(const concurrent_vector<_Ty, A1> &_A, const concurrent_vector<_Ty, A2> &_B) { return !(_A < _B); } /// /// Exchanges the elements of two concurrent_vector objects. /// /// /// The data type of the elements stored in the concurrent vectors. /// /// /// The allocator type of the concurrent vectors. /// /// /// The concurrent vector providing the elements to be swapped, or the vector whose elements are to be exchanged with those of the /// concurrent vector . /// /// /// The concurrent vector whose elements are to be exchanged with those of the concurrent vector . /// /// /// The template function is an algorithm specialized on the container class concurrent_vector to execute the member function /// .concurrent_vector::swap(). These are /// instances of the partial ordering of function templates by the compiler. When template functions are overloaded in such a way that /// the match of the template with the function call is not unique, then the compiler will select the most specialized version of the /// template function. The general version of the template function, template <class T> void swap(T&, T&), in the /// algorithm class works by assignment and is a slow operation. The specialized version in each container is much faster as it can /// work with the internal representation of the container class. /// This method is not concurrency-safe. You must ensure that no other threads are performing operations on either of the concurrent /// vectors when you call this method. /// /// /// /**/ template inline void swap(concurrent_vector<_Ty, _Ax> &_A, concurrent_vector<_Ty, _Ax> &_B) { _A.swap( _B ); } } // namespace Concurrency namespace concurrency = Concurrency; #pragma warning (pop) #pragma pack(pop)