BDE 4.14.0 Production release
|
Provide reverse iterator adapter for calendar iterators.
This component provides a template, bdlt::CalendarReverseIteratorAdapter
, that can be used to adapt a calendar iterator to be a reverse iterator (see bdlt_calendar and bdlt_packedcalendar ). Calendar iterators cannot return a reference to an underlying element of the calendar and hence cannot be used with bsl::reverse_iterator
. The reverse iterator adapter defined in this component provides a subset of the bsl::reverse_iterator
interface that can be used with the calendar iterators defined in bdlt
. Specifically, the types value_type
, difference_type , pointer
, and reference
are defined but iterator_category is not defined (since this is not a fully-compliant iterator). Furthermore, the methods appropriate for random-access iterators are not included (e.g., operator+=
).
bdlt::CalendarReverseIteratorAdapter
is not a fully-compliant implementation of std::reverse_iterator
according to the C++ standard. It is an implementation of the minimum functionality needed to support the public iterators in the bdlt_calendar and bdlt_packedcalendar components. Within that limitation, it is a subset implementation of bsl::reverse_iterator
. Specifically, iterator_category is not defined for this adapter and the methods of a bsl::reverse_iterator
relevant only to random-access compliant ITERATOR
types are omitted.
This section illustrates intended use of this component.
In this example, we will use the bdlt::CalendarReverseIteratorAdapter
to traverse an iterable container type. Specifically, we will create an array of struct
values, implement a bidirectional iterator class that is a forward iterator for this array, and then use bdlt::CalendarReverseIteratorAdapter
to provide a reverse iterator that will be used to traverse the array.
First, we define a bidirectional iterator class:
Then, we define struct
S
, the type that will be referred to by the Iterator
type:
The struct
S
has two data members. By creating an array of distinct S
values, the state of an iterator referring to an element of this array can be easily verified by inspecting these two members.
Next, we define four (distinct) S
values:
Then, we define s
, an array of S
values:
Next, we define an iterator, sfBegin
, referring to the first element of s
and an iterator, sfEnd
, having the past-the-end value for an iterator over s
:
Then, for convenience we declare our reverse iterator type that will be used to traverse s
in the reverse direction:
Next, we declare begin and end reverse iterators to our range of S
values:
Now, we traverse our range in the reverse direction, from rBegin
to rEnd
, streaming out the contents of the S
values as we go:
Finally, we verify the contents of the range output: