text
stringlengths 0
2.2M
|
---|
// 'MyFixedSizeArray', which provides mutable and constant iterators of
|
// template type 'bsl::iterator' and 'reverse_iterator':
|
//..
|
template <class VALUE, int SIZE>
|
class MyFixedSizeArray
|
// This is a container that contains a fixed number of elements. The
|
// number of elements is specified upon construction and can not be
|
// changed afterwards.
|
{
|
// DATA
|
VALUE d_array[SIZE]; // storage of the container
|
public:
|
// PUBLIC TYPES
|
typedef VALUE value_type;
|
//..
|
// Here, we define mutable and constant iterators and reverse iterators:
|
//..
|
typedef VALUE *iterator;
|
typedef VALUE const *const_iterator;
|
typedef bsl::reverse_iterator<iterator> reverse_iterator;
|
typedef bsl::reverse_iterator<const_iterator> const_reverse_iterator;
|
// CREATORS
|
//! MyFixedSizeArray() = default;
|
// Create a 'MyFixedSizeArray' object having the parameterized
|
// 'SIZE' elements of the parameterized type 'VALUE'.
|
//! MyFixedSizeArray(const MyFixedSizeArray& original) = default;
|
// Create a 'MyFixedSizeArray' object having same number of
|
// elements as that of the specified 'rhs', and the same value of
|
// each element as that of corresponding element in 'rhs'.
|
//! ~MyFixedSizeArray() = default;
|
// Destroy this object.
|
//..
|
// Now, we define the 'begin' and 'end' methods to return basic iterators
|
// ('VALUE*' and 'const VALUE*'), and the 'rbegin' and 'rend' methods to return
|
// reverse iterators ('bsl::reverse_iterator<VALUE*>' and
|
// 'bsl::reverse_iterator<const VALUE*>) type:
|
//..
|
// MANIPULATORS
|
iterator begin();
|
// Return the basic iterator providing modifiable access to the
|
// first valid element of this object.
|
iterator end();
|
// Return the basic iterator providing modifiable access to the
|
// position one after the last valid element of this object.
|
reverse_iterator rbegin();
|
// Return the reverse iterator providing modifiable access to the
|
// last valid element of this object.
|
reverse_iterator rend();
|
// Return the reverse iterator providing modifiable access to the
|
// position one before the first valid element of this object.
|
VALUE& operator[](int i);
|
// Return the reference providing modifiable access of the
|
// specified 'i'th element of this object.
|
// ACCESSORS
|
const_iterator begin() const;
|
// Return the basic iterator providing non-modifiable access to the
|
// first valid element of this object.
|
const_iterator end() const;
|
// Return the basic iterator providing non-modifiable access to the
|
// position one after the last valid element of this object.
|
const_reverse_iterator rbegin() const;
|
// Return the reverse iterator providing non-modifiable access to
|
// the last valid element of this object.
|
const_reverse_iterator rend() const;
|
// Return the reverse iterator providing non-modifiable access to
|
// the position one before the first valid element of this object.
|
int size() const;
|
// Return the number of elements contained in this object.
|
const VALUE& operator[](int i) const;
|
// Return the reference providing non-modifiable access of the
|
// specified 'i'th element of this object.
|
};
|
// ...
|
//..
|
// ----------------
|
// MyFixedSizeArray
|
// ----------------
|
// MANIPULATORS
|
template<class VALUE, int SIZE>
|
typename MyFixedSizeArray<VALUE,SIZE>::iterator
|
MyFixedSizeArray<VALUE,SIZE>::begin()
|
{
|
return d_array;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.