|
BDE 4.14.0 Production release
|
Functions | |
| bdlat_ArrayIterators::BackInsertIterator< TYPE >::BackInsertIterator (TYPE *array) | |
| BackInsertIterator & | bdlat_ArrayIterators::BackInsertIterator< TYPE >::operator= (const BackInsertIterator &rhs) |
Assign this iterator the value of the specified rhs. | |
| template<class ELEM_TYPE > | |
| bdlat_ArrayIterators::BackInsertIterator< TYPE > & | bdlat_ArrayIterators::BackInsertIterator< TYPE >::operator= (const ELEM_TYPE &obj) |
| BackInsertIterator & | bdlat_ArrayIterators::BackInsertIterator< TYPE >::operator* () |
| BackInsertIterator & | bdlat_ArrayIterators::BackInsertIterator< TYPE >::operator++ () |
| BackInsertIterator | bdlat_ArrayIterators::BackInsertIterator< TYPE >::operator++ (int) |
Provide iterator support for bdlat_ArrayFunction-conformant types.
This component provides a namespace bdlat_ArrayIterators that contains definitions for the bdlat_ArrayIterators::BackInsertIterator class template and the backInserter convenience function. Additional iterator types may be added in the future.
BackInsertIterator<ARRAY_TYPE> is an iterator type which, when used in an expression like "*i++ = v", appends the value v to the end of the ARRAY_TYPE object used to construct the iterator, i. It meets the requirements of an STL output iterator and it can be instantiated for any type that meets the requirements described in bdlat_arrayfunctions . BackInsertIterator is similar to the standard bsl::back_insert_iterator class template, which works for STL sequence containers.
The backInserter function template takes a parameter of type pointer-to-ARRAY_TYPE, where ARRAY_TYPE is a type that conforms to the interface described in the bdlat_arrayfunctions component, and returns an object of type BackInsertIterator<ARRAY_TYPE>. It is a convenience function for creating a BackInsertIterator without declaring its exact type. The backInserter function is similar to the standard bsl::back_inserter template function, which works for STL sequence containers. In fact, backInserter is specialized for bsl::vector so that it returns an bsl::back_insert_iterator, just like bsl::back_inserter does.
A BackInsertIterator contains a pointer to an array object and multiple backInsertIterator objects may point to the same array object. It is safe to access or modify two BackInsertIterator objects simultaneously, each from a separate thread, if they each refer to a different array object. It is safe to access a single BackInsertIterator object simultaneously from two or more separate threads, provided no other thread is simultaneously modifying the iterator or its referenced array. It is not safe to access or modify a BackInsertIterator object in one thread while another thread modifies the same iterator, its referenced array object, or another iterator referring to the same array.
This section illustrates intended use of this component.
To use the facilities in this component, you must of course include the header file:
The main use of the facilities in this component is for creating generic algorithms. The following generic function appends a few integers to the end of an object of type ARRAY that adheres to the bdlat_ArrayFunctions interface. It starts by creating a BackInsertIterator:
Now, using the "*i++ = v" idiom, append the numbers 5 and 4 to the array object:
Alternatively, one can use the iterator in a standard algorithm. For example, the following code appends the numbers 3, 2, and 1 to the array object:
An alternative implementation of appendSome would use backInserter to create an iterator without declaring its exact type. Note that, in this case, we do not create a variable it, but simply pass the iterator to a standard algorithm:
In our main program, we need to construct an array that adheres to the bdlat_arrayfunctions interface:
The result of calling appendSome is that the elements 5, 4, 3, 2 and 1 are appended to the array:
The result of calling appendSome2 is the same:
|
inline |
Construct a back-insertion iterator to manipulate the specified array.
|
inline |
Do nothing and return a reference to this modifiable iterator. This function is used in generic algorithms that use the expression *i++ = v or *++i = v.
|
inline |
Do nothing and return a reference to this modifiable iterator. This function is used in generic algorithms that use the expression *++i = v
|
inline |
Do nothing and return a copy of this iterator. This function is used in generic algorithms that use the expression *i++ = v
|
inline |
|
inline |